$(function() {
 
    // Menu
	$('ul.menu ul').hide();
	$('ul.menu li').hover(
		function() {
		 	$(this).find('ul').fadeIn();
		 	//$(this).find('ul').show("fold", {}, 1000);
		},
		function() {
		    $(this).find('ul').fadeOut();
		    //$(this).find('ul').hide("fold", {}, 1000);
		}
	);

        $("label.required").each(function(){
            var newHTML = $(this).html().replace(":", "<span>*</span>: ")
            $(this).html(newHTML);
        });


    
    // Ajax Spinner
	$('<div id="ajax-spinner"></div>').hide().ajaxStart(function () {
		$(this).show();
	}).ajaxStop(function () {
		$(this).hide();
	}).appendTo("body");

    $("a.ajax").live("click", function () {
	$.get(this.href);
	return false;
});

	var colorboxsetting = {
		current: "{current} / {total}",
		previous: "předchozí",
		next: "další",
		close: "zavřít",
		slideshowStart: "spustit prezentaci",
		slideshowStop: "zastavit prezentaci"
	};
	        
    $("a[rel=lightbox]").colorbox(colorboxsetting); // Select all links that contains lightbox in the attribute rel
    $('a[rel=lightbox]').live('click', function() {
	  url = this.href; // this is the url of the element event is triggered from
	  $.fn.colorbox({href: url});
	  return false;
	});

    
      // Search-box
	  $("#search").focus(function() {
	   if ($(this).attr("value") == "hledej šmudlo") {
	     $(this).attr("value","");
	    };
	  });
	  
	  $("#search").blur(function() {
	    if($(this).attr("value") == "") {
	      $(this).attr("value","hledej šmudlo");
	    };
	  });


    $('.gallery td').hover(
		function(){
		$('.gallery td').stop().animate( { 'opacity':0.6 } , 300 );
 		$(this).stop().css('opacity',1);
	}, 	function(){
		$('.gallery td').stop().animate( { 'opacity':1 } , 300 );
	}); 

    $('.a-href-nw').click(function(){
    	window.open( $(this).attr('href') );
    	return false;
  	});
	
	$('.delete').click(function(){
		return confirm('Opravdu to chcete smazat?');
	});

    $('.prubeh-short').show();
    $('.prubeh-long').hide();

    $(".switch-short-long").toggle(
        function () {
          $(this).text("Skrýt celý text");
          $("."+ $(this).attr('rel')+ '-short').slideUp(500); //hide
          $("."+ $(this).attr('rel')+ '-long').slideDown(500);
        },
        function () {
          $(this).text("Celý text");
          $("."+ $(this).attr('rel')+ '-long').slideUp(500);
          $("."+ $(this).attr('rel')+ '-short').slideDown(500); //show
        }
    );

	/*
	$('<div id="eshop"></div>').each(function(){
	   html  = '<p>Doprodej posledních věcí z Obrok krámku za snížené ceny.</p>';
	   html += '<ul class="obrok">';
	   html += '<li>Obrok butylka - <strong>120 Kč</strong></li>';
	   html += '<li>Obrok peněženka - <strong>100 Kč</strong></li>';
	   html += '<li>Obrok tričko pánské - <strong>150 Kč</strong> (všechny velikosti)</li>';
	   html += '<li>Obrok tričko dámské - <strong>150 Kč</strong> (všechny velikosti)</li>';
	   html += '<li>Obrok dámská mikina - <strong>200 Kč</strong> (zelená, velikosti M a L)</li>';
	   html += '<li>Obrok účastnický šátek <strong>70 Kč</strong></li>';
	   html += '</ul>';
	   html += '<p>V případě zájmu pište na mail <a href="mailto:plamen@obrok11.cz">plamen@obrok11.cz</a></p>';
	   if($.cookie('eshop') != 'visit') {
	   		$(this).html(html).modal();
	   		$('.simplemodal-close').text('×');
	   		$.cookie('eshop','visit');
	   }
	});
	*/



	//startclock(); // Spustit odpocitavání termínů
});
	// Pocitadlo 
	
	var timerID = null;
	var timerRunning = false;
	function showtime() {
		today = new Date();
		BigDay = new Date("march 1, 2011")
		msPerDay = 24 * 60 * 60 * 1000 ;
		timeLeft = (BigDay.getTime() - today.getTime());
		e_daysLeft = timeLeft / msPerDay;
		daysLeft = Math.floor(e_daysLeft);
		e_daysLeft = timeLeft / msPerDay;
		daysLeft = Math.floor(e_daysLeft);
		e_hrsLeft = (e_daysLeft - daysLeft)*24;
		hrsLeft = Math.floor(e_hrsLeft);
		minsLeft = Math.floor((e_hrsLeft - hrsLeft)*60);
		hrsLeft = hrsLeft;
		e_minsLeft = (e_hrsLeft - hrsLeft)*60;
		secLeft = Math.floor(e_hrsLeft);
		secLeft = Math.floor((e_minsLeft - minsLeft)*60);
		secLeft = secLeft;
		if(daysLeft < 0) daysLeft = 0;
		if(hrsLeft < 0) hrsLeft = 0;
		if(minsLeft < 0) minsLeft = 0;
		if(secLeft < 0) secLeft = 0;
		text = '<strong class="big">'+daysLeft+' dní</strong><br /><strong>'+hrsLeft+' hodin</strong>, <strong>'+minsLeft+' minut</strong> a <strong>'+secLeft+' sekund</strong>'
		$('#counter').html(text);
		timerID = setTimeout("showtime()",1000);
		timerRunning = true;
	}
	var timerID = null;
	var timerRunning = false;
	function stopclock () {
		if(timerRunning)
		clearTimeout(timerID);
		timerRunning = false;
	}
	function stopClock() {
		stopclock();    
	    Return;
	}
	function startclock () {
		stopclock();
		showtime();
	} 
	
