var imgAtual = 1;
var imgProx = 2;
var chgSpeed = 1000;
var fdeSpeed = 500;
var scrTarget = "";
var inter;
$(document).ready(function(){
	$("#works").css("width", totalWidth);
	$(".menu").mouseover(function(){
		id = $(this).attr("id");
		$("#" +id + "_over").show();
	}).mouseout(function(){
		id = $(this).attr("id");
		$("#" +id + "_over").hide();
	});
	$(".menu_over").mouseover(function(){
		$(this).show();
	}).mouseout(function(){
		$(this).hide();
	});
	$(".scroll").click(function(event){
		event.preventDefault();
		var full_url = this.href;
		var parts = full_url.split("#");
		var trgt = parts[1];
		var target_offset = $("#"+trgt).offset();
		var target_left = target_offset.left;
		if(trgt != "home") target_left = target_left - 220;
		$('html, body').stop().animate({scrollLeft:target_left}, 500);
		scrTarget = trgt;
		$(".video").each(function(){
			$(this).html($(this).data("i"));
		});
	});

	inter = setInterval("changeImg()", chgSpeed);
	$("#img"+imgProx).css({"background-image":"url(_img/bg_logo/" + bgAtual + ".jpg)","z-index":2});
	$("#img"+imgProx).fadeTo(fdeSpeed,1);

	$(window).bind('resize', function(){
		reArrange();
	});
	reArrange();
});
$(window).load(function(){
	//$("#loading").hide();
	//$("#main").fadeTo(1,1000);
	$(".video").each(function(){
		$(this).data("w",$(this).width()-5);
		$(this).data("i",$(this).html());
	});
	$(".video").click(function(event){
		$(this).html('<iframe width="'+$(this).data("w")+'" height="460" src="http://www.youtube.com/embed/'+$(this).attr("id")+'?autoplay=1;" frameborder="0" allowfullscreen></iframe>');
	});

});

function reArrange(){
	var mainWidth = $("#container").width();
	$("#home_anchor").css("left",-mainWidth/2);
	if(scrTarget != ""){
		var target_offset = $("#"+scrTarget).offset();
		var target_left = target_offset.left;
		if(scrTarget != "home") target_left = target_left - 220;
		$('html, body').stop().animate({scrollLeft:target_left}, 500);
	}
}


function changeImg(){
	bgAtual++;
	if(bgAtual > bgMax) bgAtual = 1;
	$("#img"+imgProx).css("z-index",1);
	$("#img"+imgAtual).css({"background-image":"url(_img/logo_bg/" + arBG[bgAtual] + ".jpg)","z-index":2});
	$("#img"+imgAtual).fadeTo(fdeSpeed,1, function(){
		$("#img"+imgProx).hide();
		if(imgAtual == 1){
			imgAtual = 2;
			imgProx = 1;
		}else{
			imgAtual = 1;
			imgProx = 2;
		}
	});
}

