/* country container */
var myWidth = 0, myHeight = 0,  myWidth_1 = 0, myHeight_1 = 0,  myWidth_2 = 0, myHeight_2 = 0;
function country(){
	$("a.framebox").click(function(){
		var url = $(this).attr("href");

		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth_1 = window.innerWidth;
			myHeight_1 = window.innerHeight;		
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth_1 = document.documentElement.clientWidth;
			myHeight_1 = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth_1 = document.body.clientWidth;
			myHeight_1 = document.body.clientHeight;
		}
		
		myWidth_2 = document.body.clientWidth;
		myHeight_2 = document.body.clientHeight;
		
		if (myWidth_1 > myWidth_2) {
			myWidth = myWidth_1-17;
		} else {
			myWidth = myWidth_2;
		}
		
		if (myHeight_1 > myHeight_2) {
			myHeight = myHeight_1-20;
		} else {
			myHeight = myHeight_2;
		}
		
//		alert (myWidth + " x " + myHeight);		
//		alert ("myHeight:" + myHeight + "px\n" + "myHeight_1:" + myHeight_1 + "px\n" + "myHeight_2:" + myHeight_2 + "px\n");
//		return false;
		
		$('#back').remove();
		$('#choose').remove();
		$('body').append('<div id="back"></div>');
		$('#back').css({width:myWidth, height:myHeight+20, background:'#000', opacity:0, position:'absolute', top:'0px', left:'0px', zIndex:1000});
		$('#back').animate({opacity:0.8},500,function(){
			$('body').append('<div id="choose"></div>');
			$('#choose').css({width:myWidth, textAlign:'center', background:'url(img/bg_choose_language.gif) repeat-x #ffffff', height:'480px', opacity:0, position:'absolute', top:'0px', left:'0px', top:'50%', marginTop:'0', zIndex:1200});
			$('#choose').animate({opacity:1, marginTop:'-240px'},500,function(){
				$('#choose').append('<iframe align="middle" id="iCountry" frameborder="0" height="480" scrolling="auto" src="'+url+'" width="1080"></iframe>');
		});		
		//$('body').ScrollTo(800); //////////////////////////////////////////////// COMMENTATO DALL'ORIGINALE
	});
		
		function closeIt() {
			$('#choose').animate({opacity:0},500,function(){
				$('#back').animate({opacity:0},500,function(){
					$('#choose').remove();
					$('#back').remove();
				});
			});
		}	
		$('#back').click(closeIt);
		$('a.closeFrame').click(function(){
			alert ($(this).html());
		});
		
		return false;
		
	});
}

window.onresize = function() {
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth_1 = window.innerWidth;
			myHeight_1 = window.innerHeight;		
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth_1 = document.documentElement.clientWidth;
			myHeight_1 = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth_1 = document.body.clientWidth;
			myHeight_1 = document.body.clientHeight;
		}
		
		myWidth_2 = document.body.clientWidth;
		myHeight_2 = document.body.clientHeight;
		
		if (myWidth_1 > myWidth_2) {
			myWidth = myWidth_1-17;
		} else {
			myWidth = myWidth_2;
		}
		
		if (myHeight_1 > myHeight_2) {
			myHeight = myHeight_1-20;
		} else {
			myHeight = myHeight_2;
		}
		
		$('#back').css({width:myWidth, height:myHeight+20});
		$('#choose').css({width:myWidth});
}



/* funzione tabs menu prodotti */
var querystring=location.href;
var tab;
function tabbIt() {
	if (querystring.search("tabs_")!=-1) {
		tab = querystring.substr(querystring.search("tabs_"),querystring.search("tabs_")+6);
//	alert("ciao1");
	} else {
//	alert("ciao2");
		tab = $("#tabs div[@id^='tabs_']:eq(0)").attr("id");
	}
	$("#tabs_ul li a").removeClass("attivo");
	$("#tabs_ul li a[@href='#"+tab+"']").addClass("attivo");
	$("#tabs div[@id^='tabs_']").hide();
	$("#tabs div#"+tab).show();

	$("#tabs_ul li a").click(function(){
		tab = $(this).attr("href");
		$("#tabs_ul li a").removeClass("attivo");
		$("#tabs_ul li a[@href='"+tab+"']").addClass("attivo");
		$("#tabs div[@id^='tabs_']").hide();
		$("#tabs div"+tab).show();
		return false;
	});
}

// funzione per nascondere un tab nei prodotti se il suo contenuto è nullo
function hideEmptyTab() {
	$("#tabs div[@id^='tabs_']").each(function(){
		thisId = $(this).attr("id");
		if($.trim($(this).html()) == "") {
			$(this).remove();
			$("#tabs_ul li a[@href='#" + thisId + "']").parent().remove();
		}
	});
	
	$("#tabs div#tabs_4").each(function(){
		if($(this).find("tr").size() == 0) {
			$(this).remove();
			$("#tabs_ul li a[@href='#tabs_4']").parent().remove();
		}
	});
}


/* funzione innermenu */
function innerMenu() {
	$("#inner_menu ul li a.on").not($("#inner_menu ul li ul li a.on")).next().show();
	$("#inner_menu ul li a").not($("#inner_menu ul li ul li a")).click(function(){
		if ($(this).attr("class")=="on") {
			$(this).removeClass("on").next().slideUp("normal");
		} else {
			$("#inner_menu ul li a.on").not($("#inner_menu ul li ul li a.on")).removeClass("on").next().slideUp("normal");
			$(this).addClass("on").next().slideDown("normal");
		}
	});
}


/* funzione innergallery */
function innerGallery() {
	nFigliVideo = $("#inner_video h3").next().find("li").size();
	var videoHeight = "";
	switch (nFigliVideo) {
		case 1:
			videoHeight = "85px";
		break;
		case 2:
			videoHeight = "167px";
		break;
		case 3:
			videoHeight = "250px";
		break;
	}
	
	
	nFigliPhoto = $("#inner_photo h3").next().find("li").size();
	var photoHeight = "";
	switch (nFigliPhoto) {
		case 1:
			photoHeight = "85px";
		break;
		case 2:
			photoHeight = "167px";
		break;
		case 3:
			photoHeight = "250px";
		break;
	}
	
	
	if ($("#inner_photo ul").size()) {
		$("#inner_video ul").css({padding:"0px 6px", height:0});
	} else {
		$("#inner_video ul").css("height",videoHeight);
	}
	
	$("#inner_photo ul").css("height",photoHeight);
	
	$("#inner_photo h3").mouseover(function(){
		$("#inner_photo ul").stopAll().animate({style:"padding:6px 6px 2px 6px; height:"+photoHeight+"; display:block;"},400,function(){$("#inner_photo h3").addClass("on");});
		$("#inner_video ul").stopAll().animate({style:"padding:0px 6px; height:0px; display:none;"},400,function(){$("#inner_video h3").removeClass("on");});
	});
	
	$("#inner_video h3").mouseover(function(){
		$("#inner_video ul").stopAll().animate({style:"padding:6px 6px 2px 6px; height:"+videoHeight+"; display:block;"},400,function(){$("#inner_video h3").addClass("on");});
		$("#inner_photo ul").stopAll().animate({style:"padding:0px 6px; height:0px; display:none;"},400,function(){$("#inner_photo h3").removeClass("on");});
	});
	
	$("#highlights h3").click(function(){
		if($(this).attr("class")=="on"){
				$("#highlights").find("h3").parent().find("ul").stopAll().animate({style:"padding:0px 6px; height:0px; display:none;"},400,function(){
	$("#highlights").find("h3").removeClass("on");																													});
			} else {
			$("#highlights").find("h3").addClass("on").parent().find("ul").stopAll().animate({style:"padding:6px 6px 2px 6px; height:250px; display:block;"},400);
		}
	});

}


function tooltip(){
	$("a.tooltip").mouseover(function(){
		var txt = $(this).attr("title");
		$(this).after("<span class='tool_wrap'><div class='tooltipz'>"+txt+"</div></span>");
		$(".tool_wrap").css("opacity",0.9);
		return false;
	});
	$("a.tooltip").mouseout(function(){
		$(this).css("position","static");
		$(this).next().remove();
		return false;
	});
}


function toolFirstSignUp() {
	//  Yes, I'd like to create a Technogym account.
	$("#pass_account > label > em").html('')
	$("#pass_account2 > label > em").html('')			
	$("#pass_account").hide();
	$("#pass_account2").hide();
	$("#signup_pass_1").val('')
	$("#signup_pass_2").val('')		
	$("#signup_account").click(function(){
		if($(this).attr("checked")){
			$("#pass_account > label > em").html('*')
			$("#pass_account2 > label > em").html('*')	
			$("#pass_account").show();
			$("#pass_account2").show();
		} else {
			$("#signup_pass_1").val('')
			$("#signup_pass_2").val('')			
			$("#pass_account > label > em").html('')
			$("#pass_account2 > label > em").html('')				
			$("#pass_account").hide();
			$("#pass_account2").hide();
		}
	});
}

function countryOnChange() {
	// al change della select country
	}

// funzione per recuperare l'id di un prodotto e evidenziarlo nell'inner_menu
function getMyOn() {
	if ($("#inner_title").size() && $("#inner_menu").size()) {
		$("#inner_menu ul li a").each(function(){
			if ($(this).html() == $("#inner_title").html()) {
				$(this).addClass("on");
			}
		});
	}
}


// funzione per alternare il colore delle righe nelle tabelle
function tableEvent() {if ($("table.events").size()){$("table.events tr:even").addClass("row_1");}}

/* init */
$(document).ready(function(){
	country();
	tabbIt();
});