/**
 * @author Rafael Costa
 */
 
 var sLastValue;
 
window.onload = function()
{
    var sURLAtual = window.location.href;
    markCategoryInMenuByURL(sURLAtual);

    $("#menu li").mouseenter(function(){
       $(this).find("ul").show();
    });

    $("#menu li").mouseleave(function(){
       $(this).find("ul").hide();
    });
    
    $("#conteudo #esquerda ul li").mouseover(function(){
        $(this).addClass("selected");        
    });
    
    $("#conteudo #esquerda ul li").mouseout(function(){
        $(this).removeClass("selected");
    });
	
	$(".zoom").fancybox({
		'type'				:	'image',
		'hideOnContentClick': 	true,
		'titleShow'			: 	false,
		'transitionIn'		: 	'elastic',
		'transitionOut'		:	'elastic'
	});
	
}

function markCategoryInMenuByURL(sURLAtual)
{
    var sPaginaAtual = sURLAtual.substr(sURLAtual.lastIndexOf("/")+1);

    if (sPaginaAtual != "")
    {
    var CategoriaSelecionada = $("#menu_esquerda ul li a[href=categorias/listar/"+sPaginaAtual+"]");

    // mudar cor
    $(CategoriaSelecionada).css({"color":"#68791D", "font-weight":"bolder"});

    // mostrar submenu
    $(CategoriaSelecionada).parent().next("ul").show();


    var SubCategoriaSelecionada = $("#menu_esquerda ul ul li a[href=categorias/listar/"+sPaginaAtual+"]");

    var CategoriaPai = $(SubCategoriaSelecionada).parent().parent().prev();

    // mudar cor
    $(SubCategoriaSelecionada).css({"color":"#ff7b0e", "font-weight":"bolder"});

    $(CategoriaPai).find("a").css({"color":"#68791D", "font-weight":"bolder"});

    // mostrar submenu
    $(CategoriaPai).next("ul").show();

    }
}

function toggleCategoria(nId)
{
	//$("#conteudo #esquerda ul ul").hide("slow");
	$("#submenu_"+nId).toggle("slow");
}

function onFocus(obj, defaultValue)
{
	sLastValue = $(obj).val();
        if (sLastValue == defaultValue)
        {
            $(obj).val("");
        }
}

function onBlur(obj)
{
	if ($(obj).val() == "")
	{
		$(obj).val(sLastValue);
	}
	sLastValue = "";
}

function toggleNews(id)
{
    var stateAtual = $("#news_"+id+" p.texto").css("display");

    if (stateAtual == "none"){
        $("#news_"+id+" p.texto").show("fast");
    } else{
        $("#news_"+id+" p.texto").hide("fast");
    }
}

function toggleCategory(id)
{
    var stateAtual = $("#categoria_"+id+" .produtos").css("display");
    
    if (stateAtual == "none"){
        $("#categoria_"+id+" .produtos").show("fast");
    } else{
        $("#categoria_"+id+" .produtos").hide("fast");
    }
}
