
//Inclinations
function decl_num(number, titles)  
{  
    cases = [2, 0, 1, 1, 1, 2];  
    return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];  
}  

//Date difference
function days_left_to_date(year, month, day)
{
    var date = new Date(year, month-1, day);
    var today = new Date();
  
    var diff = new Date(date - today);
    return Math.ceil(diff/1000/60/60/24);
}

//Starting nebulas
$(function()
{
    //$(".socnet a.fb").attr("href", "");

    //Locking people link
    //$("a[href='people.html']").addClass("inactive").click(function() { return false });

    //Last twe http://twitter.com/statuses/user_timeline/toster_ru.json
    $.getJSON("http://twitter.com/statuses/user_timeline/toster_ru.json?count=2&callback=?", function(data) 
    {
        $("#header .bird div").css("cursor", "pointer").click(function() { location.href = "http://twitter.com/toster_ru/" });
        $("#header .bird, .socnet").fadeIn();
        $(".bird div span").html(data[0].text);
    });

    //Current filename
    var filename = window.location.pathname.substring(window.location.pathname.lastIndexOf("/") + 1, window.location.pathname.length);

    //Modifying date before event
    var left_days = days_left_to_date(2012, 2, 10);

    $("li div.special").hide();

    if (left_days > 0)
    {
        $("#header .note").html("До конференции осталось&nbsp;" + left_days + "&nbsp;" + 
        decl_num(left_days, ["день", "дня", "дней"]) + "");

        //$("li div.special span").html(decl_num(left_days, ["Остался", "Осталось", "Осталось"]) + " " + left_days + " " + 
        //decl_num(left_days, ["день", "дня", "дней"]) + "!");
    }
    else
    {
        $("#header .note").hide();
    }

    if ($.browser.msie && parseInt($.browser.version) <= 8)
    {
        //Nothing to show in IE
    }
    else
    {

    //This nebula is on all pages
    $("#nebulas").append('<div class="nebula" style="left: 50%; top: -420px;">\
                          <img class="nebula-top-1" src="i/nebulas/top.png" />\
                          </div>');

    
    
    setInterval(function() 
    { 
        $(".nebula-top-1").animate({"opacity": 0.8}, 1000, function() { $(this).animate({"opacity":1}, 1000) });
    }, 8000);

    $("#nebulas").append('<div class="nebula" style="width: 1000px; height: 1000px; left: -600px; top: 100px;">\
                      <img class="nebula-left-1" src="i/nebulas/upper1.png" />\
                      <img style="opacity: 0.5; left: 170px; top: 130px" class="nebula-left-2" src="i/nebulas/upper2.png" />\
                      </div>');

    setInterval(function() 
    { 
        $(".nebula-left-2").animate({"opacity": 0.6}, 1500, function() { $(this).animate({"opacity":0.2}, 1000) });
        $(".nebula-left-1").animate({"opacity": 0.9}, 1500, function() { $(this).animate({"opacity":1}, 1500) });
    }, 7000);

    $("#nebulas").append('<div class="nebula" style="width: 1000px; height: 1000px; right: -600px; top:200px;">\
              <img class="nebula-right-1" src="i/nebulas/right1.png" />\
              <img style="opacity: 0.5;" class="nebula-right-2" src="i/nebulas/right2.png" />\
              </div>');

    setInterval(function() 
    { 
        $(".nebula-right-1").animate({"opacity": 0.6}, 1500, function() { $(this).animate({"opacity":0.2}, 1000) });
        $(".nebula-right-2").animate({"opacity": 0.8}, 1500, function() { $(this).animate({"opacity":1}, 1500) });
    }, 6000);

    $("#nebulas").height($(document).height());

    }

});







