var refreshDodani = function(stat,dodani) {
    if(stat == "cz"){
        $('.dodani_cz').show();
        $('.dodani_sk').hide();
        if($('.dodani_cz #dodani'+dodani).size() > 0){
            $('#dodani'+dodani).attr('checked','checked');    
        }else{
            $('.dodani_cz input:first').attr('checked','checked');
        }
		
		
    }
    if(stat == "sk"){
        $('.dodani_cz').hide();
        $('.dodani_sk').show();
		
        if($('.dodani_sk #dodani'+dodani).size() > 0){
            $('#dodani'+dodani).attr('checked','checked');    
        }else{
            $('.dodani_sk input:first').attr('checked','checked');
        }
    }
    return false;
}

function odpocet(){
    var d = $(".cas").attr('rel')/1;    
    var h = 23-Math.floor((d/3600));
    var m = 59-Math.floor((d%3600)/60);
    var s = 59-(d%60);
    
    if(m<10){
        m = "0"+m;
    }
    if(s<10){
        s = "0"+s;
    }
    $(".cas span").html(h+" : "+m+" : "+s);
    $(".cas").attr('rel',d+1);
}


  /*
 * 	Easy Tooltip 1.0 - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/4380/easy-tooltip--jquery-plugin
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 
(function($) {

	$.fn.easyTooltip = function(options){
	  
		// default configuration properties
		var defaults = {	
			xOffset: 10,		
			yOffset: 25,
			tooltipId: "easyTooltip",
			clickRemove: false,
			content: "",
			useElement: ""
		}; 
			
		var options = $.extend(defaults, options);  
		var content;
				
		this.each(function() {  				
			var title = $(this).attr("title");				
			$(this).hover(function(e){											 							   
				content = (options.content != "") ? options.content : title;
				content = (options.useElement != "") ? $("#" + options.useElement).html() : content;
				$(this).attr("title","");									  				
				if (content != "" && content != undefined){			
					$("body").append("<div id='"+ options.tooltipId +"'>"+ content +"</div>");		
					$("#" + options.tooltipId)
						.css("position","absolute")
						.css("top",(e.pageY - options.yOffset) + "px")
						.css("left",(e.pageX + options.xOffset) + "px")						
						.css("display","none")
						.fadeIn("fast")
				}
			},
			function(){	
				$("#" + options.tooltipId).remove();
				$(this).attr("title",title);
			});	
			$(this).mousemove(function(e){
				$("#" + options.tooltipId)
					.css("top",(e.pageY - options.yOffset) + "px")
					.css("left",(e.pageX + options.xOffset) + "px")					
			});	
			if(options.clickRemove){
				$(this).mousedown(function(e){
					$("#" + options.tooltipId).remove();
					$(this).attr("title",title);
				});				
			}
		});
	  
	};

})(jQuery);


$('document').ready(function(){
    /* index */
    
  $("abbr").easyTooltip();
  
    $('#s6').after('<div id="nav">').cycle({
        fx:     'scrollLeft',
        timeout: 8000,
        delay:  -1000,
        pager:  '#nav',
        random:0
    });
    $('#vip_div').cycle({
        fx:     'scrollLeft',
        timeout: 15000,
        delay:  -3000,
        random:1
    });
    $('#s').cycle({
        fx:     'fade',
        timeout: 4000,
        speed: 500
    });
  
    /*****/

    $('select[name=varianta]').bind('change',function(){
		
        var hash = $('select[name=varianta] option:selected').attr('rel').split("##");  
        if(hash[7]) $('.js_cena_puvodni').html(hash[7]);

    });
	
    $('#menu .home a').hover(function(){
        $('#menu-home_in').css("background-position","0 -38px");
    });
    $('#menu .home a').mouseout(function(){
        $('#menu-home_in').css("background-position","0 0");
    });

    if($(".cas span").size()>0){
        setInterval("odpocet()", 960);
    }
    
    if($("#rozcestnik_search-text").size()>0){
        $("#rozcestnik_search-text").autocomplete({
            source: "/json.php?akce=hledat",
            minLength: 3,
            select: function( event, ui ) {
            window.location.href = ui.item.link;
            return false;
            }
            }).data( "autocomplete")._renderItem = function( ul, item ) {
            if(item.cena){
                return $( "<li></li>" )
                .data( "item.autocomplete", item )
                .append( "<a href='"+item.link+"'><span class='name'>" + item.nazev + "</span><span class='price'>" + item.cena + "</span></a>" )
                .appendTo( ul );
            }else{
                return $( "<li></li>" )
                .data( "item.autocomplete", item )
                .append( "<a href='"+item.link+"'><span class='name'><b>" + item.nazev + "</b></span></a>" )
                .appendTo( ul );    
            }
        };
    }      
});




