/*
*       Site skripty
*
*/

(function($)
{
	$.fn.blink = function(options)
	{
		var defaults = { delay:2000, speedin: 1000, speedout: 2000 };
		var options = $.extend(defaults, options);
		
    
		return this.each(function()
		{
			var obj = $(this);
			
			//fin();
			
			
			setInterval(function()
			{
				if($(obj).attr("blink") == "1")
				{
					$(obj).fadeOut(options.speedout);
					$(obj).attr("blink", "0");
				}
				else
				{
					$(obj).fadeIn(options.speedin);
					$(obj).attr("blink", "1")
				}
			}, options.delay);  
		});
	}
}(jQuery))


function aload_product()
{
    par = par + 1;
    
    var oldDiv = $('#akce_ajax div');
    var newDiv = $('<div></div>').fadeOut();
  
   $(newDiv).load('akce_ajax.aspx?par='+par+' .cmsCatalogAction');
   
     $('#akce_ajax').append(newDiv);
     $(oldDiv).fadeOut(1000);
     $(newDiv).fadeIn(1000);
     $(oldDiv).remove();


    setTimeout(load_product, loadTimeout);
}


$(document).ready(
  function adminDocumentLoad()
  {
    jQuery.fx.interval = 100;
    
    // corners
    DD_roundies.addRule('.rounded', '5px', true);
    DD_roundies.addRule('.rounded-top', '5px 5px 0 0', true);
    DD_roundies.addRule('.rounded-topleft', '5px 0 0 0', true);
    DD_roundies.addRule('.rounded-topright', '0 5px 0 0', true);
    DD_roundies.addRule('.rounded-bottomleft', '0 0 5px 0', true);
    DD_roundies.addRule('.rounded-bottomright', '0 0 0 5px', true);
    
    $("#searchInput").attr("value",$.query.get("searchstring"));
                  
    $("#searchInput").keypress(function (e) 
    {  
      if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) 
      {  
         searchClick();
         //$("#searchButton").focus();
         return false;  
       } 
       else 
       {  
         return true;  
       }  
    });
  
    $('.cmsCatalogItem').hoverIntent(
      {
        timeout: 500, 
        over: function() { $(this).find('.moduleItemEdit').toggle(); },
        out: function() { $(this).find('.moduleItemEdit').toggle(); }
      } );
      
      
    $('.infopanel-title').blink();  
       
    });
  

  // ----------------------------
//  search
// ----------------------------
function searchClick()
{
  var searchString = $('#searchInput').attr('value');
  var url = "/cz/hledani.html"+$.query.set('searchstring',searchString).toString();
  window.location = url;
  return false;
}

      function addToBasket (id) {
        // vypocet margin
        var x = 1180 - $('#productObsah'+id).offset().left;
        var y = 47 - $('#productObsah'+id).offset().top;
        $('#productObsah'+id+' .produkt-foto img')
        .clone()
        .prependTo("#productObsah"+id)
        .css({'position' : 'absolute'})
        .animate({opacity: 0.4}, 100 )
        .animate({opacity: 0.1, marginLeft: x, marginTop: y, width: 5, height: 5}, 1800, 
        function() 
          { 
            $(this).remove();
            var par = Math.random()*999999;
            $.getJSON("~/CMSSystem.aspx?cm_action=ajax_addToBasket&par="+par+"&ModuleKey=catalog&Id="+id+"&Count="+$('#basketCount_'+id).attr('value'), 
            function(json, status) 
                  {
                    if (json.Count > -1)
                      $('div.basket a:first').html('V košíku máte: <span class="white">  '+json.Count+' produkty</span><br> Cena: <span class="white"> ' + json.Price + ' CZK s DPH</span>');
                      
                    $('#basketCount_'+id).attr('value','1');
                    $.gritter.add({ title: ' ', text: 'Zboží bylo přidáno do košíku' , sticky: false, time: '5000'});
                 });
            
          });
        }
 


