var headline_count;
var headline_interval;
var current_headline = 0;
var old_headline = 0;

$(document).ready(function(){
   $("#extra_menu").html("");
   $("a.menactive").mouseover(changemenu);
   $("a.menitem").mouseover(changemenu);
   //$("#newslist > li").hide();
   $(".nav").click(function(event){
       event.preventDefault();
       loadMonth(this);  
   });
   headline_count = $("#newslist > li").size();//count number of news
   $("#newslist > li:eq(" + current_headline + ")").css('top', '5px');
   headline_interval = setInterval(news_swap,7000);
   $("#newslist").hover(function() {
     clearInterval(headline_interval);
   }, function() {
     headline_interval = setInterval(news_swap,7000); //time in milliseconds
     news_swap();
   });
   
   $("#feedlink").hover(function() {
        $("#rssico").css({backgroundPosition:"right -126px"}); 
        }, function() {
        $("#rssico").css({backgroundPosition:"right 0px"});
   });
   $("#feedlink").click(function(event){
    event.preventDefault();
    alert("Rss non ancora disponibili");
   });
   
   /*provare con input:checked*/
    $("#pollbutton").click(function(event)
        {
        event.preventDefault();
        var votes="";
        var i=0;
        votes = "poll_id=" + $(".mypoll input[type=hidden]").attr('value');
        if($(".mypoll input:checked").size()>$("#max_ans").attr('value'))
        {
            $.prompt("Hai selezionato troppe risposte. Il massimo &egrave; " +$("#max_ans").attr('value'));
            return false;   
        }
        //$(".mypoll input[type=checkbox]").each(function(i){
        $(".mypoll input:checked").each(function(i){
            if($(this).attr('checked')==true)
            {
                votes+="&c" + i + "="+ $(this).attr('value');
                i++;
            }
        });
       votes += "&button=Vota"; 
        
        $(".mypoll").html("<h1>Il sondaggio</h1><img src='images/layout/loader.gif' alt='loader' />");
        $.post("PollHandler.ashx", votes, function(data, textStatus){            
            $(".mypoll").html("<h1>Il sondaggio</h1>" + data);
            },"text");
       });
       
 });
 
function news_swap() {
   current_headline = (old_headline + 1) % headline_count;
    $("#newslist > li:eq(" + old_headline + ")").animate({top: -205},"slow", function() {
      $(this).css('top', '210px');
     });
    $("#newslist > li:eq(" + current_headline + ")").animate({top: 5},"slow");
    old_headline = current_headline;
};/*
function news_swap() {
   current_headline = (old_headline + 1) % headline_count;
    $("#newslist > li:eq(" + old_headline + ")").fadeOut(2000,function(){
    $("#newslist > li:eq(" + old_headline + ")").animate({opacity: 1.0}, 500);//delay trick
    $("#newslist > li:eq(" + current_headline + ")").fadeIn(1000);
    }); 
    old_headline = current_headline;
};*/
function changemenu(){
    switch(this.id)
    {
    case "home":
        $("#extra_menu").html("<li><a href='/Default.aspx'>News</a></li><li><a href='/Default.aspx'>Eventi</a></li>");
        break;
    case "club":
        $("#extra_menu").html("<li><a href='/forum/'>Forum</a></li><li><a href='/Club.aspx?type=downloads'>Downloads</a></li>");
        break;
    case "meetings":
        $("#extra_menu").html("<li><a href='/Meetings.aspx'>I nostri raduni</a></li>");
        break;
    case "gallery":
        $("#extra_menu").html("<li><a href='/Gallery.aspx'>Galleria utenti</a></li>");
        break;
    case "articles":
        $("#extra_menu").html("<li><a href='/Articles.aspx?type=storia'>Storia Lancia</a></li><li><a href='/Articles.aspx?type=tecnica'>Tecnica</a></li><li><a href='/Articles.aspx?type=versioni'>Versioni</a></li>");
        break;
    case "member_area":
        $("#extra_menu").html("<li><a href='/Member.aspx?type=accessori'>Accessori</a></li><li><a href='/Member.aspx?type=tuning'>Tuning</a></li><li><a href='/User/MyYpsilon.aspx'>My Ypsilon</a></li>");
        break;
    default:
        $("#extra_menu").html("");
    }
};    
function loadMonth(refer){
    var index = refer.href.lastIndexOf("?");
    var qString = refer.href.substr(index);
    $("#calendar tbody tr:gt(0)").css("visibility","hidden");
    //$(".mycal").css("background-image","url('/images/layout/cal-loader.gif')");
   
   $.get("MonthHandler.ashx" + qString + "&show=false", function(data, textStatus){
    /*  alert("Data Loaded: " + data);
      alert(textStatus);*/
      $(".mycal").html(data);
      JT_init();
      $(".nav").click(function(event){
            event.preventDefault();
            loadMonth(this);
        });
    });
    
};

$(document).ready(function() {
    $("div.panel_button").click(
        function(){ $("div#panel").animate({ 
        height:"400px"}).animate({height: "300px" }, "fast"); 
        $("div.panel_button").toggle();}); 
        $("div#hide_button").click(function(){
        $("div#panel").animate({
            height: "0px"
        }, "fast"); 
      });       
});




