/*
*       Site skripty
*
*/

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-24645589-1']);
_gaq.push(['_trackPageview']);


$(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);
    
        $(".theme").wtRotator({
					width:705,
					height:193,
					button_width:5,
					button_height:5,
					button_margin:5,
					auto_start:true,
					delay:6000,
					play_once:false,
					transition:"random",
					transition_speed:800,
					auto_center:true,
					easing:"",
					cpanel_position:"inside",
					cpanel_align:"BR",
					timer_align:"top",
					display_thumbs:true,
					display_dbuttons:true,
					display_playbutton:true,
					display_numbers:false,
					display_timer:true,
					mouseover_pause:false,
					cpanel_mouseover:false,
					text_mouseover:false,
					text_effect:"fade",
					text_sync:true,
					tooltip_type:"image",
					lock_tooltip:true,
					shuffle:false,
					block_size:75,
					vert_size:55,
					horz_size:50,
					block_delay:25,
					vstripe_delay:75,
					hstripe_delay:180			
				});
				
				
				
				$("#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;  
           }  
        }); 
                  

        $('a[rel^=lightbox]').lightBox();
        $('#variantSelect').change( function() {{ updateVariant($('#variantSelect').val()); }});
        $('a.fav').jFav();  
        
        $('.clanek-home .more').click(function () 
        { 
          $(this).hide(); 
          $('.clanek-home .clanek-text').show(); 
          return false; 
        }); 
        
        if ($('#variantSelect').val())
          updateVariant($('#variantSelect').val());
        
        
        // google analytics
        (function() {
          var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
          ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
          var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        })();     
        
        // články
        showNews();          
    
  });
  
function showNews()
{
   var v = $('.news .clanek-nahled:visible');
   
   if (v.length == 0)
   {
      $('.news .clanek-nahled:first').show();
   }
   else
   {
      var n = v.next('.clanek-nahled:first');
      if (n.length == 0)
        n = $('.news .clanek-nahled:first');
        
      v.css('z-index','1');
      n.css('z-index','10').fadeIn('slow',function () { v.hide(); } );  
   }

   setTimeout(showNews,5000); 
}  


function updateVariant(id)
{
  variant =  $('#variant'+id);
  
	$('.foto-item img').attr('src',variant.find('a[rel^=mainimage]').attr('href'));
	$('.foto-item a').attr('href',variant.find('a[rel^=lightbox]').attr('href'));
  
  //$('.variant-input').val(variant.find('img').attr('title'));
  $('.variant-input').val(id);
  $('#variantSelect').val(id);
  $('#dostupnostProduktu').html(variant.find('input.dostupnost').val());
  $('.kosik .cena').html('naše cena: '+variant.find('input.cena').val()+',- Kč');
  
  return false;
}

function fbs_click() 
{
    u=location.href;
    t=document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width= 626,height=436');
    return false;
}

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.info-kosik a').attr('offsetLeft') + jQuery('div.info-kosik a').attr('offsetWidth')/2;
    var toTop = jQuery('div.info-kosik a').attr('offsetTop') + jQuery('div.info-kosik a').attr('offsetHeight')/2;
    var variant = "";
    if ($('#variantInput_'+id).length > 0)
      variant = '&VariantId='+ $('#variantInput_'+id).val();
      
    var count = 1;
    if ($('#basketCount_'+id).length > 0)
      count = $('#basketCount_'+id).val();
      
    $('#'+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() 
      { 
        $(this).remove();
        jQuery.getJSON("/CMSSystem.html?cm_action=ajax_addToBasket&ModuleKey=catalog&Id="+id+"&Count="+count+variant, 
            function(json, status) 
                  {
                    // reload košíku
                    if (document.location.toString().toLowerCase().indexOf('kosik.html') > 0)
                    {
                      document.location = document.location;
                      return;
                    }  
                    if (json.Count > 4)
                      jQuery('div.info-kosik a').html(''+json.Count+' produktů');
                    else if (json.Count > 1)
                      jQuery('div.info-kosik a').html(''+json.Count+' produkty');
                    else if (json.Count > 0)
                      jQuery('div.info-kosik a').html(''+json.Count+' produkt');
                      
                    jQuery('#basketCount_'+id).attr('value','1');
                 });

        
      });
  }
  


