

/* country container */
var myWidth = 0, myHeight = 0,  myWidth_1 = 0, myHeight_1 = 0,  myWidth_2 = 0, myHeight_2 = 0;
function frameBox(){
	$("a.framebox").click(function(){
		
		//hide swf
		$("#flash").css({ display: "none" })
	
		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, background:'url(img/bg_choose_language.gif) repeat-x #ffffff', height:'400px', opacity:0, position:'absolute', top:'0px', left:'0px', top:'50%', marginTop:'0', zIndex:1200});
			$('#choose').animate({opacity:1, marginTop:'-180px'},500,function(){
				$('#choose').append('<iframe align="middle" id="iCountry" frameborder="0" height="400" scrolling="auto" src="'+url+'" width="100%"></iframe>');
		});		
		$('body').ScrollTo(800);
	});
		
		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);
	} else {
		tab = "tabs_1";
	}
	$("#tabs_ul li a").removeClass("on");
	$("#tabs_ul li a[@href='#"+tab+"']").addClass("on");
	$("#tabs div[@id^='tabs_']").hide();
	$("#tabs div#"+tab).show();

	$("#tabs_ul li a").click(function(){
		tab = $(this).attr("href");
		$("#tabs_ul li a").removeClass("on");
		$("#tabs_ul li a[@href='"+tab+"']").addClass("on");
		$("#tabs div[@id^='tabs_']").hide();
		$("#tabs div"+tab).show();
	});
}


/* 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() {
	$("#inner_video ul").css({padding:"0px 6px", height:0});
	
	$("#inner_photo h3").mouseover(function(){
		$("#inner_photo ul").stopAll().animate({style:"padding:6px 6px 2px 6px; height:250px; 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:250px; 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").hide();
	$("#pass_account2").hide();
	$("#signup_account").click(function(){
		if($(this).attr("checked")){
			$("#pass_account").show();
			$("#pass_account2").show();
		} else {
			$("#pass_account").hide();
			$("#pass_account2").hide();
		}
	});
}

function submitFormOnEnterKey(e) {		  
	var code;
	if (!e) 
	{
		var e = window.event;
		if (e.keyCode) code = e.keyCode;
	}
	else 
	{
		if (e.which) code = e.which;
	}
	if (code == 13) {
		return true
	} else {
		return false	
	}
	//var character = String.fromCharCode(code);
	//alert('Character was ' + character);		  
}

/* init */
$(document).ready(function(){
	frameBox();
/*
	tabbIt();
	innerMenu();
	innerGallery();
	tooltip();
	toolFirstSignUp();
*/
});
