function addOnload(fn){
    var nowOnload = window.onload; // Let's save the existing assignment, if any
    window.onload = function () {
        fn();
        // Now we call old function which was assigned to onLoad, thus playing nice
        if(nowOnload != null && typeof(nowOnload) == 'function') {
            nowOnload();
        }
    }
}

isIE6 = /msie|MSIE 6/.test(navigator.userAgent);

function sobre(el){
	$("#sobre01,#sobre02,#sobre03,#sobre04,#sobre05").hide();
	$("#linksobre01,#linksobre02,#linksobre03,#linksobre04,#linksobre05").removeClass("on");
	$("#sobre"+el).show();
	$("#linksobre"+el).addClass("on");
	if(el == "05"){
		$(function(){
			// this initialises the demo scollpanes on the page.
			$('#pane2').jScrollPane({showArrows:true, scrollbarWidth: 17, arrowSize: 17});
		});
	}
	showhidesolucoes();
}

function addOnresize(fn){
    var nowOnresize = window.onresize; // Let's save the existing assignment, if any
    window.onresize = function () {
        fn();
        // Now we call old function which was assigned to onresize, thus playing nice
        if(nowOnresize != null && typeof(nowOnresize) == 'function') {
            nowOnresize();
        }
    }
}

function addOnscroll(fn){
    var nowOnscroll = window.onresize; // Let's save the existing assignment, if any
    window.onscroll = function () {
        fn();
        // Now we call old function which was assigned to onresize, thus playing nice
        if(nowOnscroll != null && typeof(nowOnscroll) == 'function') {
            nowOnscroll();
        }
    }
}

function chkwidth(){
	if(!isIE6){	
		var origarea = 1070;
		//var globalsize = 12000; 			quando tiver depoimentos, retornar para 12000
		var globalsize = 12000;
		var clientarea = document.body.offsetWidth;
	
		if(clientarea > origarea){
			$(".stage-area").css("width", clientarea+"px");
			//globalsize = clientarea * 6; 			quando tiver depoimentos, retornar para 6
			globalsize = clientarea * 5;
		}else{
			$(".stage-area").css("width", origarea+"px");
			//globalsize = origarea * 6; 			quando tiver depoimentos, retornar para 6
			globalsize = origarea * 5;
		}


		$("#top-regua").css("width", globalsize+"px");
		$("#bottom-regua").css("width", globalsize+"px");
		$("#setas").css("width", globalsize+"px");
		$("#global").css("width", globalsize+"px");
	}
}
var cont_stage1 = 0;
var cont_stage2 = 0;
var cont_stage3 = 0;
var cont_stage5 = 0;
var cont_stage6 = 0;

function chkPositions(){
	if(!isIE6){
		$("#menu ul").slideUp();
		
		var posmenu = $('#menu').position().left;
		var stagewidth = parseInt($(".stage-area").css("width"));
	
		var stage1 = stagewidth;
		var stage2 = stagewidth * 2;
		var stage3 = stagewidth * 3;
		var stage5 = stagewidth * 4;
		var stage6 = stagewidth * 5;
	
		var stage1_inicio = stagewidth;
		var stage2_inicio = stage1 / 5;
		var stage3_inicio = stage1 + (stage1 / 5);
		var stage5_inicio = stage2 + (stage1 / 5);
		var stage6_inicio = stage3 + (stage1 / 5);
	
		var stage1_fim = stage1 + (stage1 / 3);
		var stage2_fim = stage2 + (stage1 / 3);
		var stage3_fim = stage3 + (stage1 / 3);
		var stage5_fim = stage5 + (stage1 / 3);
		var stage6_fim = stage6 + (stage1 / 3);
	
	/*
	#slide1 - trackGoogle('home');
	#slide2 - trackGoogle('sobre_a_celulite');
	#slide3 - trackGoogle('solucoes_vichy');
	#slide5 - trackGoogle('promo');
	#slide6 - trackGoogle('siga_a_celulite');
	*/
	
		if(posmenu < (stagewidth - 221)){
			$('#menu').hide();
		}else{
			$('#menu').show();
		}
	
		if(posmenu < stage2_inicio || posmenu > stage5_inicio){
			//showhidesolucoes();
		}
	
		if(posmenu > stage1_inicio && posmenu < stage1_fim){
			//$('#area1').css('visibility','visible');
			//$('#area1 .content').show();
			if(cont_stage1 == 0){
				trackGoogle('home');
				cont_stage1 = 1;
			}
			//showhidesolucoes();
		}else{
			//$('#area1 .content').hide();
			//$('#area1').css('visibility','hidden');
		}
	
	
		if(posmenu > stage2_inicio && posmenu < stage2_fim){
			$('#area2').css('visibility','visible');
			//$('#area2 .content').show();
			if(cont_stage2 == 0){
				trackGoogle('sobre_a_celulite');
				cont_stage2 = 1;
			}
		}else{
			//$('#area2 .content').hide();
			//$('#area2').css('visibility','hidden');
		}
	
		if(posmenu > stage3_inicio && posmenu < stage3_fim){
			//$('#area3').css('visibility','visible');
			//$('#area3 .content').show();
			//trackGoogle('');
			if(cont_stage3 == 0){
				trackGoogle('solucoes_vichy');
				cont_stage3 = 1;
			}
		}else{
			//$('#area3 .content').hide();
			//$('#area3').css('visibility','hidden');
		}
	
		if(scrollhorizontal == true){
			//if(posmenu > stage5_inicio && posmenu < stage5_fim){
			//	$('#area5').css('visibility','visible');
			//	$('#area5 .content').show();
				if(cont_stage5 == 0){
					trackGoogle('promo');
					cont_stage5 = 1;
				}
			//}else{
			//	$('#area5 .content').hide();
			//	$('#area5').css('visibility','hidden');
			//}
			//showhidesolucoes();
		}
	
		if(posmenu > stage6_inicio && posmenu < stage6_fim){
			//$('#area6').css('visibility','visible');
			//$('#area6 .content').show();
			if(cont_stage6 == 0){
				trackGoogle('siga_a_celulite');
				cont_stage6 = 1;
			}
		}else{
			//$('#area6 .content').hide();
			//$('#area6').css('visibility','hidden');
		}
	}
}


function stagepromo(acao){
	if(!isIE6){
		if(acao=="lock"){
		//	scrollhorizontal = false;
		}else if(acao=="release"){
			//scrollhorizontal = true;
			//$('#area5 .content').hide();
			//$('#area5 .content').show();
		}
	}
}

function popRegulamento(){
	popUpWindow("pop_regulamento.htm","reg",341,368);
}

function goPromo(){
	$('#mnpromo').click();
}

function goCadastro(){
	window.open('http://vichybrasil.com.br/register/check_registration.aspx?bid=010');
}

function cadastroCompleto(){
	$('#mnsolucoes').click();
}


function gocellumetric(){
	$('#area3').css('visibility','visible');
	$('#area3 .content').show();
	$('#mnsolucoes').click();
	showhidesolucoes('area-cellumetric');
}


function chkClientHeight(){
	if(!isIE6){
		var clientheight = document.body.offsetHeight;
		if(clientheight > 650){
			$('html').css('overflowY','hidden');
		}else{
			$('html').css('overflowY','auto');
		}
	}
}


addOnscroll(chkPositions);
addOnresize(chkwidth);
addOnload(chkwidth);
addOnresize(chkClientHeight);
addOnload(chkClientHeight);
//addOnload(chkPositions);