/* Author:
Carlosr@agap2.pt
*/

//Variavéis globais



$(function() {

	//Hide (Collapse) the toggle containers on load
	
	$(".toggle_container").hide();
	$("#one").show();
	//$("#two").show();
	//$("#three").show();

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$("h1.trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("normal");
		return false; //Prevent the browser jump to the link anchor
	});
	

//scrool do menu
var top = $('#navTop').offset().top - 15;
var ficaFixed = $('#headerCont');
var mostrarHead = $('#mostraHeader');
/*
$('body').scroll(function (event) {
  
// Encontra o Y
    var y = ficaFixed.offset().top;
// Se tiver abaixo
	console.log($('#navTop').offset().top)
    if (y >= top) {
// adiciona a cass fixed
	console.log(y)	
		mostrarHead.removeClass('hid');
      	$('#headerCont').addClass('fixed');
    } else {
// senão remove
		mostrarHead.addClass('hid').removeClass('esconde');
      	$('#headerCont').removeClass('fixed').removeAttr('style');
    }
  }); 
*/

  
 

//Hides maricas aos labels do form de login(ou outro)
    $(".inputHolder input").val('').keydown(function () {
        $(this).prev('label').fadeOut('2000');
    }).focusout(function () {
        if ($(this).val().length == 0)
            $(this).prev('label').fadeIn('2000');
    });   
    
//menu f

$("li.rmItem").hoverIntent(
  function () {
    $('.rmSlide ul', this).slideDown(600);
  }, 
  function () {
    $('.rmSlide ul', this).slideUp(400);
  }
);

//$('link.Telerik_stylesheet').remove();


$('#mosaic').fadeIn(800).cycle({ 
    			fx: 'fade,cover,scrollUp,scrollLeft,scrollRight',random:1
    		});
//scrollEl('#leftCol');


});//End on ready

//Load temporario por ajax só para demo
function loader(click,html) {
$(click).click(function(p){
	var target = $('#main')
	target.fadeOut(500, function(){
		target.load(html + '#loader > *', function(){
		target.fadeIn(500)});	
		setTimeout(function(){ 
			equalHeight($('.metades'))
		},1000)	
		
		
	});
	p.preventDefault();
});
}

function scrollEl(el){
			var name = $(el);
			var menuYloc = 0;
			//menuYloc = parseInt($(name).css("top").substring(0,name.css("top").indexOf("px")))
			console.log(menuYloc)
			$(window).scroll(function () {
   				var offset = menuYloc+$(document).scrollTop()+"px";
   				console.log(offset)
   				$(name).animate({top:offset},{duration:500,queue:false});
			});
}
function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}


