function _changeBeer()
{

    if ($('#pivo_black').css('display') != 'none')
    {
    	if ($.browser.msie)
    	{
    		$('#pivo_black').hide(); $('#pivo_white').show();

        }
        else
	    {
	       $('#pivo_black').fadeOut('slow', function(){
	            $('#pivo_white').fadeIn('slow');
	        });
	    }
    }


    else if ($('#pivo_black2').css('display') != 'none')
    {
    	if ($.browser.msie)
    	{
    		$('#pivo_black2').hide(); $('#pivo_white').show();

        }
        else
	    {
	       $('#pivo_black2').fadeOut('slow', function(){
	            $('#pivo_white').fadeIn('slow');
	        });
	    }
    }


    else
    {
	    if ($.browser.msie)
	    {
	    	$('#pivo_white').hide(); $('#pivo_black').show();
	    }
	    else
	    {
	      $('#pivo_white').fadeOut('slow', function(){
	            $('#pivo_black').fadeIn('slow');
	        });
	    }
	}
    ChangeBeer();
}

function ChangeBeer()
{
    setTimeout("_changeBeer()", 5000);
}

 	window.currentSect = 'textScroll';
    window.currentPage = 0;


$(document).ready(function()
{
	
	$(function(){
  	$("#slides").slides({
    play: 5000,
    pause: 2500,
	effect: 'fade'
  });
});
	
	 if(window.currentSect == 'textScroll') window.totalPages = $('#textScroll li').size();
	
    $('.menu td a').bind('click', function(){
        $('.for_content').css({
            'visibility': 'visible'
        });
    });

    jQuery.preloadImages = function()
    {
        for (var i = 0; i < arguments.length; i++)
            jQuery("<img>").attr("src", arguments[i]);
    }

    // jQuery.preloadImages('../images/bg2.jpg');
    jQuery.preloadImages('images/bg2.jpg');
    //$(document).bgStretcher({images:['images/bg1.jpg', 'images/bg2.jpg'],imageWidth:1920,imageHeight:1068});
    //$.fn.bgStretcher.pause();
    ChangeBeer();



    $('#changeCheh').bind('click', function()
    {
        if ($(this).attr('rel') == 'cheh1')
        {
			setCookie("ks.background", "1");

            $(this).attr('rel', 'cheh2');
            $(this).children('span').html('Королевские традиции');

           $('#' + window.currentSect).hide();
            $('#' + window.currentSect + ' li').hide();
            window.currentSect = 'textScroll';
            $('#' + window.currentSect).show();
            window.currentPage = 0;
            window.totalPages = $('#' + window.currentSect + ' li').size();
            $('#' + window.currentSect + ' li').eq(0).show();
            $("#page2").removeClass("old");

        }
        else if ($(this).attr('rel') == 'cheh2')
        {
			setCookie("ks.background", "2");

            $(this).attr('rel', 'cheh1');
            $(this).children('span').html('Современная Чехия');

            $('#' + window.currentSect).hide();
           $('#' + window.currentSect + ' li').hide();
            window.currentSect = 'textScroll2';
            $('#' + window.currentSect).show();
            window.currentPage = 0;
            window.totalPages = $('#' + window.currentSect + ' li').size();

            $('#' + window.currentSect + ' li').eq(0).show();
            $("#page2").addClass("old");


        }

		scrollVisible(window.currentPage, window.totalPages);

    });

    
    
	var changeBG = function()
    {
        if ($(this).attr('rel') == 'cheh1')
        {
			setCookie("ks.background", "1");

            $(this).attr('rel', 'cheh2');
            $(this).children('span').html('Королевские традиции');

            $("#page2").removeClass("old");

        }
        else if ($(this).attr('rel') == 'cheh2')
        {
			setCookie("ks.background", "2");

            $(this).attr('rel', 'cheh1');
            $(this).children('span').html('Современная Чехия');

            $("#page2").addClass("old");


        }
    }
    
    $('#changeCheh_priv_1').bind('click', changeBG);
    $('#changeCheh_priv_2').bind('click', changeBG);
    
    $('#scrollLeft').bind('click', function(){
        var prev = window.currentPage;



        if (window.currentPage - 1 < 0)
            window.currentPage = window.totalPages - 1;
        else
            window.currentPage = window.currentPage - 1;


		scrollVisible(window.currentPage, window.totalPages);

        $('#' + window.currentSect + ' li').eq(prev).fadeOut('slow', function(){
            $('#' + window.currentSect + ' li').eq(window.currentPage).fadeIn('slow');
        });

    });

    $('#scrollRight').bind('click', function(){
        var prev = window.currentPage;



        if (window.currentPage + 1 < window.totalPages)
            window.currentPage ++;
        else
            window.currentPage = 0;

		scrollVisible(window.currentPage, window.totalPages);

        if (!$.browser.msie)
    	{
	        $('#' + window.currentSect + ' li').eq(prev).fadeOut('slow', function(){
	            $('#' + window.currentSect + ' li').eq(window.currentPage).fadeIn('slow');
	        });
    	}
    	else
    	{
    		$('#' + window.currentSect + ' li').eq(prev).hide();
    		$('#' + window.currentSect + ' li').eq(window.currentPage).show();
    	}

    });



    $('#scrollLeft2').bind('click', function(){
        var prev = window.currentPage;
        if (window.currentPage - 1 < 0)
            window.currentPage = window.totalPages - 1;
        else
            window.currentPage = window.currentPage - 1;

        $('#' + window.currentSect + ' li').eq(prev).fadeOut('slow', function(){
            $('#' + window.currentSect + ' li').eq(window.currentPage).fadeIn('slow');
        });

        $('.lenta_c').html($('.stories2 li').eq(window.currentPage).attr('rel'));
        $('.stories2 li').removeClass('active');
        $('.stories2 li').eq(window.currentPage).addClass('active');

    });

    $('#scrollRight2').bind('click', function(){
        var prev = window.currentPage;

        if (parseInt(window.currentPage) + parseInt(1) < window.totalPages)
            window.currentPage ++;
        else
            window.currentPage = 0;

        if (!$.browser.msie)
        {
	        $('#' + window.currentSect + ' li').eq(prev).fadeOut('slow', function(){
	            $('#' + window.currentSect + ' li').eq(window.currentPage).fadeIn('slow');
	        });
        }
        else
        {
        	$('#' + window.currentSect + ' li').eq(prev).hide();
        	$('#' + window.currentSect + ' li').eq(window.currentPage).show();
        }

        $('.lenta_c').html($('.stories2 li').eq(window.currentPage).attr('rel'));
        $('.stories2 li').removeClass('active').children('img').attr('src', 'images/hist1_footer.png');
        $('.stories2 li').eq(window.currentPage).addClass('active');
        $('.stories2 li').eq(window.currentPage).children('img').attr('src', 'images/hist2_footer.png');

    });

    $('.close').bind('click', function(){
        $('.for_content').css({
            'visibility': 'hidden'
        });

    });

    $('.stories2 li a').bind('click', function(){

        var prev = window.currentPage;
        window.currentPage = $(this).attr('pos');

        $('#' + window.currentSect + ' li').eq(prev).fadeOut('slow', function(){
            $('#' + window.currentSect + ' li').eq(window.currentPage).fadeIn('slow');
        });

        $('.stories2 li').removeClass('active').children('img').attr('src', 'images/hist1_footer.png');
        $(this).parents('li').addClass('active');
        $('.lenta_c').html($(this).parents('li').attr('rel'));
        $(this).parents('li').children('img').attr('src', 'images/hist2_footer.png');
    });

    $('.stories3 li a').bind('click', function(){

        $('.text_scrols li').hide();

        if ($(this).attr('rel') == 1)
        {
        	$('#textScroll').show();
         	window.currentSect = 'textScroll';
        }
        else
        {
        	$('#textScroll' + $(this).attr('rel')).show();
        	window.currentSect = 'textScroll' + $(this).attr('rel');
        }

       // window.currentPage = 1;

        $('#' + window.currentSect + ' li:first-child').show();


        $('.stories3 li').removeClass('active').children('img').attr('src', 'images/hist1_footer.png');
        $(this).parents('li').addClass('active');
        $('.lenta_c').html($(this).parents('li').attr('rel'));
        $(this).parents('li').children('img').attr('src', 'images/hist2_footer.png');
    });

//    if(form:mode.int(0) == 2){
//        $("#page2").addClass("old");
//    }

	scrollVisible(window.currentPage, window.totalPages);
	
// Buttons
	
	var bg = getCookie("ks.background");
	
	if(!isNaN(bg)){

		if(bg == 2){
			$('#bg_1').show();
			$('#bg_2').hide();
		}else{
			$('#bg_2').show();
			$('#bg_1').hide();		
		}

	}
	
});

function scrollVisible(currentPage, totalPages)
{
	if(currentPage == 0){
		$('#scrollLeft').hide();
	}else{
		$('#scrollLeft').show();
	}

	
	if (currentPage == (totalPages-1))
	{
		$('#scrollRight').hide();
	}else{
		$('#scrollRight').show();
	}

//	alert(currentPage + " / " + totalPages);

}

function nextField(obj, maxsize, next_obj)
{
    if(obj.value.length >= maxsize && !isNaN(obj.value)){
        $('#' + next_obj).focus();
    }
}

function checkBD(mode)
{
    var link = 'not18.html';
    try{

        var bd_year = Number($('#bd_year').val());
        var bd_month = Number($('#bd_month').val());
        var bd_day = Number($('#bd_day').val());
        bd_year += 18;

        var bd = new Date( bd_year, bd_month, bd_day);
        var nd = new Date();

        if( nd >= bd ){
            if(mode == 2) link = 'dobro.html';
            else link = 'dobro_2.html';
        }

    } catch(e) {

    } finally {
        document.location.href=link;
    }
}

function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
//        ((expires) ? "; expires=" + expires : "") +
     	"; expires=365" +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie (name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0)
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function setCurrentSect(sect)
{
	window.currentSect = sect;
    window.currentPage = 0;
    window.totalPages = $('#' + sect + ' li').size();
}

