var this_id = 0;
var prev_id = 0;

$(document).ready(function(){  
    $(".news-more").click(function(){  
        prev_id = this_id;
        this_id = $(this).parent().parent().attr('id').substring(5);
        openNews();
    });
    
    $(".news-title").click(function(){  
        prev_id = this_id;
        this_id = $(this).parent().attr('id').substring(5);
        openNews();
    });
    
    var hash = location.hash.substring(1);

    if (hash.length > 0){
        this_id = hash;
        openNews();
    }

    $("#dropdown-trigger").click(function(){
        $(".dropdown").slideDown('fast');
    });
    $(".dropdown").mouseenter(function(){

    }).mouseleave(function(){
        $(".dropdown").slideUp();
    });
    
    $("#prijava-potrdi").click(function(){
        
        var str = "";
        
        for (i=0; i<=4; i++){
            if ($("#prijava-"+i+":checked").val()=='on'){
                str += ','+i;
            }
        }
        if (str.length>0) str = str.substring(1);
        
        $("#prijava-loader").show();
        $("#prijava-ajax").hide();
        
        $.post("/Mailing/Submit",{
            email: $("#prijava-email").val(),
            cat: str    
        },function(data){
            $("#prijava-ajax").html('<br /><br />'+data);
            $("#prijava-loader").hide();
            $("#prijava-ajax").slideDown();    
        }); 
    });
    
}); 
function openNews(){ 
    if (this_id != prev_id){
        closeNews();

        $("#news-"+this_id+" .news-preview").hide();
        $("#news-"+this_id+" .news-content").slideDown();
        $("#news-"+this_id).css('background-color','#eee');  
        location.hash = "#"+this_id;
    }  
}
function closeNews(){
    $("#news-"+prev_id+" .news-preview").show();
    $("#news-"+prev_id+" .news-content").hide();
    $("#news-"+prev_id).css('background-color','#fff');      
}

