$(document).ready(function (){
     bind_ie6_fix_multiclass ();
    bind_menu_l2_sherlog ();
    bind_menu_l3_sherlog ();
    bind_path ();
    bind_top_search ();
    bind_pnv_cycle ();
    bind_home_cycle ();
    bind_home_counter ();
    bind_td_first ();
    
    $(".article-aktualita p:first").addClass("p-first-child");
    
    $(".menu li").hover(
        function() { $(this).addClass("sfhover"); },
        function() { $(this).removeClass("sfhover"); }
    );
    
    $(".panel-t2 .pt2d:first").after('<img class="separator3" alt="" src="http://www.sherlog.cz/img/separator3.png">');
    
    $("button, input[type='button']").hover(
        function() { $(this).addClass("btn-hover"); },
        function() { $(this).removeClass("btn-hover"); }
    );
});

function bind_ie6_fix_multiclass ()
{
    $(".sherlog-neo.active").addClass("sherlog-neo-active");
    $(".sherlog-trace.active").addClass("sherlog-trace-active");
    $(".sherlog-security-pipeline.active").addClass("sherlog-security-pipeline-active");
}

function bind_menu_l2_sherlog ()
{
    var item = $("#menu-l3-products > ul > li.active");
    var index = $("#menu-l3-products > ul > li").index(item);
    switch(index)
    {
    case 0:
      $(".sherlog-neo").addClass("sherlog-neo-active");
      break;
    case 1:
      $("h1, h2, .menu-special ul li").addClass("lblue");
      $(".menu-l3-products-sub").addClass("menu-l2-lblue");
      $(".sherlog-trace").addClass("sherlog-trace-active");
      break;
    case 2:
      $("h1, h2, .menu-special ul li").addClass("green");
      $(".menu-l3-products-sub").addClass("menu-l2-green");
      $(".sherlog-security-pipeline").addClass("sherlog-security-pipeline-active");
      break;
    default:
      $(".sherlog-neo").addClass("sherlog-neo-active");
      break;
    }
//     $(".active.sherlog-trace").ready(function () { $(".menu-l2, h1, h2, .menu-special ul li").addClass("lblue"); });
//     $(".active.sherlog-security-pipeline").ready(function () { $(".menu-l2, h1, h2, .menu-special ul li").addClass("green"); });
}

function bind_menu_l3_sherlog ()
{
	$("#menu-l3-sherlog ul li:not(:last)").after("<div></div>");
}

function bind_path ()
{
	$(".path ul li:not(:last)").after("<div> </div>");
}

function bind_top_search ()
{
    $("#top-search input").click( function () {
        $(this).val("");
    });
}

function bind_pnv_cycle ()
{
    $('#pnv-cycle dl dd').cycle({
        fx:     'fade',
        timeout: 5000
    });
    
    $('.pnv-excerpt ul li:nth-child(1)').addClass('pnv-ukradeno');
    $('.pnv-excerpt ul li:nth-child(2)').addClass('pnv-nalezeno');
}

function bind_home_cycle ()
{
    $('#home-cycle1 div').cycle({
        fx:     'fade',
        timeout: 5000
    });
    
    $('#home-cycle1 ul').each(function() {
        $('li:eq(0)', this).addClass('home-cycle-li0');
        $('li:eq(1)', this).addClass('home-cycle-li1');
        $('li:eq(2)', this).addClass('home-cycle-li2');
        $('li:eq(3)', this).addClass('home-cycle-li3');
    });

    
    $('#home-cycle2 dl dd').cycle({
        fx:     'scrollDown',
        timeout: 5000
    });
}

var previousValues = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var iterator = 0;

function bind_home_counter ()
{
    var d = new Date();
    //var x = Math.round(((d.getTime() - 1295481600000) / 1000) * 0.4); //prictena hodnota k 5.11.2010 v 1,667 Kč / sekundu
    //hodnoty pro rok 2010: var x = Math.round(((d.getTime() - 1290466800000) / 1000) * 1.667), x = x + 45305000
    var x = 817529554 + Math.round((d.getTime() - 1307989800000) / 1000) + iterator++; 
	// alert((d.getTime() - 1307989800000) / 1000);
    var i;
    var base = x;
    var out = "";
    var cntr = 0;
    var cntr2 = 1;   
    var changedFlag;
    var TIMER = 1052;
    
    while (x >= 1) {
        i = x % 10;
        x = Math.floor(x / 10);
        
        // kontrola predchozich hodnot
        if (previousValues[cntr2 - 1] == i) changedFlag = "";
        else changedFlag = " home-hza-number-changed";
        
        // nastaveni cisel
        var num1 = previousValues[cntr2 - 1];
        var num2 = i;
        
        // predchozi hodnota
		if(changedFlag != "")
		{
			out = out + "<div class='fr home-hza-number home-hza-number-prev" + cntr2 + " home-hza-number-prev'>" + "<span>" + num2 + "</span></div>";
		} 
        
        // nova hodnota
        out = out + "<div class='fr home-hza-number home-hza-number" + cntr2 + changedFlag + "'>";
        
        cntr++;
        cntr2++;

        if (cntr == 3 && x > 0)
	{
            out = out + "<div class='abs home-hza-three'> </div>";
            cntr = 0;
        }

        out = out + "<span>" + num1 + "</span></div>";
        
        // nastaveni predchozich hodnot v poli
        previousValues[cntr2-2] = i;
    }

	// aktualizace HTML kodu
    $('#home-panel4 .home-hza-number').remove();
    $("#home-panel4 .home-hza").after(out);
    $("#home-panel4 .home-hza-number:first").addClass("home-hza-number-last");
    
    // animace puvodni
    /*
    $('#home-panel4 .home-hza-number-changed').animate({ 
    	marginTop: "50px",
	    opacity: 0.7
	  }, 595 );
    */
    
    // animace
    $('#home-panel4 .home-hza-number-changed span').animate({ 
    	marginTop: "50px"
	  }, TIMER );
	  
	  
	$('#home-panel4 .home-hza-number-prev span').animate({ 
    	marginTop: "0"
	  }, TIMER );

    // sleep
    setTimeout("bind_home_counter();", TIMER);
}

function bind_td_first ()
{
$("table.pricelist tbody tr").each(function(){
	$("td:first", this).each(function(){
		$(this).addClass("tdfirst");
	});
});
}

// 
// function bind_identif ()
// {
// 	var i=0;
// 	$("table.pricelist tbody tr td").each(function(){
// 		$(this).addClass("sloupec"+i);
// 		i++;
// 	});
// }
// 
// function bind_th ()
// {	
// 	$('.content table.pricelist').each(function(){
// 		if ($('thead', this).lenght > 0) {
// 			$('tr:first-child td',this).each(function(){
// 				$(this).replaceWith('<th>' + $(this).text() + '</th>');
// 			});
// 		}
// 	});
// }
