$(document).keydown(function(e) {  
			if (e.keyCode == 27) {  
         		$("#login-panel").hide(0);  
     		}  
 		});  
$(document).ready(function(){
	var mesic=0;
	$('.kallen').hide().empty();
	$.ajax({
		url: "/soubory/ajax/kalendar.php",
		type: "POST",
		data: "mesic="+mesic,
		async: true,
		success:function(html){
			obj=html.split("xxxx");
			$('.kallen').append(obj[1]);
			$('.mesic').append(obj[0]);
			$('.kallen').delay(600).fadeIn("slow");
		}
	});	
	$(".nas").click(function(){
		mesic++;
		$('.kallen').hide().empty();
		$('.mesic').empty();
		$.ajax({
			url: "/soubory/ajax/kalendar.php",
			type: "POST",
			data: "mesic="+mesic,
			async: true,
			success:function(html){
				obj=html.split("xxxx");
				$('.kallen').append(obj[1]);
				$('.mesic').append(obj[0]);
				$('.kallen').delay(600).fadeIn("slow");
			}
		});		
	});
	$(".pred").click(function(){
		mesic--;
		$('.kallen').hide().empty();
		$('.mesic').empty();
		$.ajax({
			url: "/soubory/ajax/kalendar.php",
			type: "POST",
			data: "mesic="+mesic,
			async: true,
			success:function(html){
				obj=html.split("xxxx");
				$('.kallen').append(obj[1]);
				$('.mesic').append(obj[0]);
				$('.kallen').delay(600).fadeIn("slow");
			}
		});		
	});
	
	//ANKETA	
	$(".varianta").click(function(){
		if($(this).parents(".anketa").hasClass("nehlasoval")){
			$(this).parents(".anketa").removeClass("nehlasoval");
			var x=$(this).attr("rel").split("-");
			var html = $.ajax({
				type: "POST",
				url: "/soubory/ajax/anketa.php",
				data: "key="+$(this).attr("rel"),
				dataType: 'json',
				async: false
			}).responseText;
			obj = jQuery.parseJSON(html);
			for(i=1;i<6;i++){
				if(obj["pocet_"+i]!=null){
					$(".lis-"+x[0]+"_"+i).animate({width: obj["pro_"+i]+"%"}, 1500 );
					$(".var-"+x[0]+"_"+i+" >span").append(" - ("+obj["pocet_"+i]+"%)");
				}	
			}
		
		}
	});
	
	//NEWS
	$("#prihlasit_news").click(function(){
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if(reg.test($(".input_news").val()) == true){
			temno();
			$.ajax({
			url: "/soubory/ajax/news.php",
			type: "POST",
			data: "email="+$(".input_news").val(),
			async: true,
			success:function(html){
				if(html=="1"){
					okno("hlaska",400,"<p>Email byl přidán k odběru novinek.");
					$(".input_news").val("@");
				}else{
					okno("hlaska",400,"<p>Email již je přihlášen k odběru.");
					$(".input_news").val("@");
				}
				$('.strana_vyp').append(html);
				$('.strana_vyp').delay(400).fadeIn("slow");
			}
		});
			
		}else{
			temno();
			okno("hlaska",400,"<p>Email není ve správném formátu.");
		}
	});
	

	//Vypnutí temna
	$('.close, #fade').live('click', function() {
		$('#fade , .popup_block').fadeOut(function() {
			$('#fade').remove();  
		});
 	   return false;
	});



});
function temno(){
		$('body').append('<div id="fade"><\/div>'); 
	   	$('#fade').css({'filter' : 'alpha(opacity=60)'}).fadeIn();	
	}
function okno(id,width,text){
	$('body').append('<div id="'+id+'" class="popup_block"><a href="#" class="close kriz"><img src="/img/close_pop.png" class="btn_close" title="Zavřít okno" alt="Zavřít" /></a><div class="popup_white">'+text+'<\/div><\/div>'); 
	$('#'+id).fadeIn().css({ 'width': width });
	var popMargTop = ($('#' + id).height() + 80) / 2;
    var popMargLeft = ($('#' + id).width() + 80) / 2;
   	$('#' + id).css({
    	'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
	});	
	lze_zavrit=true;
}
//Hodnocení
//copyright 2008 Jarrett Vance
//http://jvance.com
$.fn.rater = function(options) {
    var opts = $.extend({}, $.fn.rater.defaults, options);
    return this.each(function() {
        var $this = $(this);
        var $on = $this.find('.ui-rater-starsOn');
        var $off = $this.find('.ui-rater-starsOff');
        opts.size = $on.height();
        if (opts.rating == undefined) opts.rating = $on.width() / opts.size;
        if (opts.id == undefined) opts.id = $(this).attr('id');

        $off.mousemove(function(e) {
            var left = e.clientX - $off.offset().left;
            var width = $off.width() - ($off.width() - left);
            width = Math.ceil(width / (opts.size / opts.step)) * opts.size / opts.step;
            $on.width(width);
        }).hover(function(e) { $on.addClass('ui-rater-starsHover'); }, function(e) {
            $on.removeClass('ui-rater-starsHover'); $on.width(opts.rating * opts.size);
        }).click(function(e) {
            var r = Math.round($on.width() / $off.width() * (opts.units * opts.step)) / opts.step;
            $off.unbind('click').unbind('mousemove').unbind('mouseenter').unbind('mouseleave');
            $off.css('cursor', 'default'); $on.css('cursor', 'default');
            $.fn.rater.rate($this, opts, r);
        }).css('cursor', 'pointer'); $on.css('cursor', 'pointer');
		if($off.attr("rel")==1){$off.unbind('click').unbind('mousemove').unbind('mouseenter').unbind('mouseleave');$off.css('cursor', 'default'); $on.css('cursor', 'default');}

    });
};

$.fn.rater.defaults = {
    postHref: location.href,
    units: 10,
    step: 1
};

$.fn.rater.rate = function($this, opts, rating) {
    var $on = $this.find('.ui-rater-starsOn');
    var $off = $this.find('.ui-rater-starsOff');
    $off.fadeTo(600, 0.4, function() {
        $.ajax({
            url: opts.postHref,
            type: "POST",
            data: 'id=' + opts.id + '&rating=' + rating + '&foto=' + $this.attr("rel"),
            complete: function(req) {
                if (req.status == 200) { //success
				 pol= req.responseText.split(",");
                    opts.rating = parseFloat(pol[0]);
                    $off.fadeTo(600, 0.1, function() {
                        $on.removeClass('ui-rater-starsHover').width(opts.rating * opts.size);
                        var $count = $this.find('.ui-rater-rateCount-ho');
                        $count.text(parseInt($count.text()) + 1);  //připsání počtu hlasů
                        $this.find('.ui-rater-rating').empty().append("<strong>"+opts.rating.toFixed(1)+"</strong>/10"); //nastavení nohé hodnoty
                        $off.fadeTo(600, 1);

                        $this.attr('title', 'Tvoje hodnocení: ' + opts.rating.toFixed(1));
                    });
                } else { //failure
                    alert(req.responseText);
                    $on.removeClass('ui-rater-starsHover').width(opts.rating * opts.size);
                    $this.rater(opts);
                    $off.fadeTo(2200, 1);
                }
            }
        });
    });
};



/**
Vertigo Tip by www.vertigo-project.com
Requires jQuery
*/

this.vtip = function() {    
    this.xOffset = -10; // x distance from mouse
    this.yOffset = 10; // y distance from mouse       
    
    $(".napoveda").unbind().hover(    
        function(e) {
            this.t = this.title;
            this.title = ''; 
            this.top = (e.pageY + yOffset); this.left = (e.pageX + xOffset);
            
            $('body').append( '<p id="vtip"><img id="vtipArrow" />' + this.t + '</p>' );
                        
            $('p#vtip #vtipArrow').attr("src", '/img/vtip_arrow.png');
            $('p#vtip').css("top", this.top+"px").css("left", this.left+"px").fadeIn("slow");
            
        },
        function() {
            this.title = this.t;
            $("p#vtip").fadeOut("slow").remove();
        }
    ).mousemove(
        function(e) {
            this.top = (e.pageY + yOffset);
            this.left = (e.pageX + xOffset);
                         
            $("p#vtip").css("top", this.top+"px").css("left", this.left+"px");
        }
    );            
    
};

jQuery(document).ready(function($){vtip();}) 

//URL parser


jQuery.url = function()
{
	var segments = {};
	
	var parsed = {};
	
	/**
    * Options object. Only the URI and strictMode values can be changed via the setters below.
    */
  	var options = {
	
		url : window.location, // default URI is the page in which the script is running
		
		strictMode: false, // 'loose' parsing by default
	
		key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], // keys available to query 
		
		q: {
			name: "queryKey",
			parser: /(?:^|&)([^&=]*)=?([^&]*)/g
		},
		
		parser: {
			strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,  //less intuitive, more accurate to the specs
			loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // more intuitive, fails on relative paths and deviates from specs
		}
		
	};
	
    /**
     * Deals with the parsing of the URI according to the regex above.
 	 * Written by Steven Levithan - see credits at top.
     */		
	var parseUri = function()
	{
		str = decodeURI( options.url );
		
		var m = options.parser[ options.strictMode ? "strict" : "loose" ].exec( str );
		var uri = {};
		var i = 14;

		while ( i-- ) {
			uri[ options.key[i] ] = m[i] || "";
		}

		uri[ options.q.name ] = {};
		uri[ options.key[12] ].replace( options.q.parser, function ( $0, $1, $2 ) {
			if ($1) {
				uri[options.q.name][$1] = $2;
			}
		});

		return uri;
	};

    /**
     * Returns the value of the passed in key from the parsed URI.
  	 * 
	 * @param string key The key whose value is required
     */		
	var key = function( key )
	{
		if ( jQuery.isEmptyObject(parsed) )
		{
			setUp(); // if the URI has not been parsed yet then do this first...	
		} 
		if ( key == "base" )
		{
			if ( parsed.port !== null && parsed.port !== "" )
			{
				return parsed.protocol+"://"+parsed.host+":"+parsed.port+"/";	
			}
			else
			{
				return parsed.protocol+"://"+parsed.host+"/";
			}
		}
	
		return ( parsed[key] === "" ) ? null : parsed[key];
	};
	
	/**
     * Returns the value of the required query string parameter.
  	 * 
	 * @param string item The parameter whose value is required
     */		
	var param = function( item )
	{
		if ( jQuery.isEmptyObject(parsed) )
		{
			setUp(); // if the URI has not been parsed yet then do this first...	
		}
		return ( parsed.queryKey[item] === null ) ? null : parsed.queryKey[item];
	};

    /**
     * 'Constructor' (not really!) function.
     *  Called whenever the URI changes to kick off re-parsing of the URI and splitting it up into segments. 
     */	
	var setUp = function()
	{
		parsed = parseUri();
		
		getSegments();	
	};
	
    /**
     * Splits up the body of the URI into segments (i.e. sections delimited by '/')
     */
	var getSegments = function()
	{
		var p = parsed.path;
		segments = []; // clear out segments array
		segments = parsed.path.length == 1 ? {} : ( p.charAt( p.length - 1 ) == "/" ? p.substring( 1, p.length - 1 ) : path = p.substring( 1 ) ).split("/");
	};
	
	return {
		
	    /**
	     * Sets the parsing mode - either strict or loose. Set to loose by default.
	     *
	     * @param string mode The mode to set the parser to. Anything apart from a value of 'strict' will set it to loose!
	     */
		setMode : function( mode )
		{
			options.strictMode = mode == "strict" ? true : false;
			return this;
		},
		
		/**
	     * Sets URI to parse if you don't want to to parse the current page's URI.
		 * Calling the function with no value for newUri resets it to the current page's URI.
	     *
	     * @param string newUri The URI to parse.
	     */		
		setUrl : function( newUri )
		{
			options.url = newUri === undefined ? window.location : newUri;
			setUp();
			return this;
		},		
		
		/**
	     * Returns the value of the specified URI segment. Segments are numbered from 1 to the number of segments.
		 * For example the URI http://test.com/about/company/ segment(1) would return 'about'.
		 *
		 * If no integer is passed into the function it returns the number of segments in the URI.
	     *
	     * @param int pos The position of the segment to return. Can be empty.
	     */	
		segment : function( pos )
		{
			if ( jQuery.isEmptyObject(parsed) )
			{
				setUp(); // if the URI has not been parsed yet then do this first...	
			} 
			if ( pos === undefined )
			{
				return segments.length;
			}
			return ( segments[pos] === "" || segments[pos] === undefined ) ? null : segments[pos];
		},
		
		attr : key, // provides public access to private 'key' function - see above
		
		param : param // provides public access to private 'param' function - see above
		
	};
	
}();
