// RELEXPAND
function link_expand() {
	$("a[rel*=expand]")
		.each(function() {
			var destinazioneLink = $(this).attr("href");
			var target_var = $(this).attr("target");
			var cliccato=0;
			$(this).unbind("click").click(function() {
                                        cliccato=1;
				})
				.parents(":eq(0)")
				.unbind("click")
				.click( function() {
					if(cliccato==0){
						if(target_var=="_blank") window.open(destinazioneLink,'sponsor');
						else window.location = destinazioneLink;
					}
					cliccato=0;
				})
				.hover(function () {
					$(this).css({ cursor: "pointer" });
				}, function () {
					$(this).css({ cursor: "default" });
			});
	});
		
			$("a[rel*=expand_2]")
		.each(function() {
			var destinazioneLink = $(this).attr("href");
			var target_var = $(this).attr("target");
			var cliccato=0;
			$(this).unbind("click").click(function() {
                                        cliccato=1;
				})
				.parents(":eq(1)")
				.unbind("click")
				.click( function() {
					if(cliccato==0){
						if(target_var=="_blank") window.open(destinazioneLink,'sponsor');
						else window.location = destinazioneLink;
					}
					cliccato=0;
				})
				.hover(function () {
					$(this).css({ cursor: "pointer" });
				}, function () {
					$(this).css({ cursor: "default" });
			});
	});
}


/*____________________GESTIONE POPUP TELLEAFRIEND_________________*/	

function getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}
	return new Array(xScroll,yScroll)
}

function getPageHeight() {
	var windowHeight
	if (self.innerHeight) { // all except Explorer
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = document.body.clientHeight;
	}
	return windowHeight
}

function getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}
	return new Array(xScroll,yScroll)
}

function getPageHeight() {
	var windowHeight
	if (self.innerHeight) { // all except Explorer
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = document.body.clientHeight;
	}
	return windowHeight
}




// Console
if (typeof console == 'undefined') {
	console = new Object;
	console.trace = function() {};
	console.log = function() {};
	console.debug = function() {};
	console.info = function() {};
	console.warn = function() {};
	console.error = function() {};
	console.time = function() {};
	console.timeEnd = function() {};
	console.count = function() {};
}

// AJAX forms
function ajaxifySingleForm(form, callback) {
	callback = callback || function(){ };
	$(form).validate({
		wrapper: "strong",
		submitHandler: function(form){
			$(form).ajaxSubmit({
			target: $(form).parent(),
			success: function() {
				initAjaxForms();
				callback.call();
				}
			});
		}
	});
}

function initAjaxForms() {
	$("form.ajax").each(function() {
		ajaxifySingleForm(this);
	});
}

function getFlashObject_nomedia(id, src, w, h, flashVersion, flashVars ){
	var flash_nomedia = 
		'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + 
			'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+flashVersion+'" '+ 
			'width="'+w+'" '+ 
			'height="'+h+'">'+
			'<param name="allowScriptAccess" value="sameDomain" />'+
			'<param name="allowFullScreen" value="true" />'+
			'<param name="movie" value="'+src+'" />'+
			'<param name="quality" value="high" />'+
			'<param name="wmode" value="transparent" />'+
			'<param name="bgcolor" value="#ffffff" />'+
			'<param name="salign" value="t" />'+
			'<param name="FlashVars" value="'+flashVars+'" />'+
			'<embed src="'+src+'" '+
				'quality="high" '+
				'wmode="transparent" '+
				'bgcolor="#ffffff" '+
				'width="'+w+'" '+
				'height="'+h+'" '+
				'name="'+id+'" '+
				'align="middle" '+
				'salign="t" '+
				'allowScriptAccess="sameDomain" '+
				'allowFullScreen="true" '+
				'type="application/x-shockwave-flash" '+
				'pluginspage="http://www.macromedia.com/go/getflashplayer"' +
				'FlashVars="'+ flashVars +'"/>'+
		'</object>'	;
	return flash_nomedia;
}

function popUpWin(url,type,strWidth,strHeight){
	var tools="";
	tools="resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
	nuova_finestra=window.open(url,'nuova_finestra',tools);
	nuova_finestra.focus();
}


// MENU
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function ddmenu_open(){
	ddmenu_canceltimer();
   	ddmenu_close();
	//alert("ppp");
	$("#toppaSubMenuNav").css('display','block');
   	ddmenuitem = $(this).find('ul').css('display', 'block');
}

function ddmenu_close(){ 
	if(ddmenuitem) ddmenuitem.css('display', 'none');
	$("#toppaSubMenuNav").css('display','none');
}

function ddmenu_timer(){
	closetimer = window.setTimeout(ddmenu_close, timeout);
}

function ddmenu_canceltimer(){  
	if(closetimer){  
		window.clearTimeout(closetimer);
        closetimer = null;
	}
}

// Inizio document.ready
$("document").ready ( function (){
	// PNG FIX IE
	$(document).pngFix();
	
	//NAVIGAZIONE MENU
	$('#menuNav > li').bind('mouseover', ddmenu_open);
    $('#menuNav > li').bind('mouseout',  ddmenu_timer);

	//CONTROLLO BLOCCO MAX FOCUS HOME pAGE
	if($('#contents .max_focus').find("div").length == 0){
		$('#contents .max_focus').css('display','none');
	}
	
	// Ciao utente
	var nameEQ = "maxuser_user=";
	var ca = document.cookie.split(';');
	var cookieValue = "";
	for(var i=0;i < ca.length;i++) {
	var c = ca[i];
	while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) cookieValue = c.substring(nameEQ.length,c.length);
	}

	if (cookieValue=="") {
		$(".topLogin").append('<label class="labelLogin" for="login">Login</label><input type="text" name="userid"/>');
		$(".topLogin").append('<label class="labelPsw" for="password">Pw</label><input type="password" type="password" name="password"/>');
		$(".topLogin").append('<button class="btnLogin" type="submit" onClick="loginForm.submit();">Invia</button>');
		$(".topLogin").after('<a class="linkRegistrati" href="/utenti/toRegistration.action">Registrati</a>');
	} else {
		$(".topLogin").after('<span class="linkRegistrati">Ciao</span><a class="linkRegistrati" href="/utenti/toProfile.action" title="Modifica il Tuo profilo" style="color:#CC0000">&nbsp;&nbsp;' + cookieValue + '</a><a href="http://max.rcs.it/utenti/logout.action" class="linkRegistrati">&nbsp;&nbsp;&nbsp;&nbsp;LOGOUT</a>');
	}
    
	// ultimo blocco max_focus HP
	if($(".max_focus").length>=1){
		$(".box_focus:last").addClass("last_box");
	}
	
	$('.inputBlog').attr('title');
	$('.inputBlog').keyup(function(e) {
		$('.inputBlog').text('');
		if(e.keyCode == 13) {
			$('#search-topright').submit();
		}
	});
	
	// SE ESISTE ADV HALF PAGE RIDIMENSIONO BOX MAXNEWS e lo NASCONDO
	/*if($("#adv_half_page").children().length>1){
		$("#vaschetta_news_max").css("display","none");
		$("#max-news-right2").css("height","155px");
		$("#vaschetta_news_max").css("height","155px");
	}*/
	
	// GESTIONE TOPBANNER
	if($("#topbanner").children().length>1) {
		$("#topbanner").css("display","block");
	}
	
	// REL EXPAND
/*	$("a[rel*=expand]").each(function() {
		var destinazioneLink = $(this).attr("href");
		$(this).parent("div")
			.click(function() {
				window.location = destinazioneLink;
			})
			.hover(function () {
				$(this).css({ cursor: "pointer" });
			}, function () {
				$(this).css({ cursor: "default" });
			});
	});
*/	
	// RICERCA - TOLGO BORDER ALL'ULTIMO ELEMENTO DELLA LIST
	$(".list").each(function() {
		$(this).children(".articolo_singolo_altri:last").css("border","none");
	});
	
	// GALLERY HOME PAGE
	
	$('#home #gallery-hp').cycle({
        fx:     'fade',
        speed:  400,
        timeout: 4000,
		sync:1,
		before:  onBefore,
        pager:  '#cNav',
		pagerEvent: 'mouseover',
		fastOnEvent: true,
		pagerAnchorBuilder: function(idx, slide) {
			return '<li><a href="'+ slide.name +'"><img src="'+ slide.src +'" width="70" height="46" class="jqrbi"/></a></li>'
		}
    });
	function onBefore() {
		//$("#title_gallery_bis").html("<a rel=\""+this.name+"\" href=\""+this.name+"\" class=\"titolo\">"+this.title+"</a><br/><a rel=\""+this.name+"\" href=\""+this.name+"\" class=\"sottotitolo\">"+this.alt+"</a>").fadeIn(200);
		$("#title_gallery_bis").html("<a rel=\""+this.name+"\" href=\""+this.name+"\" class=\"titolo\">"+this.title+"</a>").fadeIn(200);
		$("#maxstore #title_gallery_bis").css('display','none');
	}
	$("#home #gallery-hp img").each(function() {
		var linkImg = $(this).attr('name');
		$(this).wrap("<a href=\""+linkImg+"\"></a>");
	});
	
	// GALLERY HOME MAXSTORE
	
	$('#maxstore #gallery-hp').cycle({
        fx:     'fade',
        speed:  400,
        timeout: 4000,
		sync:1,
		before:  onBeforeStore,
        pager:  '#cNav',
		pagerEvent: 'mouseover',
		fastOnEvent: true,
		pagerAnchorBuilder: function(idx, slide) {
			return '<li><img src="'+ slide.src +'" width="86" height="57" class="jqrbi"/></li>'
		}
    });
	function onBeforeStore() {
		//$("#title_gallery_bis").html("<a rel=\""+this.name+"\" href=\""+this.name+"\" class=\"titolo\">"+this.title+"</a><br/><a rel=\""+this.name+"\" href=\""+this.name+"\" class=\"sottotitolo\">"+this.alt+"</a>").fadeIn(200);
		$("#title_gallery_bis").html("<a rel=\""+this.name+"\" href=\""+this.name+"\" class=\"titolo\">"+this.title+"</a>").fadeIn(200);
		$("#maxstore #title_gallery_bis").css('display','none');
	}
	
	
	/*____________________GESTIONE POPUP TELLEAFRIEND_________________	*/

	$('#tellAFriend').click(function() {
		// 1. Verifico che non sia stato creato gia un oggetto
		// 2. Se Ë stato creato faccio il load e sostituisco l'html dell'oggetto stesso.
		// 3. Se non Ë stato creato, lo creo e lo appendo in coda al body.
		if ($("#tellafriend_popup").html()==null) {
			$("body").append("<div id='tellafriend_popup'></div>");
		}

		$("#tellafriend_popup").load("/ssi/includes/shared/tellafriend_sm.shtml", function(){
			$('#tellafriend_popup').css({
				position: 'absolute',
				display: 'none',
				top:	getPageScroll()[1] + (getPageHeight() / 10),
				left:	'385px',
				background: '#fff'
			});
			
			//$("#taf-link").attr("value",window.location.href.toString());
			var link_pop_up = $(window).attr('location')+"";
			link_pop_up = link_pop_up.replace('#tellafriend_popup',' ');
			$("#taf-form input[@name='link']").attr('value', link_pop_up);
			$("#tellafriend_popup .close_taf").click(function() {
				$("#tellafriend_popup").fadeOut(200);	
			});
			$("#tellafriend_popup").fadeIn(200);

			initAjaxForms();
		});
		return false;
	});

	/*____________________ FINE GESTIONE POPUP TELLEAFRIEND_________________*/
	
	//DISABILITA MOUSE CLICK //
	oggi_Y=new Date();
	var clickmessage="Copyright " +oggi_Y.getFullYear()+ " - RCS Periodici SpA" ;

	function disableclick(e) { 
	if (document.all) { 
	if (event.button==2||event.button==3) { 
	if (event.srcElement.tagName=="IMG"){ 
	alert(clickmessage); 
	return false; 
	} 
	} 
	} 
	else if (document.layers) { 
	if (e.which == 3) { 
	alert(clickmessage); 
	return false; 
	} 
	} 
	else if (document.getElementById){ 
	if (e.which==3&&e.target.tagName=="IMG"){ 
	alert(clickmessage) 
	return false 
	} 
	} 
	} 

	function associateimages(){ 
	for(i=0;i<document.images.length;i++) 
	document.images[i].onmousedown=disableclick; 
	} 

	if (document.all||document.getElementById) 
	document.onmousedown=disableclick 
	else if (document.layers) 
	associateimages() 
	// FINE DISABILITA MOUSE CLICK //


	var link_img_sg="";
	var link_img_sg_bis="";

	if($("div.smallgallery .slides img").length>1){
		$("div.smallgallery .slides").cycle({
			fx:     "scrollHorz",
			timeout: 6000,
			after:   onAfterSmallGallery,
			next:   "div.smallgallery .smallgallery-next",
			prev:   "div.smallgallery .smallgallery-prev"
		});
	}
	else {
		onBeforeSmallGallery($("div.smallgallery .slides").find('img'));
		$("div.smallgallery .smallgallery-next, div.smallgallery .smallgallery-prev").hide();
	}

	 	$('div.smallgallery img').click(function() {
			window.location = link_img_sg;
		});

	function onBeforeSmallGallery(objetc_slide) { 
		var href_replace = "<a class='white' href='"+$(objetc_slide).attr('name')+"' title='"+$(objetc_slide).attr('alt')+"'>"+$(objetc_slide).attr('alt')+"</a>";
	    $('div.smallgallery h3').html(href_replace);
		link_img_sg = $(objetc_slide).attr('name');
	} 

	function onAfterSmallGallery() { 
		var href_replace = "<a class='white' href='"+this.name+"' title='"+this.alt+"'>"+this.alt+"</a>";
	    $('div.smallgallery h3').html(href_replace);
		link_img_sg = this.name;
	}
	if($("div.smallgallery_bis .slides img").length>1){
		$("div.smallgallery_bis .slides").cycle({
			fx:     "scrollHorz",
			timeout: 6000,
			before:  onBeforeSmallGallery_bis,
			after:   onAfterSmallGallery_bis,
			next:   "div.smallgallery_bis .smallgallery-next",
			prev:   "div.smallgallery_bis .smallgallery-prev"
		});
		}
	else {
		onBeforeSmallGallery_bis($("div.smallgallery_bis .slides").find('img'));
		$("div.smallgallery_bis .smallgallery-next, div.smallgallery_bis .smallgallery-prev").hide();
	}

	  	$('div.smallgallery_bis img').click(function() {
			window.location = link_img_sg_bis;
		});

		$('div.smallgallery .slides').show();
		$('div.smallgallery_bis .slides').show();

	function onBeforeSmallGallery_bis(objetc_slide) { 
		var href_replace_bis = "<a class='white' href='"+$(objetc_slide).attr('name')+"' title='"+$(objetc_slide).attr('alt')+"'>"+$(objetc_slide).attr('alt')+"</a>";
	    $('div.smallgallery_bis h3').html(href_replace_bis);
		link_img_sg_bis = $(objetc_slide).attr('name');
	} 
	function onAfterSmallGallery_bis() { 
		var href_replace_bis = "<a class='white' href='"+this.name+"' title='"+this.alt+"'>"+this.alt+"</a>";
	    $('div.smallgallery_bis h3').html(href_replace_bis);
		link_img_sg_bis = this.name;
	}

	var script_disable_clk ="<script type=\"text/javascript\">oggi_Y=new Date(); var clickmessage=\"Copyright \" +oggi_Y.getFullYear()+ \" - � RCS Periodici SpA\" ; function disableclick(e) { if (document.all) { if (event.button==2||event.button==3) { if (event.srcElement.tagName==\"IMG\"){ alert(clickmessage); return false; }}} else if (document.layers) { if (e.which == 3) { alert(clickmessage); return false; }} else if (document.getElementById){ if (e.which==3 && e.target.tagName==\"IMG\"){ alert(clickmessage); return false; }}} function associateimages(){ for(i=0;i<document.images.length;i++) document.images[i].onmousedown=disableclick; } if (document.all||document.getElementById) document.onmousedown=disableclick; else if (document.layers) associateimages();</script>";

	$("a[rel*=popup]")
		.click(function(){
			var o = {
				rsPath: "/fotogallery"
			}
			$(this).ajaxMetrics(o);
			//set defaults - if nothing in rel attrib, these will be used
			var t = "standard";
			var w = "780";
			var h = "580";
			var hr = $(this).attr("href");
			//look for parameters
			attribs = $(this).attr("rel").split(" ");
			if (attribs[1]!=null) {t = attribs[1];}
			if (attribs[2]!=null) {w = attribs[2];}
			if (attribs[3]!=null) {h = attribs[3];}
			//call the popup script
			if(t == "console"){
			popUpMax($(this).attr("href"),t,w,h);
			}
			else if(t == "classic"){
			popUpWin($(this).attr("href"),t,w,h);
			}
			else if(t == "fixed"){
			if (attribs[4]!=null) {hr = attribs[4];}
			popUpWin(hr,t,w,h);
			}
			else{
			popUpMax_edicola($(this).attr("href"));
			}
			return false;
		})
		.each(function(){
		// add popup indicator
		if ($(this).attr("rel").indexOf("noicon")==-1) {
			$(this).addClass("new-window").attr("title", $(this).attr("title") + "  [Apre una nuova finestra]");
		}
	});



	function popUpMax_edicola(url)
	{
	image_new = new Image();
	image_new.src = url;
	width=image_new.width;
	height=image_new.height;

	  var generator=window.open('','','resizable=no,menubar=no,toolbar=no,location=no,status=no,scrollbars=no,width='+width+',height='+height+',left=0,top=0');
	  generator.document.write('<html>');     
	  generator.document.write('<head><title>MAXpopup</title>');
	  generator.document.write('</head><body>');
	  generator.document.write('<img style="position:absolute;top:0;left:0;" src="'+url+'" alt="MAX" />');
	  generator.document.write('</body></html>');
	  generator.document.close();

	}
	function popUpMax(url, type, imgWidth, imgHeight)
	{

	image_new = new Image();
	image_new.src = url;
	  var popwidth = image_new.width;
	  var popheight = image_new.height;
	//  var popwidth = imgWidth;
	//  var popheight = imgHeight;

	  var imgwidth = imgWidth-20;
	  var imgheight = imgHeight-20; 

	  var strWidth = screen.availWidth;
	  var strHeight = screen.availHeight;

	  if(imgWidth>imgHeight) {
		  popwidth = strWidth-20;
		  perc =  100*popwidth/imgWidth;
		  popheight = parseInt(imgHeight*perc/100);

		  if(popheight>strHeight) {
			  popheight = strHeight-20;
			  perc =  100*popheight/imgHeight;
			  popwidth = parseInt(imgWidth*perc/100);
		  }

	  }
	  else{
		  popheight = strHeight-20;
		  perc =  100*popheight/imgHeight;
		  popwidth = parseInt(imgWidth*perc/100);

		  if(popwidth>strWidth){
			  popwidth = strWidth-20;
			  perc =  100*popwidth/imgWidth;
			  popheight = parseInt(imgHeight*perc/100);
		  }
	  }

	  var generator=window.open('','','resizable=no,menubar=no,toolbar=no,location=no,status=no,scrollbars=no,width='+popwidth+',height='+popheight+',left=250,top=0');
	  generator.document.write('<html>');
	  generator.document.write('<head><title>MAXpopup</title>');
	  generator.document.write(script_disable_clk);
	  generator.document.write('</head><body>');
	  generator.document.write('<img style="position:absolute;top:0;left:0;" src="'+url+'" alt="MAX"/>');
	  generator.document.write('</body></html>');
	  generator.document.close();

	  $(generator.document).ready(function(){
		  if (generator.document.body.clientHeight>0){
	        imgheight = generator.document.body.clientHeight;
	        imgwidth = generator.document.body.clientWidth;
	        console.log("imgheight:"+imgheight);
	        console.log(" imgwidth:"+imgwidth);
	        $("img", generator.document).attr('width',imgwidth).attr('height',imgheight);
	      }
	  });
	}
	
	// MAXCLUB
	if($("#mycarousel").length!=0){
		$('#mycarousel').jcarousel();
	}
	// MOUSEOVER ARTICOLI CORRELATI VISUALIZZA BG E BLOCCO HOME DI SEZIONE
	$(".articolo_singolo_altri p").mouseover(function(){
		$(this).parent().css("background-position","90px 5px");
	}).mouseout(function(){
		$(this).parent().css("background-position","-90px 5px");
	});
	$(".agenda_evento p").mouseover(function(){
		$(this).parent().css("background-position","130px 15px");
	}).mouseout(function(){
		$(this).parent().css("background-position","-130px -15px");
	});
	$(".blocco p").mouseover(function(){
		$(this).parent().css("background-position","130px 15px");
	}).mouseout(function(){
		$(this).parent().css("background-position","-130px -15px");
	});
	
	// TRUNCATE 
	$(".box_sezione_2 h4 p, #fashion .box_col_3_red p").truncate( 50,{
		chars: /\s/,
		trail: [ "...", "..." ]
	});
	$(".layer_box_tit_white h3, .layer_box_tit h3").truncate( 40,{
		chars: /\s/,
		trail: [ "...", "..." ]
	});
	$("#fashion .box_col_3_red p, #max_tv h4").truncate( 70,{
		chars: /\s/,
		trail: [ "...", "..." ]
	});
	$(".articolo_singolo_altri p, .articolo_singolo p").truncate( 200,{
		chars: /\s/,
		trail: [ "...", "..." ]
	});
	$("#contents .blocco p, .box_col_3 .blocco_post p, #maxstore .box_sez span").truncate( 95,{
		chars: /\s/,
		trail: [ "...", "..." ]
	});
	$("#max_edicola h4").truncate( 112,{
		chars: /\s/,
		trail: [ "...", "..." ]
	});
	
	// CONTROLLO MARGINE ULTIMO BOX FASHION
	$("#fashion .box_col_3_red:last").removeClass('m_default_right_col');
	
	// DIDA GALLERY 
	if($("#galleryArticolo").length!=0){  
		if($("#galleryArticolo .dida_photo").text().length>3) {
			//var dida = $("#galleryArticolo img").attr('title');
			//$("#galleryArticolo .dida_photo").text(dida);
			$('#galleryArticolo .dida_photo').css('display','block');
		}
		
	}
	
	// CONTROLLO NUMERAZIONE GALLERY ARTICOLO
	if($(".navGallery").length!=0){
		var numScala = 3;
		if($("a.bt_numGallery").length >= 11){
			var numTot = $("a.bt_numGallery").length;
			var numSelected = $("a.bt_numGallery.selected").text();
			var numUp = 1*numSelected + numScala;
			var numDown = numSelected - numScala;
			$("a.bt_numGallery").each(function(i) {
				$(this).attr({ id: + ++i });
				var numSelf = $(this).attr('id');
				if(numSelected <= 5){
					if(numSelf >= 7){$(this).css('display','none');}
				}else if(numSelected >= (numTot-5)){
					if(numSelf <= (numTot-7)){$(this).css('display','none');}
				}else if(numSelf < numDown || numSelf > numUp){
					$(this).css('display','none');
				}
			});
		}
	}
	
	// CONTROLLO BLOG SHARETHIS
	$("#blog .sharethis").css('margin-right','5px');
	
	if($('#newsMail').length!=0){
		$('#newsMail').bind('click', function(){
			$('#newsMail').val('');
		});
	}
	
	// JFLOW SLIDE ANNO IN MAXCLUB
	if($('#mySlides').length!=0){
		var annoSelected = $("#mySlides .selected").attr('id');
		$("#myController").jFlow({
			slides: "#mySlides",
			selectedWrapper: "jFlowSelected",
			width: "100%",
			height: "100%",
			duration: 100,
			activeSlide: annoSelected
		});
	}
	
	// SZIONE SPORT TOLGO MARGINTOP AL PRIMO BLOCCO
	if($('#sport #contents .blocco').length!=0){
		$('#sport #contents .blocco:first').css('margin-top','0px');
	}
	
	// GESTIONE BANNER
	if($("#topbanner").length>=1){
		if($('#cityguide').length!=0){
			if($('#menuNav').length!=0){
				$("#topbanner").addClass('bgCityG');
				//$("body#cityguide").css('background-position','0px 61px');
				//$("#headerNav").css('padding-top','91px');
				//$("#logo").css('top','73px');
				//$('#bottomNav').css('top','151px');
				$("body#cityguide").css('background-position','0px 78px');
				$("#headerNav").css('padding-top','18px');
				$("#logo").css('top','0px');
				$('#bottomNav').css('top','78px');
			}else{
				//$("#topbanner").addClass('bgCityG');
				//$("#headerNav").css('padding-top','53px');
				//$("#logo").css('top','35px');
				//$('#bottomNav').css('top','118px');
				//$("body#cityguide").css('background-position','0px 29px');
			}
		}else{
			
			$("#topbanner").append('<div class=\"abb_super-banner\"><a href=\"http://www.abbonamentircs.it/Abbonamenti/GestioneOfferte.action?idOfferta=258930" target=\"_blank\"><img src="http://max.rcs.it/libs/css/assets/banner_8.gif" alt=""></a></div>');
			//$("#topbanner").append('<div class=\"abb_super-banner2\">.</div>');
		}
		$(this).css("display","block");
	}

	if($("#pushbanner object").length>=1){
		$('#pushbanner').css("display","block");
	}
	
	if($("#skybanner").length>=1){
		$(this).css("display","block");
	}
	
	// REGOLA ALTEZZA BOX IN BASE AL MAGGIORE
		var i = 0;
		var arr = new Array();
		var nomeDiv = ".box_col_3 .blocco_post";

		function sortNumber(a,b) {
			return b - a;
		}

		function altezzaBoxMagazine(){
			$(nomeDiv).each( function(){
				arr[i] = $(this).height();
			    i++
			});
			var heightBox = arr.sort(sortNumber)[0];
		    $(nomeDiv).css("height",heightBox);
		}
		if ($(nomeDiv).length>=1){
			altezzaBoxMagazine();
		}
		function altezzaBoxNoleggio(){
			$(nomeDiv).each( function(){
				arr[i] = $(this).height();
			    i++
			});
			var heightBox = arr.sort(sortNumber)[0];
		    $(nomeDiv).css("height",heightBox);
		}
		if ($(nomeDiv).length>=1){
			altezzaBoxNoleggio();
		}
	
	
	if($('#email').length!=0){
		if(getParameterByName('newsMail') != ''){
			 $('#email').val(getParameterByName('newsMail').replace('%40', '@'));
		}
	}
	
	// MULTIMEDIA
	if($('#multimedia #player').length!=0){
		$('.text_maxi_video span').css('margin-top','33px');
	}
	
	link_expand();
	
	//MAXSTORE 
	$("#maxstore #title_gallery_bis").css('display','none');
	
	// LINK EDICOLA FOOTER
	var linkEdicola = $(".bgTitEdicola").attr("href");
	$(".footer_link a[title=Edicola]").attr({href:linkEdicola});
	
});
// Fine document.ready

document.onclick = ddmenu_close;

// Inizio window.load
$(window).load(function(){
	if($("#topbanner").length>=1){
		if($('body#cityguide').length!=0){
			if($('#menuNav').length!=0){
				$("#topbanner").addClass('bgCityG');
				//$("body#cityguide").css('background-position','0px 61px');
				//$("#headerNav").css('padding-top','91px');
				//$("#logo").css('top','73px');
				//$('#bottomNav').css('top','151px');
				$("body#cityguide").css('background-position','0px 78px');
				$("#headerNav").css('padding-top','18px');
				$("#logo").css('top','0px');
				$('#bottomNav').css('top','78px');
			}else{
				//$("#topbanner").addClass('bgCityG');
				//$("#headerNav").css('padding-top','0px');
				//$("#headerNav").css('height','30px');
				//$("#logo").css('top','-50px');
				//$('#bottomNav').css('top','29px');
				//$("body#cityguide").css('background-position','0px 29px');
			}
		}else{
			$("#topbanner").append('<div class=\"abb_super-banner\"><a href=\"http://www.abbonamentircs.it/Abbonamenti/GestioneOfferte.action?idOfferta=258930" target=\"_blank\"><img src="http://max.rcs.it/libs/css/assets/banner_8.gif" alt=""></a></div>');
			//$("#topbanner").append('<div class=\"abb_super-banner2\">.</div>');
		}
		$(this).css("display","block");
	}
	if($('.box_adv').children('div').length>=1){
		$('.box_adv').before("<div class='box_advTit'></div>");
		$('.box_adv').css('display','block');
	}
});


function getParameterByName( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

