/*
*       Site skripty
*
*/


$(document).ready(
  function adminDocumentLoad()
  {
    // corners
    DD_roundies.addRule('.rounded', '5px', true);
    DD_roundies.addRule('.rounded-top', '5px 5px 0 0', true);
    DD_roundies.addRule('.rounded-bottom', '0 0 5px 5px', 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);
    
    
    $(document).ready(function(){{
				$('.produkt-foto a[rel^=lightbox],.produkt-nextfoto a[rel^=lightbox]').lightBox();
				}});
				
		// hledání
    $("#searchInput").attr("value",$.query.get("searchstring"));
        $('#searchInput').hint();          
        $("#searchInput").keypress(function (e) 
        {  
          if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) 
          {  
             searchClick();
             //$("#searchButton").focus();
             return false;  
           } 
           else 
           {  
             return true;  
           }  
        }); 
        		
		$('div.pocitadlo').html('<img width="88" height="60" alt="TOPlist" src="http://toplist.cz/count.asp?id=915193&amp;logo=mc&amp;http=http%3A//www.cukrarskepotreby.cz/&amp;wi=1680&amp;he=1050&amp;cd=24&amp;t=CukrarskePotreby.cz%20-%20e-shop">');		
  });
  
function searchClick()
  {
    var searchString = $('#searchInput').attr('value');
    var url = "/cz/hledani.html"+$.query.set('searchstring',searchString).toString();
    window.location = url;
    return false;
  }

function addToBasket (prefix, id) 
  {
    var toLeft = jQuery('div.kos a').attr('offsetLeft') + jQuery('div.kos a').attr('offsetWidth')/2;
    var toTop = jQuery('div.kos a').attr('offsetTop') + jQuery('div.kos a').attr('offsetHeight')/2;
    
    
    $('#'+prefix+id+' img')
    .clone()
    .css({'position' : 'absolute'})
    .prependTo("#"+prefix+id)
    .animate({opacity: 0.8}, 100 )
    .animate({opacity: 0.1, left: toLeft, top: toTop, width: 10, height: 10}, 1200, 
    function() 
      { 
        var count = 1;
        if ($('#basketCount_'+id).length > 0)
          count = $('#basketCount_'+id).val();
          
        $(this).remove();
        jQuery.getJSON("~/CMSSystem.aspx?cm_action=ajax_addToBasket&ModuleKey=catalog&Id="+id+"&Count=" + count, 
            function(json, status) 
                  {
                    if (json.Count > -1)
                      jQuery('div.kos a').html(''+json.Count+' položek');
                      
                    jQuery('#basketCount_'+id).attr('value','1');
                 });

        
      });
  }


