$(document).ready(function() {

	$('#home').click(function(){
		$('.menu-principal').find('a').removeClass('underline');
	});

	$('#comentarioNoticia').validate();

	$('#comentarioFlickr').validate();

	// destaquesCycle
	//$('#carroselprofissionais').hide();
	
	// ScrollPage
	
	$('.scroll-pane').jScrollPane();
	
	//TOOLTIP
	$(".twipsyTip").twipsy({
		live: true,
		placement: 'below'
    });

	//Cycle
	$('.destaquesCycle').cycle({
		fx: 'slideX',
		timeout : '5000',
		speed: 	'500',
		pager: 	'#nav',
		next: 	'#next',
		prev: 	'#prev'
	});
	
	//Cycle - Botão Pausar
	$('#pausar').click(function(){
		$('.destaquesCycle').cycle('pause');
	});
	
		$("select, input:checkbox, input:radio, input:file, input:text").uniform();

		// Carregamento de imagens
		/*$("img").lazyload({
            effect : "fadeIn"
        });*/
	
		// Posicionando
		$('#home').click(function(){
			$.scrollTo( 0, 1500 );
		});
		
		$('#salao').click(function(){
			$.scrollTo( 820, 1500 );
		});
		
		$('#osalao-logo').click(function(){
			$.scrollTo( 820, 1500 );
		});
		
		$('#sspa').click(function(){
			$.scrollTo( 2520, 1500 );
		});
		
		$('#servicosprodutoss').click(function(){
			$.scrollTo( 1700, 1500 );
		});
		
		$('#profissionaiss').click(function(){
			$.scrollTo( 3380, 1500 );
		});
		
		$('#educ').click(function(){
			$.scrollTo( 4200, 1500 );
		});
		
		$('#tendenciass').click(function(){
			$.scrollTo( 5120, 1500 );
		});
		
		// Blogs 
		
		$('#blogs').mouseenter(function() {
		  $('#relacao-blogs-menu').fadeIn();
		});

		$('#blogs').mouseout(function() {
		  setTimeout($('#relacao-blogs-menu').fadeOut(), 10000);
		});

		$('#relacao-blogs-menu').mouseenter(function() {
		  $('#relacao-blogs-menu').stop(true,true).show();
		});
		
		$('#relacao-blogs-menu').mouseleave(function() {
		  $('#relacao-blogs-menu').fadeOut();
		});
		
});

/* METODOS QUE PEGAM largura, altura, vertical, horizontal em vários Browsers */
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

// Monitorando posição do scroll
$(window).scroll(function(e){
 
    // grab the scroll amount and the window height
    var scrollAmount = f_scrollTop();
    var documentHeight = f_clientHeight();
 
    // calculate the percentage the user has scrolled down the page
    //var scrollPercent = (scrollAmount / documentHeight) * 100;
	var scrollPercent = scrollAmount;

	//$('.aki').html(scrollPercent);

 	// Condições Sub Menu O Salão
 	if(scrollPercent < 820) {
 	    // run a function called doSomething
 	    submenuOsalaoEsconder();
	    underlineMenu('');
 	}
 
    if( scrollPercent >= 820 && scrollPercent < 1690) {
        // run a function called doSomething
        submenuOsalao();
	    underlineMenu('salao');
    }

	if(scrollPercent > 1690) {
        // run a function called doSomething
        submenuOsalaoEsconder();
    }

	if( scrollPercent >= 1700 && scrollPercent < 2520) {
	    underlineMenu('servicosprodutoss');
    }

	if( scrollPercent >= 2520 && scrollPercent < 3380) {
	    underlineMenu('sspa');
    }

	if( scrollPercent >= 3380 && scrollPercent < 4200) {
	    underlineMenu('profissionaiss');
    }

	if( scrollPercent >= 4200 && scrollPercent < 5120) {
	    underlineMenu('educ');
    }

	if( scrollPercent >= 5120) {
	    underlineMenu('tendenciass');
    }
 	
 	
    function submenuOsalao() {

		$('#sub-menu-osalao').fadeIn();

    }
    
    function submenuOsalaoEsconder() {

		$('#sub-menu-osalao').fadeOut();

    }

	// Condições Sub Menu Profissionais
	if(scrollPercent < 3380) {
	    // run a function called doSomething
	    submenuProfissionaisEsconder();
	}
	
	if(scrollPercent >= 3380 && scrollPercent < 4200) {
	    // run a function called doSomething
	    submenuProfissionais();
	}
	
	if(scrollPercent > 4200) {
	    // run a function called doSomething
	    submenuProfissionaisEsconder();
	}

   function submenuProfissionais() {
		$('#sub-menu-profissionais').fadeIn();
	   //$('#carroselprofissionais').fadeIn();
   }
   
   function submenuProfissionaisEsconder() {
   	    $('#sub-menu-profissionais').fadeOut();
   }
   	
   	
   	
   	
   	
   	
   	
   	
   	
   	
   // Condições logomarca
   
   if(scrollPercent >= 820) {
   	    // run a function called doSomething
   	    logomarcaMenorMostra();
   	}
   	
   if(scrollPercent < 820) {
   	    // run a function called doSomething
   	    logomarcaMenorEsconde();
   	}
   	
	function logomarcaMenorMostra() {
		$('#logomarca-topo').fadeIn();
		//setTimeout(function(){$("#logomarca-topo").fadeIn(1000)},6000);
	}
	
	function logomarcaMenorEsconde() {
		$('#logomarca-topo').fadeOut();
		//setTimeout(function(){$("#logomarca-topo").fadeOut(1000)},6000);
	}
   
   function logomarcaMaiorMostra() {
   	$('#logomarca-home').fadeIn();
	   //setTimeout(function(){$("#logomarca-home").fadeIn(1000)},6000);
   }
   
   function logomarcaMaiorEsconde() {
   	$('#logomarca-home').fadeOut();
	   //setTimeout(function(){$("#logomarca-home").fadeOut(1000)},6000);
   }
 
});

// Colorbox 

$(document).ready(function(){

    // Clipping
    $(".imagemClipping").colorbox();
	
	//Galeria de Fotos
	$(".padraogaleria").colorbox({rel:'group1', transition:"fade"});
	
	//Extra
	$(".botao-midias").colorbox({iframe:true, rel:'extra', transition:"fade", width:"600px", height:"558px"});
	$(".botao-cadastro-home").colorbox({iframe:true, rel:'extra', transition:"fade", width:"600px", height:"420px"});
	$(".botao-cadastro").colorbox({iframe:true, rel:'extra', transition:"fade", width:"600px", height:"420px", scrolling: false});
	$(".botao-carreira").colorbox({iframe:true, rel:'extra', transition:"fade", width:"600px", height:"480px"});
	$(".botao-contato").colorbox({iframe:true, scrolling: true, rel:'extra', transition:"fade", width:"600px", height:"558px"});
	
	// Profissionais Diversos
	$(".botao-profissionaisdiversos").colorbox({iframe:true, scrolling: true, rel:'extra', transition:"fade", width:"600px", height:"80%"});

	// Tendências
	$('.tendencias-iframe').live('click', function() { 
		url = this.href;
		$.fn.colorbox({href: url, iframe:true, rel:'tendencias-janela', transition:"fade", width:"600px", height:"70%"});
		return false;
	})
	
	// $(".tendencias-iframe").colorbox({iframe:true, rel:'tendencias-janela', transition:"fade", width:"600px", height:"600px"});

	
	// $(".servicos-iframe").colorbox({iframe:true, width:"80%", height:"80%"});
	$(".produtos-iframe").colorbox({iframe:true, width:"600px", height:"600px"});

	$('.galeriaImageShow').live('click', function() { 
		url = this.href;
		$.fn.colorbox({href: url});
		return false;
	});

	$('.servicos-iframe').live('click', function() { 
		url = this.href;
		$.fn.colorbox({href: url, iframe:true, width:"600px", height:"600px"});
		return false;
	})

	$(".inline").colorbox({inline:true, width:"50%"});
	$(".callbacks").colorbox({
		onOpen:function(){ alert('onOpen: colorbox is about to open'); },
		onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
		onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
		onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
		onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
	});
	
	//Example of preserving a JavaScript event for inline calls.
	$("#click").click(function(){ 
		$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
		return false;
	});

	$("#leituraGaleria .slideshow").cycle({
			fx: "none",
			pause: true,
			pager: ".leituraGaleriaPaginacao",
			prev: ".setaEsquerda",
			timeout: 20000,
			next: ".setaDireita",
			toggle: ".playPause",
			pagerAnchorBuilder: function(idx, slide) { 
				return '<a href="#"><img src="'+$(slide).find("img").attr("src")+'" width="50" height="50" /></a>';
		    	
			}
	});
	
});

	// Janela Popup
	function newWindow(mypage, w, h, scroll) {
				var winl = (screen.width - w) / 2;
				var wint = (screen.height - h) / 2;
				winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',status=yes, resizable'
				win = window.open(mypage, '', winprops)

				if (parseInt(navigator.appVersion) >= 4) { 
					win.window.focus(); 
				}
			}

function underlineMenu(item){
	if(item == ""){
		$('.menu-principal').find('a').removeClass('underline');
	}else{
		$('.menu-principal').find('a').removeClass('underline');
		$('#'+item).addClass('underline');
	}
}
