// JavaScript Document
$(document).ready( function() {
    //INIT
	/*$("#hidden").fadeTo("slow", 0);
	$("#hidden").hide("slow");*/
	esconde_back();
	$(".cont").hide(0);
	
	$(document).pngFix();
	
	$('body').dragResize({grid:1});
	

	$("#hidden").click(function(){
		$("#hidden").fadeTo("slow", 0);
		esconde_back();
	});
	
	$(".link1").click(function(){
		esconde_conteudos_todos();
		mostra_back();
		marca_menu(this.parentNode,this);
		$("#loader").fadeTo("slow", 0);
		//$(this.parentNode).next().toggle(200);
		
		$(this.parentNode).next("div").toggle(200);
	});
	
	$(".link2").click(function(){
		esconde_conteudos_todos();
		mostra_back();
		marca_menu(this.parentNode,this);
		
		//PIECE OF SHIT ADDED
		//poe o menu na posição X
		$value_position=$(this).attr('rel');
		
		$('#mydiv').animate({
			left: $value_position,
		}, 1000);

	});
	
	$(".link3").click(function(){
		mostra_back();
	});
});	

function marca_menu(menu, clique)
{
	/*$(".handle").css('background-color', '#f00');
	$(menu).css('background-color', '#ff0');*/
	desmarca_menus();
	var selected_id = $(clique).attr("id").replace('m-menu-','');
	$("#menu-"+selected_id).attr("src", "new_site/images/menu-"+selected_id+"_sel.png");
}

function desmarca_menus()
{
	$('#mydiv img').each(function() {
		var id_nome=$(this).attr("id");
		id_nome = id_nome.replace('m-','');
		//alert(id_nome);
		$(this).attr("src","new_site/images/"+id_nome+".png");
	});

}

function esconde_back()
{
	$("#logo").css('background-image', 'url(new_site/images/logo.png)');
	$("#hidden").fadeTo("slow", 0);
	$("#hidden").hide("slow");
	esconde_conteudos_todos();
}


function mostra_back()
{
	$("#logo").css('background-image', 'url(new_site/images/logo-branco.png)');
	$("#hidden").show();
	$("#hidden").fadeTo("slow", 0.9);
	$("#loader").fadeTo("fast", 1);
}

function esconde_conteudos_todos()
{
	$(".cont").hide("slow");
}

function loader()
{
	$("#loader").fadeTo("slow", 0);
}
