﻿$(document).ready(function(){
    $(".destacadoListContainer").hover(
        function(){
            deselectAll();
            select(this.id);
        },
        function(){
        }
    );
    
    function select(id){
        try{
        document.cookie = "destacado="+id;
        $("#"+id).removeClass();
        $("#"+id).addClass('destacadoListContainerSelected');
    
        $("#"+"elemento"+id.substr(12)).css("display","");
        }catch(ex){
        }
    }
    
    function deselectAll(){
        $(".destacadoContainer").css("display","none");
        $(".destacadoListContainerSelected").addClass('destacadoListContainer');
        $(".destacadoListContainer").removeClass('destacadoListContainerSelected');
    }
    
    function initDestacados(){
        
        deselectAll();
        var destacado=getCookie('destacado');
        
        if($("#elemento"+getCookie('destacado').substr(12)).attr("id")!=undefined){
            select(destacado);
        }else{
            select($(".destacadoListContainer:first").attr("id"));
        }
    }
    
    function getCookie(c_name) {
        if (document.cookie.length>0) {
          c_start=document.cookie.indexOf(c_name + "=");
          if (c_start!=-1) { 
            c_start=c_start + c_name.length+1; 
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
          } 
        }
        return "";
    }

    initDestacados();
    
});