function show_event(e,currentElement)
{
      var x = e.pageX;
      var y = e.pageY;  
      var addr = $(currentElement).attr("rel");

      if(addr!="")
      {
            $.get(addr, function(data){$("#calendar-event").html(data);});      

            $("#calendar-event").css("position","absolute");
            $("#calendar-event").css("top",y);
            $("#calendar-event").css("left",x+20);
            $("#calendar-event").show('slow');
      }
}

function ajaxShowEvent(e,dataElement,id)
{
      if(e.target.href) 
      {
            var page=e.target.href.substring(e.target.href.length-8,e.target.href.length); 
            var addr = "http://www.pokerzone.cz/includes/home-calendar/"+page;
            dataElement.hide();
            $.post(addr, function(data){
                  var dataElementPos=data.search('<div id="'+id+'" class="description">')+31+id.length;
                  var dataLen=data.length;
                 
                  dataElement.empty();

                  if(id=='calendar-live-eventy')
                  {
                       var data=data.substring(dataElementPos,data.search('<div id="tab-ten" style="display:none;">')-60);
                         
                        dataElement.html(data); //document.write(data);

                         $('#calendar-live-eventy .month_links .arrow').click(function(event) { 
                               var currentElement=$('#calendar-live-eventy');
                               var id='calendar-live-eventy';
                               ajaxShowEvent(event,currentElement,id);     
                         });

                         $('#calendar-live-eventy table tr .event a').mouseover(function(event) {show_event(event,this);});
                  }
                  else
                  {
                        var data=data.substring(dataElementPos,dataLen-6);

                        dataElement.html(data);

                        $('#calendar-pokerzone-akce .month_links .arrow').click(function(event) { 
                                var currentElement=$('#calendar-pokerzone-akce');
                                var id='calendar-pokerzone-akce';
                                ajaxShowEvent(event,currentElement,id);
                         });

                         $('#calendar-pokerzone-akce table tr .event a').mouseover(function(event) {show_event(event,this);});
                  }
            });        

            dataElement.show();        
            e.preventDefault();
      }     
}

function promoSlide()
{
      var current=$("a.promo").index($("a.promo-active"));
      var next=current+1;
      
      if(next==5) next=0;

      $("a.promo").eq(current).css("position","relative");
      $("a.promo").attr("class","promo");


      $("a.promo").eq(next).attr("class","promo promo-active");
      $(".promo-box").eq(next).show();

      $(".promo-box").eq(current).hide();
}

$(document).ready(function(){
    $(".promo-box").css("display","none");
    $("a.promo").eq(0).attr("class","promo promo-active");
    $(".promo-box").eq(0).show();

    interval=setInterval("promoSlide()", 5000);
    
   $("a.promo").click(function (e) {
          clearInterval(interval);
          $(".promo-box").hide();
          $("a.promo").attr("class","promo");
          $(this).attr("class","promo promo-active");
          $(this).next().show();
          e.preventDefault();
   });

   $("#calendar-event").mouseout(function () {$(this).hide();});
    
   $().click(function () {$("#calendar-event").hide();});     

   $(".event a").mouseover(function (e) {show_event(e,this);});

    $("#calendar-live-eventy .month_links .arrow").click(function(e) { 
      var currentElement=$('#calendar-live-eventy');
      var id='calendar-live-eventy';
      ajaxShowEvent(e,currentElement,id);     
      });

      $("#calendar-pokerzone-akce .month_links .arrow").click(function(e) { 
      var currentElement=$('#calendar-pokerzone-akce');
      var id='calendar-pokerzone-akce';
      ajaxShowEvent(e,currentElement,id);
      });

   $("#search").focus(function (e) {if(e.target.value=="hledat") {e.target.value="";} });
   $("#search").blur(function (e) { if(e.target.value=="") {e.target.value="hledat";} });
   $("#search-dictionary").focus(function (e) {if(e.target.value=="hledat") {e.target.value="";} });
   $("#search-dictionary").blur(function (e) { if(e.target.value=="") {e.target.value="hledat";} });
   $("#login-name").focus(function (e) {if(e.target.value=="Jméno") {e.target.value="";} });
   $("#login-name").blur(function (e) { if(e.target.value=="") {e.target.value="Jméno";} });
   $("#login-pass").focus(function (e) {if(e.target.value=="Heslo") {e.target.value="";} });
   $("#login-pass").blur(function (e) { if(e.target.value=="") {e.target.value="Heslo";} });

    $("#user_order_form select").change(function() {$("#user_order_form").submit();});

   $("form .rating_stars img").click(function(e) { 

      if(e.target.alt) 
      {
         var rate=e.target.alt; 
         if(rate.match(/^[0-9]$/))
         { 
            var currentElement=$("form input[name='rating']");
            currentElement.val(rate);
            currentElement.parent().submit();
            //alert(currentElement.val());
         } 
      }
   });

   $(".rating_stars > img").mouseover(function(e){
      $(this).attr("src","/images/icons/full-star.gif");
      $(this).prevAll().attr("src","/images/icons/full-star.gif");
   });

    $(".rating_stars > img").mouseout(function(e){
      $(this).attr("src","/images/icons/no-star.gif"); 
      $(this).prevAll().attr("src","/images/icons/no-star.gif");
   });

});