/*
*       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-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);
    
    
    //$('div.lista-close .pruh-obsah').hoverIntent( { timeout: 500, over: showLista, out: hideLista } );
    //$('div.lista-close .pruh-cont').load('CMSSystem.aspx?cm_action=ajax_campaign #container', function () {$('div.lista-close .pruh-cont a').css( 'opacity','0' );});
    
    Cufon.replace('.top-panel h1',  { fontFamily: 'Monotype Corsiva' });
    
    $("#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;  
       }  
    }); 
    
    $('.lista-obsah a:first').click(function () 
    {
      if ($('.lista').height()<40)
         $('.lista').animate({height: 100});
      else
        $('.lista').animate({height: 35});
      
      return false;
    }) 
    
    $('.facebook-box').html('<iframe src="http://www.facebook.com/plugins/likebox.php?href=https%3A%2F%2Fwww.facebook.com%2Fpages%2FPiercing4Ueu%2F117558964988351%2F&width=200&colorscheme=dark&show_faces=true&border_color=%23FFFFFF&stream=false&header=true&height=343" style="border: medium none; overflow: hidden; width: 200px; height: 343px;" allowtransparency="false" scrolling="no" frameborder="0"></iframe>');
  });
  
function showLista()
{
  //if ($('div.lista-close .pruh-cont').css('height') == '2px')
  {
    $('div.lista-close .pruh-cont').animate( { height: '74px' } ,500);
    $('div.lista-close .pruh-cont a').animate( { opacity: '1' } ,500);
    $('div.lista-close .pruh-obsah').animate( { marginTop: '-70px' } ,500);
  }
}

function hideLista()
{
  //else
  {
    $('div.lista-close .pruh-cont').animate( { height: '2px' } ,500);
    $('div.lista-close .pruh-cont a').animate( { opacity: '0' } ,500);
    $('div.lista-close .pruh-obsah').animate( { marginTop: '2px' } ,500);
  }
}

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, count, variant, subvariant) 
  {
    var toObject = jQuery('div.head-right .basket');
    var toLeft = toObject.attr('offsetLeft') + toObject.attr('offsetWidth')/2;
    var toTop = toObject.attr('offsetTop') + toObject.attr('offsetHeight')/2;
    
    $('#'+prefix+id+' .produkt-foto 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() 
      { 
        $(this).remove();
        jQuery.getJSON("~/CMSSystem.aspx?cm_action=ajax_addToBasket&ModuleKey=catalog&Id="+id+"&PriceFormat=N0&Count="+count+"&VariantId="+variant+"&Variant="+encodeURIComponent(subvariant), 
            function(json, status) 
                  {
                    
                    Anthem_InvokePageMethod('GetBasketInfo', [], function(result) { jQuery('div.head-right .basket').html(result.value); } ); 
                    
                     //if (json.Count > -1)
                      //jQuery('div.head-right .basket').html('V košíku máte: <a href="/cz/kosik.html">  '+json.Count+' produktů</a><br>Cena: <a href="Kosik.aspx">  '+json.Price+' CZK</a><br><a href="/cz/kosik.html" class="pink">vstup do košíku</a>');
        

                 });

        
      });
  }


