
$(document).ready(function(){

$('.fade').cycle({
                        fx: 'fade',
                        pager:  '#nav'
                    });
                    
//Saber a altura das imagens
$('#logoWrapper').sliderCandy();

//Tabs
$(".tab_content").hide();
$("ul.tabs li:first").addClass("active").show();
$(".tab_content:first").show();


$("ul.tabs li a").click(function() {
	$("ul.tabs li").removeClass("active");
	$(this).parent().addClass("active");
	$(".tab_content").hide();
	var activeTab = $(this).attr("id");

	$(activeTab).show();
	return false;
});

//Scrollbar
if($('#contentScroll')){
	//$('#contentScroll').jScrollPane({showArrows:true, scrollbarWidth: 22, arrowSize: 22});
	$('#contentScroll').jScrollPane({showArrows:false, scrollbarWidth: 10, scrollbarMargin:10});
}

//Load first image
//alert($("#first").html());
if($("#first")){
	if($("#first").html() != null){
		loadImageToogle($("#first").html());
	}
}

$("#concordo").click(function(){
	if($("#concordo").is(':checked')){
		$("#hideForm").slideDown(1000);
	}else{
		$("#hideForm").slideUp(1000);
	}
});

});

$(window).load(function(){
	$('#leftNavLogos a img').each(function(){
		var half = $(this).height()/2;
		var topPos = ($("#leftNavLogos").height()/2) - half;
		if(topPos > 0){
			$(this).css('top', topPos + 'px');
		}
	});
});

function toggleMe(id, j, grupo){
	if($('#texto_' + id + '_' + j).css('display') == 'block'){
		$('#texto_' + id + '_' + j).slideUp(1000); 
	}else{
		$('.group_' + grupo).slideUp(1000);
		$('#texto_' + id + '_' + j).slideDown(1000, function(){
			loadImageToogle(id);
		}); 
	}
}

function loadImageToogle(id){
	$.ajax({
		type: "POST",
		url: "/gca/image.php",
	    cache: false,
	    data: "id=" + id,
	    success: function(html){
		
			if(html != ''){
				var actualHeight = $("#toggle_image").css("height");
				height = actualHeight.replace("px", "");
				if(height < 200){
					$("#toggle_image").animate({height: "210px"}, "slow");
				}
				
		    	$("#toggle_image").prepend(html);
		    	if($("#toggle_image img").length > 1){
			    	$("#toggle_image img:last").fadeOut(1000, function(){
				    	$("#toggle_image img:last").remove();
			    	});
		    	}
			}else{
	    		$("#toggle_image").animate({height: "1px"}, "slow");
	    		$("#toggle_image img:first").remove();
	    	}
	    	
	    }
	});
}


function openMe(id, obj){	
	$('#oport_' + id).slideToggle();
	var simbol = $('#plus_' + id).html();
	if(simbol.indexOf('+') > -1){
		simbol = simbol.replace('+', '-');
	}else if(simbol.indexOf('-') > -1){
		simbol = simbol.replace('-', '+');
	}
	$('#plus_' + id).html(simbol);
}

function resizeFrame(f) {
	f.style.height = f.contentWindow.document.body.scrollHeight + "px";
}


