var timeout=0;
var areaSito="";
var cl_newsletter="false";

function ie6custom(){
	if(isIE() && $.browser.version<=6){

	}
}

function fixPng(){
	if(isIE() && $.browser.version<=6){
		$("img").ifixpng();
		// $("#popNews").ifixpng();
		// $("#popStore").ifixpng();

	}
}

function attivaCufon(idElemento, callback){
	idElemento=(typeof(idElemento)=="undefined")?"":(idElemento+" ");
	//Cufon.replace(idElemento+'.helvetica', { fontFamily: 'helvetica', hover:'true' });
	Cufon.replace(idElemento+'.eurostile', { fontFamily: 'eurostile', hover:'true' });

	Cufon.CSS.ready(function(){
		try{ callback(); }catch(err){ }
	});
}

function actBottCheckbox(jqObjBott,jqObjInput){
	var valAtt=jqObjInput.val();
	valAtt=(valAtt==0)?1:0;
	jqObjInput.attr("value",valAtt);
	if(valAtt==0){ jqObjBott.removeClass("selected"); } else { jqObjBott.addClass("selected"); }
}

function objVis(obj, act){
	if(act==1){ $(obj).fadeIn(500); } else { $(obj).fadeOut(500); }
}

function objVisSwap(obj, tempo){
	if(typeof(tempo)=="undefined"){ tempo=100; }
	$(obj).slideToggle(tempo, function(){ /* nulla */ });
}

function txtCampiSwap(objContainer, obj){
	var campi=$(objContainer);
	$.each(campi, function(key, value){
		if($(value).attr("value")==$(value).attr("title") && $(obj).attr("value")==$(value).attr("value")){
			$(value).attr("value","");
		} else {
			if($(value).val()==""){
				$(value).attr("value",$(value).attr("title"));
			}
		}
	});
}

function resizeFooter(){

}

/* ------------------- FUNZIONI PER I FORM ----------------------------------- */

function getGifText(idText){
	img="img/"+idText+".gif";
	txt=arrJsTexts[idText];
	htmlRis='';
	htmlRis+='<img';
	htmlRis+=' src="'+img+'"';
	htmlRis+=' alt="'+txt+'"';
	htmlRis+=' title="'+txt+'"';
	htmlRis+=' />';
	return(htmlRis);
}

var scrolling=null;
function doJsScroll(container,px,time){
	scrolling = setInterval (function(){ $(container)[0].scrollBy(px); }, time );
}

function stopJsScroll(){
	clearInterval(scrolling);
}

function doAzione(action){

}

var timeFade=(isIE())?0:0;

function attivaRollOvers(){
	$(".rollover").bind("mouseover",function(){ $(this).attr('src',$(this).attr('imgOn')); });	
	$(".rollover").bind("mouseout",function(){ $(this).attr('src',$(this).attr('imgOff')); });	
}

function attivaBotts(area){
	attivaRollOvers();
}

/* --------------------------- SFONDO PROIETTORE ---------------------------------- */

function resetWH100(val_selector){
	$(val_selector).css("width","100%"); $(val_selector).width("100%");
	$(val_selector).css("height","100%"); $(val_selector).height("100%");
}

function resetW100Hauto(val_selector){
	$(val_selector).css("width","100%");  $(val_selector).width("100%");
	$(val_selector).css("height","auto"); $(val_selector).height("auto");
}

function resizeBackground(){
	var diffW_IE=0;
	var diffH_IE=0;
	if(isIE()){
		switch(true){
			case($.browser.version>7):
				diffW_IE=0;
				diffH_IE=0;
			break;
		}
	}
	resetWH100("#background");
	resetW100Hauto(".imgBgHome");
	if(isiPhone){
		var totalWidth=Math.max($(window).width(),$(document).width());
	} else {
		var totalWidth=$(window).width();
	}
	totalWidth=totalWidth-diffW_IE;
	if(isiPhone){
		var totalHeight=Math.max($(window).height(),$(document).height());
	} else {
		var totalHeight=$(window).height();
	}
	totalHeight=Math.max(totalHeight,$("#contImgBgHome").height());
	totalHeight=Math.max(totalHeight,$("#background").height());
	
	totalHeight=totalHeight-diffH_IE;
	$("#background").width(totalWidth);
	$("#background").height(totalHeight);
	
	if(totalHeight>126){
		$("#col1Int, #col2Int, #contScolled").css("min-height",(totalHeight-126)+"px");
		if($("#div.contNews").length>0){
			$("div.contNews").height((totalHeight)-$("div.contNews").offset().top);
		}
	}

	var objs=$(".imgBgHome");
	var totObjs=$(".imgBgHome").length;
	if(totObjs>0){
		$.each(objs, function(key, tmpObj){
			$(tmpObj).css("top","0px");
			$(tmpObj).css("left","0px");
			var imgW=parseInt($(tmpObj).width(),10);
			var imgH=parseInt($(tmpObj).height(),10);
			imgW=(imgW<=0)?1:imgW;
			imgH=(imgH<=0)?1:imgH;
			if((imgW/imgH)<(totalWidth/totalHeight)){
				//adatta alla larghezza e centra verticalmente
				$(tmpObj).css("width",totalWidth+"px"); $(tmpObj).width(totalWidth);
				$(tmpObj).css("height","auto");
				// centra verticalmente
				areaToScroll=parseInt(((totalHeight-$(tmpObj).height())/2),10);
				if(areaToScroll<0){
					$(tmpObj).animate({
						top: areaToScroll
					}, 0);
				} else {
					$(tmpObj).css("top","0px");
				}						
			} else {
				// adatta all'altezza
				$(tmpObj).css("height",totalHeight+"px"); $(tmpObj).height(totalHeight);
				$(tmpObj).css("width","auto");
				// centra orizzontalmente
				if($(tmpObj).height()>0 && $(tmpObj).width()>0){
					$(tmpObj).css("left",parseInt(((totalWidth-$(tmpObj).width())/2))+"px");
				} else {
					setTimeout(function(){ resizeBackground(); },500);
				}
			}


		});
	}
}

function resizeBackgroundHome(){
	var diffW_IE=0;
	var diffH_IE=0;
	if(isIE()){
		switch(true){
			case($.browser.version>7):
				diffW_IE=0;
				diffH_IE=0;
			break;
		}
	}
	resetWH100("#background");
	resetW100Hauto(".imgBgHome1");
	var totalWidth=Math.max($(window).width(),$(document).width());
	totalWidth=totalWidth-diffW_IE;
	var totalHeight=Math.max($(window).height(),$(document).height());
	totalHeight=Math.max(totalHeight,$("#contImgBgHome").height());
	totalHeight=totalHeight-diffH_IE;
	$("#background").width(totalWidth);
	$("#background").height(totalHeight);

	$("#contmain").height(totalHeight);
	// $("#contmain").css("background-color","FF0000");

	$("#imgBackgroundHome1").width("auto");
	$("#imgBackgroundHome1").height("auto");

	var imgW=parseInt($("#imgBackgroundHome1").width());
	var imgH=parseInt($("#imgBackgroundHome1").height());

	$(".imgBgHome1").css("top","98px");

	var stageImgWidth=990+parseInt((totalWidth-990)/2,10);
	var stageImgHeight=totalHeight-98;

	// test landscape
	if(stageImgWidth*imgH/imgW < stageImgHeight){
		// adattata alla larghezza è bassa in altezza => adatta all'altezza (minima)
		$(".imgBgHome1").height(stageImgHeight);
		$(".imgBgHome1").width("auto");
		if($(".imgBgHome1").width()>stageImgWidth){
			$(".imgBgHome1").css("left",-($(".imgBgHome1").width()-stageImgWidth));
		} else {
			$(".imgBgHome1").css("left",0);
		}
	} else {
		// adattata all'altezza è stretta in larghezza => adatta all'altezza (minima)
		$(".imgBgHome1").css("left",0);
		$(".imgBgHome1").width(stageImgWidth);
		$(".imgBgHome1").height("auto");
	}

	// $(".imgBgHome1").css("width","auto"); $(".imgBgHome1").width(990+parseInt((totalWidth-990)/2,10));
	// $(".imgBgHome1").css("height",(totalHeight-98)+"px"); $(".imgBgHome1").height(totalHeight-98);

	/*
	$(".imgBgHome1").css("height","auto"); $(".imgBgHome1").height("auto");
	$(".imgBgHome1").css("width",totalWidth+"px"); $(".imgBgHome1").width(totalWidth);
	*/
	if(false){}
	else if(imgH<(totalHeight-98)){ // resta bianco sotto? (es. landscape)
		/*
		$(".imgBgHome1").css("height",(totalHeight-98)+"px"); $(".imgBgHome1").height(totalHeight-98);
		$(".imgBgHome1").css("width","auto"); $(".imgBgHome1").width("auto");
		var imgW=parseInt($("#imgBackgroundHome1").width());
		if(imgW>990+parseInt((totalWidth-990)/2,10)){
			$(".imgBgHome1").css("left",-(imgW-(990+parseInt((totalWidth-990)/2,10))));
		}
		$('#imgBackgroundHome, .imgBgHome').css("top","0px");
		*/
		
	} else if(imgW<totalWidth){ // resta bianco destra? (es. portrait)
	}
	// centra orizzontalmente
	// $("#imgBackgroundHome1, .imgBgHome1").css("left",parseInt((($("#background").width()-$("#imgBackgroundHome").width())/2))+"px");
	// centra verticalmente
	// areaToScroll=parseInt((totalHeight-imgH)/2);


}

function changeBgImg(arrBgImgs, idAtt, newSrc, bianco, val_auto){
	attivaPulse(".close", 0);
	var imgNew=$('<img />');
	imgNew.animate({ opacity: 0.00 }, 0);
	loading(1);
	imgNew.bind("load",function(){
		loading(0);
		$("#tmcLogo img").attr("src",((parseInt(bianco,10)==1)?$("#tmcLogo img").attr("bianco"):$("#tmcLogo img").attr("nero")));
		// la inserisce trasparente, ne calcola posizione, poi la sposta insieme all'esistente, poi elimina la vecchia, poi da l'id alla nuova
		imgNew.attr("class","imgBgHome");
		imgNew.css("z-index","10");
		imgNew.attr("width","auto");
		imgNew.attr("height","auto");
		$("#contImgBgHome").append(imgNew);
		$('#imgBackgroundHome').attr("id","oldBg");
		imgNew.attr("id","imgBackgroundHome");
		resizeBackground();
		imgNew.animate({ opacity: 1.00 }, 0);
		offsetImg=imgNew.offset();
		vOffset=offsetImg.top;
		oOffset=offsetImg.left;

		var tipoGhigliottina=rand(1, 4);
		// tipoGhigliottina=2; // sovrascrive
		if(tipoGhigliottina==1){ // ghigliottina dall'alto al basso
			imgNew.animate({
				top: -(imgNew.height()-vOffset)
			}, 0);
			
			imgNew.animate({
				top: vOffset
			}, 1000);
			$("#oldBg").animate({
				top: (imgNew.height()+(4*vOffset))
			}, 1000, function(){
				$("#oldBg").remove();
				setTimeout(function(){
					attivaPulse(".close", 1);
				},1000);
			});
		}
		if(tipoGhigliottina==2){ // ghigliottina dal basso all'alto
			var totalHeight=Math.max($(window).height(),$(document).height());
			totalHeight=Math.max(totalHeight,$("#contImgBgHome").height());

			imgNew.animate({
				top: totalHeight+vOffset
			}, 0);
			
			imgNew.animate({
				top: vOffset
			}, 1000);
			$("#oldBg").animate({
				top: (-totalHeight+(vOffset))
			}, 1000, function(){
				$("#oldBg").remove();
				setTimeout(function(){
					attivaPulse(".close", 1);
				},1000);
			});
		}
		if(tipoGhigliottina==3){ // ghigliottina da sx a dx
			imgNew.animate({
				left: -(imgNew.width()-oOffset)
			}, 0);
			
			imgNew.animate({
				left: oOffset
			}, 1000);
			$("#oldBg").animate({
				left: (imgNew.width()+(4*oOffset))
			}, 1000, function(){
				$("#oldBg").remove();
				setTimeout(function(){
					attivaPulse(".close", 1);
				},1000);
			});
		}
		if(tipoGhigliottina==4){ // ghigliottina da dx a sx
			imgNew.animate({
				left: (imgNew.width()-oOffset)
			}, 0);
			
			imgNew.animate({
				left: oOffset
			}, 1000);
			$("#oldBg").animate({
				left: -(imgNew.width()+(4*oOffset))
			}, 1000, function(){
				$("#oldBg").remove();
				setTimeout(function(){
					attivaPulse(".close", 1);
				},1000);
			});
		}

	});
	imgNew.attr('src', newSrc);
}

function swapGllHome(arrBgImgs, idAtt){
	var totImgs=arrBgImgs.length;
	idAtt=idAtt+1;
	var newSrc=arrBgImgs[idAtt][0];
	if(typeof(newSrc)=="undefined"){ idAtt=1; newSrc=arrBgImgs[idAtt][0]; }
	do{
		idAtt=rand(1,(arrBgImgs.length)-1);
		newSrc=arrBgImgs[idAtt][0];
	}while(newSrc==$('#imgBackgroundHome').attr("src") || typeof(newSrc)=="undefined" || newSrc=="");
	// alert(newSrc);
	changeBgImg(arrBgImgs, idAtt, newSrc, arrBgImgs[idAtt][1], false);
}

function loadHomeBackgrounds(){
 var holder = $("#contImgBgHome");
 holder.empty();
 var loaded = new Array();
 var i1 = new Image();
 i1.src = HVA.domainLink+'img/bg/home/02.jpg';
 
 var i2 = new Image();
  i2.src = HVA.domainLink+'img/bg/home/01.jpg';
  
  var i3 = new Image();
   i3.src = HVA.domainLink+'img/bg/home/03.jpg';
   
   $(i1).load(function(e){loaded.push(i1); $(i1).addClass("imgBgHome1").appendTo(holder);});
   $(i2).load(function(e){loaded.push(i2); $(i2).addClass("imgBgHome1").appendTo(holder);});
   $(i3).load(function(e){loaded.push(i3); $(i3).addClass("imgBgHome1").appendTo(holder);});

   holder.children().css("opacity",0);
   
   $("#contBoxesH a").each(function(i,v){
     $(this).bind("mouseover",function(e){
       holder.children(".active").removeClass('active');
       $("#contBoxesH a.active").children("div.off").fadeIn(300);
       $("#contBoxesH a.active").children("div.on").fadeOut(300);
       $("#contBoxesH a.active").removeClass('active');
       
       $(this).addClass('active');
       $(loaded[i]).css({"z-index":3}).stop().fadeIn(1000).addClass('active');
       $(this).children("div.off").fadeOut(300);
       $(this).children("div.on").fadeIn(300);
     });
   });
}

function backgroundImg(){
	arrBgImgs.sort(randOrd);
	if($("#imgBackgroundHome").length<=0){ // appende immagine cha cambia
		var newSrc="img/0.gif";
		newImg=null;
		newImg=$("<img>");
		$(newImg).attr("id","imgBackgroundHome");
		$(newImg).attr("class","imgBgHome");
		$(newImg).attr("src",newSrc);
		$(newImg).css("z-index","10");
		$(newImg).attr("width","auto");
		$(newImg).attr("height","auto");
		$("#contImgBgHome").append(newImg);
	}
	swapGllHome(arrBgImgs, 1);
	return(false);
}

function setActiveBoxHome(){
	$("#contBoxesH a .on").hide(0);
	$("#boxProductsH .on").show(0);
	$("#boxProductsH .off").hide(0);
	$("#imgBackgroundHome1").unbind("load");
	$("#imgBackgroundHome1").bind("load",function(){ funzioniResize("home"); $("#imgBackgroundHome1").show(0); })
	$("#imgBackgroundHome1").attr("src",$("#boxProductsH").attr("img"));

	$("#contBoxesH a").bind("mouseover",function(){
		$("#contBoxesH a .on").hide(0);
		$("#contBoxesH a .off").show(0);
		$(this).children(".off").hide(0);	
		$(this).children(".on").show(0);
		// $("#imgBackgroundHome1").hide(0);
		$("#imgBackgroundHome1").unbind("load");
		$("#imgBackgroundHome1").bind("load",function(){ funzioniResize("home"); $("#imgBackgroundHome1").show(0); })
		$("#imgBackgroundHome1").attr("src",$(this).attr("img"));
	})

}

/* -------------------------- VIDEO -------------------------------- */

function playMovie(idVideo,idFlash){
	try{
		var movie = document.getElementById(idVideo);
		movie.play();	
	} catch(err){ }
	try{
		var flashObj = document.getElementById(idFlash);
		flashObj.playVideo();
	} catch(err){ }
	return(false);

}

function stopMovie(){
	try{
		var movie = document.getElementById(idVideo);
		movie.pause();	
	} catch(err){ }	
	try{
		var flashObj = document.getElementById(idFlash);
		flashObj.pauseVideo();
	} catch(err){ }

}

function attivaScrollBars(){
	$(".boxTxtScroll").jScrollPane({showArrows:false, dragMinHeight:13, dragMaxHeight:13, scrollbarWidth:13 });
	$('.jScrollPaneContainer').bind("click", function(e){ $('.jScrollPaneContainer').blur(); });
}
/*---------------------------ROLL OVER PAGINA PRODOTTI--------------------------------------------------*/
function setRollOverProduct(){
	$(".elMotoCellUp").bind("mouseover",function(){
		var box=$(this).parent().parent().parent().parent();
		var urlBig=$(this).attr('urlImgBigTH');
		var imgBig=$(box).children('.motoPR').children('.motoPRFoto').children('img');
		//console.log(imgBig);
		$(imgBig).attr('src',urlBig);
	});
}
/*--------------------------GALLERY PRODOTTI, CATEGORIA MEDIA ------------------------------------------*/
function setGalleryMedia(){
	
	$("#contThumbs .thumb").bind("click",function(){
		//var urlImg=$(this).attr("href");
		var urlImgBig=$(this).attr("urlBig");
		$("#grande").attr("src",urlImgBig);
		//$("#grandeUrl").attr("href",urlImg);
		var iden=$(this).attr("id_th");
		$("#grandeUrl").attr("iden",iden);
	});
	
	$(".topGallery .next").bind("click",function(){
		var id_photo=parseInt($("#grandeUrl").attr("iden"));
		var nro_photo=parseInt($('.contIntThumbs').attr('nro_thumb'));
		//console.log(nro_photo);
		id_photo=((id_photo+1>=nro_photo)?(parseInt(nro_photo-1)):id_photo+1);
		//alert(nro_photo);
		//console.log(parseInt(nro_photo-1));
		var obj=$("#contThumbs a[id_th|="+id_photo+"]");
		
		//console.log(obj);
		var span=$(obj).children('span');
		$('#contThumbs a span').removeClass('select');
		$(span).addClass('select');
		
		var urlImg=$(obj).attr("href");
		var urlImgBig=$(obj).attr("urlBig");
		$("#grande").attr("src",urlImgBig);
		$("#grandeUrl").attr("href",urlImg);
		var iden=$(obj).attr("id_th");
		$("#grandeUrl").attr("iden",iden);
	});
	
	$(".topGallery .prev").bind("click",function(){
		var id_photo=parseInt($("#grandeUrl").attr("iden"));
		var nro_photo=parseInt($('.contIntThumbs').attr('nro_thumb'));
		id_photo=((id_photo-1<0)?0:id_photo-1);
		var obj=$("#contThumbs a[id_th|="+id_photo+"]");
		
		var span=$(obj).children('span');
		$('#contThumbs a span').removeClass('select');
		$(span).addClass('select');
		
		var urlImg=$(obj).attr("href");
		var urlImgBig=$(obj).attr("urlBig");
		$("#grande").attr("src",urlImgBig);
		$("#grandeUrl").attr("href",urlImg);
		var iden=$(obj).attr("id_th");
		$("#grandeUrl").attr("iden",iden);
	});
}
function closeGalleryMedia(){
	$('#contContScrolled').css('position','absolute');
	$('#contGalleryMedia').hide();
	$('#contThumbs').hide();
}
function openGalleryMedia(val_idMedia){
		//alert('ggg');
	$.get(HVA.baseUrl+"/media_gallery.php",{
		idMedia: val_idMedia,
		time: unixTime(),
		navType: HVA.navType
	}, function(data){
		$("#contGalleryMedia").html(data);
		window.scrollTo(0,0);
		setGallery();
		$('#contGalleryMedia').show();
		$('#contContScrolled').css('position','fixed');
	});
	
	$.get(HVA.baseUrl+"/contThumbs.php",{
		idMedia: val_idMedia,
		time: unixTime(),
		navType: HVA.navType
	}, function(data){
		$("#contThumbs").html(data);
		window.scrollTo(0,0);
		setGallery();
		$('#contThumbs').show();
	});

}

function openGalleryMediaProduct(){
	window.scrollTo(0,0);
	$('#contContScrolled').css('position','fixed');
	$('#contGalleryMedia').show();
	$('#contThumbs').show();
}

//eventi galleria di gallery.php
function setGallery(){
	
	$("#contThumbs a").bind("click",function(){
		var urlImgBig=$(this).attr("urlBig");
		
		var span=$(this).children('span');
		$('#contThumbs a span').removeClass('select');
		$(span).addClass('select');
		
		$("#grande").attr("src",urlImgBig);
		//$("#grandeUrl").attr("href",urlImg);
		var iden=$(this).attr("id_th");
		$("#grandeUrl").attr("iden",iden);
	});
	
	$(".next").bind("click",function(){			 
		var id_photo=parseInt($("#grandeUrl").attr("iden"));
		var nro_photo=parseInt($('.contIntThumbs').attr('nro_thumb'));

		id_photo=((id_photo+1>=nro_photo)?nro_photo-1:id_photo+1);

		var obj=$("#contThumbs a[id_th|="+id_photo+"]");
		
		//console.log(id_photo);
		
		var span=$(obj).children('span');
		$('#contThumbs a span').removeClass('select');
		$(span).addClass('select');
		
		var urlImg=$(obj).attr("href");
		var urlImgBig=$(obj).attr("urlBig");
		$("#grande").attr("src",urlImgBig);
		$("#grandeUrl").attr("href",urlImg);
		var iden=$(obj).attr("id_th");
		$("#grandeUrl").attr("iden",iden);
	});
	
	$(".prev").bind("click",function(){
		var id_photo=parseInt($("#grandeUrl").attr("iden"));
		id_photo=((id_photo-1<0)?0:id_photo-1);
		var obj=$("#contThumbs a[id_th|="+id_photo+"]");
		
		var span=$(obj).children('span');
		$('#contThumbs a span').removeClass('select');
		$(span).addClass('select');
		
		var urlImg=$(obj).attr("href");
		var urlImgBig=$(obj).attr("urlBig");
		$("#grande").attr("src",urlImgBig);
		$("#grandeUrl").attr("href",urlImg);
		var iden=$(obj).attr("id_th");
		$("#grandeUrl").attr("iden",iden);
	});
}
//video gallery
function setGalleryVideo(){
	$(".video-item").bind("click",function(){
		//var urlImg=$(this).attr("href");
		//var urlImgBig=$(this).attr("urlBig");
		//$("#grande").attr("src",urlImgBig);
		//$("#grandeUrl").attr("href",urlImg);
		//var iden=$(this).attr("id_th");
		//$("#grandeUrl").attr("iden",iden);
	});
	
}
function closeGalleryVideo(){
	//$('#contContScrolled').css('position','relative');
	$('#contGalleryVideo').hide();
}
function openGalleryVideo(val_url){
	window.scrollTo(0,0);

	var swfVersionStr = "9.0.124";
	var xiSwfUrlStr = "";
	var flashvars = {url:val_url, usePlayPause: "1", useFit: "1", useLoop: "0", callbackEndVideoOn: "0", showControls:"1", marginDn:10, marginSxDx:10, autohide:"1" };
	var params = {};
	params.quality = "high";
	params.bgcolor = "#000000";
	params.play = "true";
	params.loop = "false";
	params.wmode = "opaque";
	params.scale = "noscale";
	params.menu = "false";
	params.devicefont = "false";
	params.salign = "";
	params.allowscriptaccess = "sameDomain";
	var attributes = {};
	attributes.id = "playervideo";
	attributes.name = "playervideo";
	attributes.align = "middle";
	swfobject.createCSS("html", "height:100%; background-color: #000000;");
	swfobject.createCSS("body", "margin:0; padding:0; overflow:hidden; height:100%;");
	
	$("#gllPlayerVideoInt").remove();
	$("#playervideo").remove();
	
	var divNew=$('<div />');
	divNew.attr("width","557");
	divNew.attr("height","321");
	divNew.attr("height","321");
	divNew.attr("id","gllPlayerVideoInt");

	$("#gllPlayerVideo").append(divNew);
	
	swfobject.embedSWF(
		HVA.domainLink+"playervideo.swf", "gllPlayerVideoInt",
		"100%", "100%",
		swfVersionStr, xiSwfUrlStr,
		flashvars, params, attributes);
	
	//$('#contContScrolled').css('position','fixed');
	$('#contGalleryVideo').show();
}

//start video
function startVideo(obj){
	//var var_key=$(obj).attr("key");
	//var var_tipo=$(obj).attr("tipo");
	//var var_url=$(obj).attr("url");
	var var_titolo=$(obj).attr("titolo");
	var var_sottotitolo=$(obj).attr("sottotitolo");
	$("#intTitVideo strong").html(var_titolo);	
	$("#intTitVideo span").html(var_sottotitolo);
	Cufon.replace('.bebas', { fontFamily: 'bebas', hover:'true' });
	var urlV=(var_tipo=="vjs")?"video_vjs.php":"video_yt.php";
	loading(1);
	$.post(urlV,{
		key: var_key,
		tipo: var_tipo,
		url: var_url,
		titolo: var_titolo,
		sottotitolo: var_sottotitolo,
		time: unixTime()
	}, function(data){
		loading(0);
		$("#intBoxVideo").html(data);
		if(var_tipo=="vjs"){
			VideoJS.setupAllWhenReady();	
		}
	});
}
//newsletter
function popnl(){
	var obj=$("#menuHeader a:contains('Newsletter')");
	//var obj = $("a.newsletterModal").parent();
	offsetDiv=$(obj).offset();
	vOffset=offsetDiv.top;
	oOffset=offsetDiv.left;
	itemW=$(obj).width();
	itemH=$(obj).height();
	vOffset=vOffset+parseInt((itemH)/2,10)+10-$(document).scrollTop();
	oOffset=oOffset-354+parseInt((itemW)/2,10);
	
	
	if(cl_newsletter=="false"){
		$('#popup_newsletter').show();	
		cl_newsletter="true";
		
		$("#popup_newsletter").after(
		  $("<div/>").attr("id","newsBG").html("&nbsp;").width($(window).width()).height($(window).height()).css(
		    {opacity:0,"backgroundColor":"#000000",
		    position:"fixed","top":0,"left":0,"z-index":1000})
		  );
		  
		  
  		$("#closeNL,#newsBG").click(function(e){
  		  cl_newsletter="true";
  		  popnl();
  		});
		  
		  $("#newsBG").animate({opacity:0.5},500);
		
		  $("#popup_newsletter").show().css({top: vOffset+20,left: oOffset}).animate({opacity:1,top:vOffset},500);
    /*	
    	$("#popup_newsletter").animate({
      		top: vOffset,
      		left: oOffset
      	}, 1000);*/

	}else{
		$('#popup_newsletter').stop().animate({opacity:0},100,function(){$('#popup_newsletter').hide()});
		$('#newsBG').stop().animate({opacity:0},500,function(){$("#newsBG").remove();});
		cl_newsletter="false";
		
	}
	
	return(false);
	
}

/* --------- FORMS -------------------- */

function contrContact(){
	$(".alertForm").html("&nbsp;");
	$.post(HVA.domainLink+"background.php",{
			act: "contact",
			DEMlang: $("#DEMlang").val(),
			nome: $("#nome").val(),
			email: $("#email").val(),
			department: $("#department").val(),
			messaggio: $("#messaggio").val(),
			privacy: $("#privacy:checked").val(),
			time: unixTime()
		}, function(data){
			if(data=="ok"){
				location.href="/"+($("#formJob #idLang").val())+"/company/contact?act=ok";
			} else {
				if(data=="nome_missing"){ $("#nome").focus(); $(".alertForm").html(arrJsTexts['alert_nome']); return(false); }
				if(data=="email_missing"){ $("#email").focus(); $(".alertForm").html(arrJsTexts['alert_email']); return(false); }
				if(data=="email_wrong"){ $("#email").focus(); $(".alertForm").html(arrJsTexts['alert_wrongemail']); return(false); }
				if(data=="messaggio_missing"){ $("#messaggio").focus(); $(".alertForm").html(arrJsTexts['alert_messaggio']); return(false); }
				if(data=="privacy"){ $("#privacy").focus(); $(".alertForm").html(arrJsTexts['alert_privacy']); return(false); }
				$(".alertForm").html("ERROR. Please try again later.");
				return(false);
				// location.href="/"+($("#formJob #idLang").val())+"/company/contact?act=ko";
			}
		});
	return(false);
}

function attivaJobSel(){
	$(".itemJob").bind("click", function(){
		var obj=this;
		if($(obj).attr("stato")=="0"){
			$(obj).attr("stato","1");
			$("#"+$(obj).attr("code")).attr("stato","1");
			$("#"+$(obj).attr("code")).val("1");
			$(obj).addClass("selected");
		} else {
			$(obj).attr("stato","0");
			$("#"+$(obj).attr("code")).val("0");
			$(obj).removeClass("selected");
		}

	});	
}

function attivaJobCV(){
		
}

function contrNL(){
	$(".alertForm1").html("&nbsp;");
	$.post(HVA.domainLink+"background.php",{
			act: "newsletterIns",
			nome: $("#NLnome").val(),
			email: $("#NLemail").val(),
			country: $("#NLcountry").val(),
			nascita: $("#NLnascita").val(),
			tipomoto: $("#NLtipomoto").val(),
			privacy: $("#NLprivacy:checked").val(),
			time: unixTime()
		}, function(data){
			if(data=="ok"){
				location.href="/"+($("#idLangNl").val())+"/company/contact?act=ok";
			} else {
				if(data=="nome_missing"){ $("#NLnome").focus(); $(".alertForm1").html(arrJsTexts['alert_nome']); return(false); }
				if(data=="email_missing"){ $("#NLemail").focus(); $(".alertForm1").html(arrJsTexts['alert_email']); return(false); }
				if(data=="email_wrong"){ $("#NLemail").focus(); $(".alertForm1").html(arrJsTexts['alert_wrongemail']); return(false); }
				if(data=="country_missing"){ $("#NLcountry").focus(); $(".alertForm1").html(arrJsTexts['alert_nazione']); return(false); }
				if(data=="nascita_wrong"){ $("#NLnascita").focus(); $(".alertForm1").html(arrJsTexts['alert_nascita']); return(false); }
				if(data=="privacy"){ $("#NLprivacy").focus(); $(".alertForm1").html(arrJsTexts['alert_privacy']); return(false); }
				$(".alertForm").html("ERROR. Please try again later.");
				return(false);
				// location.href="/"+($("#idLangNl").val())+"/company/contact?act=ko";
			}
		});
	return(false);
}
/*******************imposta galleria prodotto************************/
function setGalleryDxProduct(){
	$(".gallery-products .arrow_up").bind("click", function(){
	});
	$(".gallery-products .arrow_down").bind("click", function(){
	});
}
/************************GOOGLE MAP DETT LOCALITY RACE*******************************/
function showGoogleMap() {
	 // document.getElementById('daddr').value=address;
	 var address=$("#address").val();
	 var idDiv=$("#idDiv").val();
	 if (GBrowserIsCompatible()) {
		   geocoder = new GClientGeocoder();
	 }
	
	 if (geocoder) {
		   geocoder.getLatLng(
			 address,
			 function(point) {
				   if (!point) {
					 alert(address + " non trovato");
				   } else {
				   /*zoom*/
	
						   coordinate = point;
	
						   map = new GMap2(document.getElementById(idDiv));
						   
						   /*mappa - satellite - ibrida */
						   map.addControl(new GMapTypeControl());
						   
						   /*controller con barra vert*/
						   // map.addControl(new GSmallMapControl());
						   map.addControl(new GLargeMapControl());
						   
						   /*zoom box, in basso a dx*/
							/*
							map.addControl(new GOverviewMapControl(),
						   new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(9, 9)));
						   */
						   
						   /*COORDINATE DI PARTENZA DELLA MAPPA*/
						   map.setCenter(point, 15);
						   // map.setCenter(point, 12);
						   var marker = new GMarker(point);
						   map.addOverlay(marker);
						   if(titolo){
								   marker.openInfoWindowHtml(titolo+" &nbsp;  ");
						   } else {
								   marker.openInfoWindowHtml(address+" &nbsp;  ");
						   }
				   }
			 }
		   );
	 }
}
/***********************SCROLL GALLERY PRODUCTS IN home_product.php*******************************/
function galleryScroll(){
	/* scroll riders */
	if($('.cont-product').size()!=0){
		$('.cont-product').height($(window).height()-$('#headerInt').height()-395);
		animated = false;
		$('#scroll-down').click(function(){
			nn =67;
			//$('.cont-product > ul:first > li:first').height()+10;
			topp = parseInt($('.cont-product > ul:first').css('top').split('px')[0]);
			pos=parseInt(-($('.cont-product > ul:first').height()-$('.cont-product').height()-nn));
			if(topp > pos ){	
				newTop = Number(topp)-Number(nn);
				if(!animated){
					animated = true;
					$('.cont-product > ul:first').animate({'top':newTop+'px'}, 400, function(){
						animated = false;
						if(topp<=0){ $('#scroll-up').css('visibility','visible');}
						nnnn = $('.cont-product > ul:first').height()-$('.cont-product').height()-nn;
						if(topp<-nnnn+nn){ $('#scroll-down').css('visibility','hidden'); }
					});
				}
			}
		});
	
		$('#scroll-up').click(function(){
			nn2 = 67;
			//$('.cont-product > ul:first > li:first').height()+10;
			topp2 = $('.cont-product > ul:first').css('top').split('px')[0];
			if(topp2<=-nn2){
				newTop2 = Number(topp2)+Number(nn2);
				if(!animated){
					animated = true;
					$('.cont-product > ul:first').animate({'top':newTop2+'px'}, 400, function(){
						animated = false;
						if(topp2>=-nn2){ $('#scroll-up').css('visibility','hidden');}
						nnnn2 = $('.cont-product > ul:first').height();
						if(topp2>Number(-nnnn2)){ $('#scroll-down').css('visibility','visible'); }
					});	
				}
			}
		});
	
	}	
}
/*************************/
function showAllProducts(){
	$(".cont-product ul").animate({top:0},0);
	$(".cont-product ul li").css('display','block');
	$(".col-dx-product .colDx a").removeClass('select');
	$('#scroll-up').css('visibility','hidden');
	$('#scroll-down').css('visibility','visible'); 
	$(".shadow").css('display','block');
	
}
/**************attiva btn view more race product.php******************/
function viewMoreRace(){
	var status=$('.cont-more_races').attr('status');
	if(status=='close'){
		$('.cont-more_races').css('display','block');
		$('.cont-more_races').attr('status','open');
		funzioniResize("products");
	}else{
		$('.cont-more_races').css('display','none');
		$('.cont-more_races').attr('status','close');
		funzioniResize("products");
	}
}
function viewVideoGallery(){
	var status=$('.cont-more-videos').attr('status');
	if(status=='close'){
		$('.cont-more-videos').css('display','block');
		$('.cont-more-videos').attr('status','open');
		funzioniResize("products");
	}else{
		$('.cont-more-videos').css('display','none');
		$('.cont-more-videos').attr('status','close');
		funzioniResize("products");
	}
}
/****************************/

function openTabMoto(idTab){
	if(!($('div[title="'+idTab+'"]').length>0)){
		idTab="intro";
	}
      $('.selectedPanel').removeClass('selectedPanel').hide();
      $('div[title="'+idTab+'"]').show().addClass('selectedPanel');
}

function initPageScripts(url){
  $(window).hashchange( function(){
      var hash = location.hash;

     if(hash != "#!/race"){
       $("#raceTrack").hide();
     }
      
	  switch(hash){
        case "#!/race":
          openBtnRaceTrack();
          $("#tLoader").remove();
        break;
        
        case "#!/social":
          openBtnSocialConnection();
          $("#tLoader").remove();
        break;
        
        case "#!/media":
        setActiveSubNav(hash);
          $.get(HVA.baseUrl+"/"+url,{
        		motoID: HVA.productId,
        		time: unixTime(),
        		navType: HVA.navType,
        		p: 'media',
        		currLang: HVA.locale
        	}, function(data){
				$(".cellMSP a").removeClass("selected");
        		$("#contentPlaceHolder").html(data);
        		setHeightSchedaProduct();
        		$("#tLoader, .smLoader").remove();
				openTabMoto('media');
        	});
        break;
        
        case "#!/specifications":
         setActiveSubNav(hash);
          $.get(HVA.baseUrl+"/"+url,{
        		motoID: HVA.productId,
        		time: unixTime(),
        		navType: HVA.navType,
        		p: 'specifications',
        		currLang: HVA.locale
        	}, function(data){
				$(".cellMSP a").removeClass("selected");
        		$("#contentPlaceHolder").html(data);
        		setHeightSchedaProduct();
        		$("#tLoader, .smLoader").remove();
				openTabMoto('specifications');
        	});
        break;
        
        case "#!/downloads":
         setActiveSubNav(hash);
          $.get(HVA.baseUrl+"/"+url,{
        		motoID: HVA.productId,
        		time: unixTime(),
        		navType: HVA.navType,
        		p: 'downloads',
        		currLang: HVA.locale
        	}, function(data){
				$(".cellMSP a").removeClass("selected");
        		$("#contentPlaceHolder").html(data);
        		setHeightSchedaProduct();
        		$("#tLoader, .smLoader").remove();
				openTabMoto('downloads');
        	});
        break;
        
        case "#!/special-parts":
         setActiveSubNav(hash);
          $.get(HVA.baseUrl+"/"+url,{
        		motoID: HVA.productId,
        		time: unixTime(),
        		navType: HVA.navType,
        		modelYear: HVA.modelYear,
        		p: 'special_parts',
        		currLang: HVA.locale
        	}, function(data){
				$(".cellMSP a").removeClass("selected");
        		$("#contentPlaceHolder").html(data);
        		setHeightSchedaProduct();
        		$("#tLoader, .smLoader").remove();
				openTabMoto('special_parts');
        	});
        break;
        
        //default: // was default but now loads on init also dangerous because if we want to take off the hash its the default
        case "#!/highlights":
        setActiveSubNav(hash);
         $.get(HVA.baseUrl+"/"+url,{
       		motoID: HVA.productId,
       		time: unixTime(),
       		navType: HVA.navType,
       		p: 'highlight',
      		currLang: HVA.locale
       	}, function(data){
			$(".cellMSP a").removeClass("selected");
       		$("#contentPlaceHolder").html(data);
       		setHeightSchedaProduct();
       		$("#tLoader, .smLoader").remove();
			openTabMoto('highlight');
       	});
        break;
		
      }

    });

    // Since the event is only triggered when the hash changes, we need to trigger
    // the event now, to handle the hash the page may have loaded with.
    $(window).hashchange();
  
  $("div.cont-top-race-track, div.cont-top-sc").height($(window).height() - $("div.cont-top-race-track").offset().top);
  //$('#bottsMenuSchedaProd .cellMSP a').
  
  $('a[href^="#!/"]').each(function(i,v){
    var scope = $(this);
    scope.click(function(e){
      $(this).after($("<img/>").attr({src:HVA.domainLink+"img/ajax-loader-small.gif",id:"tLoader"}).addClass("smLoader"));
	  if($(this).attr("href")=="#!/custom"){
	     $("#tLoader, .smLoader").remove();
	  }
    });
  });
  
  
}

function setActiveSubNav(h){
	// alert(h);
  $(".cellMSP a").removeClass("selected");
  $('.cellMSP a[href="'+h+'"]').addClass("selected");
  Cufon.refresh();
}

function openBtnRaceTrack(id){
	if($("#socialConnect").hasClass('open')){
	  // ideally we should check to see if its animating too.
	  closeSocialConnection(false);
	} // end check to see if its open

	$('.links .btn_sc').removeClass('selected');
	$('.links .btn_vrt').addClass('selected');
	
	// slide the panel out
	$("#raceTrack").show();
	 $("#overlay_product").fadeIn(500);
	$('.cont-race-track').animate({"right":"0px"},500,function(){
	 
	  $(".cont-top-race-track").addClass('open');
	});
	
	if($("#raceTrackContent").length < 1){
	  $("#rtLoader").show();
	  $.get(HVA.domainLink+"/race_track_server.php",{
  		motoID: HVA.productId,
  		time: unixTime(),
  		navType: HVA.navType,
  		marketId: HVA.marketId,
  		subCatId: HVA.subCatId,
  		locale: HVA.locale
  	}, function(data){
  	  $("#rtLoader").hide();
  		$("#raceOverContent").html(data);
  	});
  
  }
	
}
function closeRaceTrack(clearhash){
	$(".cont-top-race-track").removeClass('open');
	$('.cont-race-track').animate({"right":"-450px"},500,function(){
	  if(clearhash) $("#overlay_product").fadeOut(500,function(){$("div.cont-top-race-track").hide();});
	  
	});
	if(clearhash)	window.location.hash = "";
	
	$('.links .btn_vrt').removeClass('selected');
	$('.links .btn_sc').removeClass('selected');
	//attivaCufon('');
}
function openBtnSocialConnection(){
	if($("#raceTrack").hasClass('open')){
	  // ideally we should check to see if its animating too.
	  closeRaceTrack(false);
	} // end check to see if its open
	
	$('.links .btn_vrt').removeClass('selected');
	$('.links .btn_sc').addClass('selected');
	
	// slide the panel out
	$("#socialConnect").show();
	 $("#overlay_product").fadeIn(500);
	$('.cont-sc').animate({"right":"0px"},500,function(){
	 
	  $("#socialConnect").addClass('open');
	});
	/*
	$.get(HVA.domainLink+"/social_connect_server.php",{
		motoID: HVA.productId,
		time: unixTime(),
		navType: HVA.navType
	}, function(data){
		$("#raceOverContent").html(data);
	});*/
  
}
function closeSocialConnection(clearhash){

	$("#socialConnect").removeClass('open');
	$('.cont-sc').animate({"right":"-450px"},500,function(){
	  if(clearhash) $("#overlay_product").fadeOut(500,function(){});
	  $("#socialConnect").hide();
	});
	if(clearhash)	window.location.hash = "";
	
	$('.links .btn_vrt').removeClass('selected');
	$('.links .btn_sc').removeClass('selected');
}

function setPosInfoPromo(){
	var arr;
	if(self.innerWidth!=undefined)arr= [self.innerWidth,self.innerHeight];
	else{
		var D= document.documentElement;
		if(D) arr= [D.clientWidth,D.clientHeight];
	}
	var h=parseInt(arr[1]);
	var pos=parseInt(h-256);
	//$('.bottom_page_promo').css('height',256+'px');
	//$('.bottom_page_promo').css('top',pos+'px');
	//
}

function showAllTextProduct(){
	var th=$('.read_more_product').parent();
	var obj=$(th).attr('testo');
	$(th).html(obj);
}

function setHeightSchedaProduct(){
	var arr;
	if(self.innerWidth!=undefined)arr= [self.innerWidth,self.innerHeight];
	else{
		var D= document.documentElement;
		if(D) arr= [D.clientWidth,D.clientHeight];
	}
	var h=parseInt(arr[1]);
	var h_cont=$('.contenitore').height()+126;
	//alert(h_cont);
	if(h_cont<h){
		$('#schedaProd').css('min-height',h-(133+281)+'px');
	}
}

function setcontProductRangeHeight(){
	//$('#contProductRange').css('height',parseInt($('#contProductRange').height()+456)+'px');
}
/*show modelli moto**/
function resizeContMotos(){
	/* scroll riders */
	if($('.cont-motos').size()!=0){
		var hitem=65;
		var hbox=($(window).height())-530;
		hbox=hbox-(hbox%hitem);
		$('.cont-motos').height(hbox);
		
		var nro_photos=$('.cont-motos ul').children('.ch_moto').length;
		var h=hitem*nro_photos;
		if(h<$(window).height()-530){
			$('.cont-mod-moto #scroll-up-moto').css('visibility','hidden');	
			$('.cont-mod-moto #scroll-down-moto').css('visibility','hidden');	
			$('.cont-mod-moto').css('overflow','visible');	
			var lg=$('.cont-motos ul').children('.ch_moto').length;
			$('.cont-motos').height(hitem*lg);
		}else{
			$('.cont-mod-moto #scroll-up-moto').css('visibility','visible');	
			$('.cont-mod-moto #scroll-down-moto').css('visibility','visible');	
			$('.cont-mod-moto').css('overflow','hidden');	
		}
		animated = false;
		
		$('#scroll-down-moto').click(function(){
			
			nn =62;
			
			//$('.cont-product > ul:first > li:first').height()+10;
			topp = parseInt($('.cont-motos > ul:first').css('top').split('px')[0]);
			pos=parseInt(-($('.cont-motos> ul:first').height()-$('.cont-motos').height()));
			
			if(topp > pos ){
				newTop = Number(topp)-Number(nn);
				if(!animated){
					animated = true;
					$('.cont-motos> ul:first').animate({'top':newTop+'px'}, 400, function(){
						animated = false;
						if(topp<=0){ $('#scroll-up-moto').css('visibility','visible');}
						nnnn = $('.cont-motos > ul:first').height()-$('.cont-motos').height();
						if(topp<-nnnn+nn){ $('#scroll-down-moto').css('visibility','hidden'); }
					});
				}
			}
		});
	
		$('#scroll-up-moto').click(function(){
			nn2 = 62;
			
			topp2 = $('.cont-motos > ul:first').css('top').split('px')[0];
			
			if(topp2<=-nn2){
				newTop2 = Number(topp2)+Number(nn2);
				if(!animated){
					animated = true;
					$('.cont-motos > ul:first').animate({'top':newTop2+'px'}, 400, function(){
						animated = false;
						if(topp2>=nn2){ $('#scroll-up-moto').css('visibility','hidden');}
						
						nnnn2 = $('.cont-motos > ul:first').height();
						
						if(topp2>Number(-nnnn2)){ $('#scroll-down-moto').css('visibility','visible'); }
					});	
				}
			}
		});
	
	}	
}

var pp_info=false;
$(document).ready(function(){
	$('#menuSxH .info').click(function(){
		if(pp_info==false){
			$('.cont-pp-info').css('display','block');		
			pp_info=true;
		}else{
			$('.cont-pp-info').css('display','none');		
			pp_info=false;
		}
	});					   
						   
});

function initChampionshipPage(){
  $(window).hashchange( function(){
     var hash = location.hash;
         
         if(hash != ""){
           setChampionshipContent(hash.replace( /^#!\//, '' ));
      
          $(".col-int-championship a.btn").each(function(){
              if($(this).attr("href") == hash){
                $(".col-int-championship a.btn").removeClass("selected");
                $(this).addClass("selected");
                Cufon.refresh();
              }
          });
        
        }else{
          $(".col-int-championship a[href='#!/races']").addClass("selected");
          Cufon.refresh();
        }
  
   });

   // Since the event is only triggered when the hash changes, we need to trigger
   // the event now, to handle the hash the page may have loaded with.
   $(window).hashchange();

  $(".col-int-championship a.btn").click(function(e){
    $(".col-int-championship a.btn").removeClass("selected");
    $(this).addClass("selected");
    $(this).after($("<img/>").attr({src:HVA.domainLink+"img/ajax-loader-small.gif",id:"tLoader"}).addClass("smLoader"));
    Cufon.refresh();
  });
  
  
  
  $("#champContentHolder table a").live("click",function(e){
      return false;
    });
}

function setChampionshipContent(cont){
  $("#largePulse").show();
  $.get(HVA.baseUrl+"/championship_server.php",{
		content: cont,
		time: unixTime(),
		market: HVA.market,
		contentType: HVA.contentType,
		locale: HVA.locale,
		cats: HVA.cats
	}, function(data){
		$("#champContentHolder").html(data);
		$("#tLoader").remove();
		showRaces();
		Cufon.refresh();
	});
}

function contrVin(lang){
	$(".alertForm").html("&nbsp;");
	if($("#vinCode").val()==""){
		$(".alertForm").html(($("#DEMlang").val()=="it")?"Inserire il codice VIN":"Please insert VIN number");
	} else {
		$("#formVin").submit();
	}
	return(false);	
}

var nextSelector = function(selector) {
	return $(selector).is(':last-child') ?
		   $(selector).siblings(':first-child') :
    	   $(selector).next();
};

// JavaScript Document
function slideshowHome(){
	//$(function() {
	//console.log('accedi');
	  var panels = [];
	  $('a.dot_home').each(function(i,v){ panels.push('#'+$(this).attr('id'))});
    $(".slideshow-home-int").jCarouselLite({
		btnGo:panels,
		start:0,
		auto: 5000,
		speed: 1000,
		circular:true,
		beforeStart: function(a){
		  var nn = nextSelector('.dot_home.selected');
		  $('.dot_home.selected').removeClass('selected');
		  nn.addClass('selected');}	
    });
   //});
    //console.log('accedi1');
	$("a.dot_home").bind("click",function(){
		$("a.dot_home.selected").removeClass("selected");
		$(this).addClass("selected");
	});
	//window.setInterval(gotoNextDot,6000);
}

function gotoNextDot(){	
	var nDot=(($(".contDots a.selected").attr("idDot")=='Nan')?1:parseInt($(".contDots a.selected").attr("iddot")));							 
	var newDot= nDot+ 1;
	newDot=(newDot > $('.contDots').length)? 0 : newDot;

	$(".contDots a").removeClass("selected");
	$("#dotSlide"+newDot).addClass("selected");
}

function closeNations(){
	$('#popup_nations').stop().animate({opacity:0},100,function(){$('#popup_nations').hide()});
	$('#newsBG').stop().animate({opacity:0},500,function(){$("#newsBG").remove();});
	return(false);
}

function openNations(){
	$('#popup_nations').stop().animate({opacity:10},100,function(){$('#popup_nations').show()});
	$("#popup_nations").after(
		$("<div/>").attr("id","newsBG").html("&nbsp;").width($(window).width()).height($(window).height()).css({opacity:0,"backgroundColor":"#000000", position:"fixed","top":0,"left":0,"z-index":1000})
	);
	$("#newsBG").click(function(e){
		closeNations();
	});
	$("#newsBG").animate({opacity:0.5},500);
	return(false);
}

function closeRegions(){
	$('#popup_regions').stop().animate({opacity:0},100,function(){$('#popup_regions').hide()});
	$('#newsBG').stop().animate({opacity:0},500,function(){$("#newsBG").remove();});
	return(false);
}

function openRegions(){
	$('#popup_regions').stop().animate({opacity:10},100,function(){$('#popup_regions').show()});
	$("#popup_regions").after(
		$("<div/>").attr("id","newsBG").html("&nbsp;").width($(window).width()).height($(window).height()).css({opacity:0,"backgroundColor":"#000000", position:"fixed","top":0,"left":0,"z-index":1000})
	);
	$("#newsBG").click(function(e){
		closeRegions();
	});
	$("#newsBG").animate({opacity:0.5},500);
	return(false);
}

function setGllPag(val_idPag,val_lang,domainLink){
	var obj=$("#contImgBgHome");
	if(obj.length>0){
		$.post(domainLink+"background.php",{
			idPag: val_idPag,
			lang: val_lang,
			act: "getImgPag",
			time: unixTime()
		}, function(data){
			if(data!=""){
				$("#contImgBgHome").html(data);
				resizeBackground();
				setTimeout(function(){ resizeBackground(); },1000);
			}
		});
	}
}


