
$(function() {
	$('input["name=barva[]"][type=checkbox]').click(function(){
		if($(this).val()=="NULL" && $(this).attr("checked")==true){
			$('input["name=barva[]"][type=checkbox]').each(function(index) {
				$(this).attr("checked","");
			});
			$("input['name=barva[]'][type=checkbox][value=NULL]").attr("checked","checked");  
		}
		if($(this).val()!="NULL" ){
			$("input['name=barva[]'][type=checkbox][value=NULL]").attr("checked",""); 
		}
            

	});
});

function dataSent()

{   
	$("#box").css("display", "block");
	$("#sent_filter").append('<input id="sentHidden" type="hidden" name="sent" value="true">');
/*
 	$("#a_zobrazit_box").css("display", "none"); 		  
  $("#box").css("display", "block");
  $("#a_skryt_box").css("display", "block");
  $("#filter_odeslat").css("display", "none");
	
    */
} 

function dataNotSent()
{   
	$("#box").css("display", "block");/*
 	$("#a_zobrazit_box").css("display", "block"); 		  
  //$("#box").css("display", "none");
  $("#a_skryt_box").css("display", "none");
    */
}

function filterHandler()
{ 
	//$("#box").css("display", "block");
/* obsluha filtru */      
/*
 	$("#a_zobrazit_box").live('click', function () {		  
	  $("#box").slideDown("slow");
	  $(this).fadeOut("slow");
	  $("#a_skryt_box").fadeIn("slow");
	  $("#filter_odeslat").css("display", "none");
	  $("#sent_filter").append('<input id="sentHidden" type="hidden" name="sent" value="true" />');
  });
	
	$("#a_skryt_box").live('click', function () {		  
	  $("#box").slideUp("slow");
	  $(this).fadeOut("slow");
	  $("#a_zobrazit_box").fadeIn("slow");
	  $("#filter_odeslat").css("display", "inline");
	  $("#sentHidden").remove();
    });
    */
}

function sendSimpleFilter()
{
	$("#filtr").remove();
}

/**
 * Vrati hodnotu vybrane polozky.
 */ 
function getSelected(el) 
{
	var dropdownIndex = document.forms.razeni[el].selectedIndex;
	var dropdownValue = document.forms.razeni[el][dropdownIndex].value;
	return dropdownValue;
}

function getSelected2(el) 
{
	var dropdownIndex = document.forms.razeni2[el].selectedIndex;
	var dropdownValue = document.forms.razeni2[el][dropdownIndex].value;
	return dropdownValue;
}

function setSelected(el, el2) 
{     
      
	var dropdownIndex = document.forms.razeni[el].selectedIndex;
	var dropdownValue = document.forms.razeni[el][dropdownIndex].value;
      
	$("#orderby").val(dropdownValue);
}


/**
 * Ovladaci prvky posuvneho pasu, ktery je ulozen v itemlist/strip.st
 *
 */  
function printPrevious(textString)
{
	document.write('<a class="prev" href="#" title="' + textString + '"><span>' + textString + '</span></a><div id="slideshow">');
}

function printNext(textString)
{
	document.write('</div><a class="next" href="#" title="' + textString + '"><span>' + textString + '</span></a><br class="clear_both" />');	
}


/*fce otevri - detail tématické krabice, otevírá a zavírá boxy s popisem vín, šipky pod obrázkem a otvírá a zavírá také seznam*/
function otevri(co)
{

	document.getElementById("tema_packet_list").style.display = "none";
	document.getElementById("tema_packet_0").style.display = "none";
	document.getElementById("tema_packet_1").style.display = "none";
	document.getElementById("tema_packet_2").style.display = "none";
	document.getElementById("tema_packet_3").style.display = "none";
	document.getElementById("tema_packet_4").style.display = "none";
	document.getElementById("tema_packet_5").style.display = "none";
	//document.getElementById("charakteristiky").style.display = "block";

	document.getElementById("tema_packet_"+co).style.display = "block";

	document.getElementById("tema_sipka0").style.display = "none";
	document.getElementById("tema_sipka1").style.display = "none";
	document.getElementById("tema_sipka2").style.display = "none";
	document.getElementById("tema_sipka3").style.display = "none";
	document.getElementById("tema_sipka4").style.display = "none";
	document.getElementById("tema_sipka5").style.display = "none";

	if (co != "list")
	{
		document.getElementById("tema_sipka"+co).style.display = "inline";
		$(".navbar").css("display","block");
	}

	if (co == "list")
	{
		$("#obsah_baleni_odkaz").css("display","block");
	//document.getElementById("charakteristiky").style.display = "none";
	}

	return false;
}
$(document).ready(function() {
  if($("#linkToEshop").length > 0)
  {
    showTemaNews($("#linkToEshop").attr("href"), 1);                             
  }

  if($("#main_content #filterWrapper").length > 0)
  {
    showFilter($("#filterWrapper").attr("class"));
  }  

	//item-detail add to bookmarks
	$('#hlidani').append('<a id="pridat_oblibene" onclick="test();" href="javascript:window.external.AddFavorite(location.href,document.title);"  title="přidat mezi oblíbené">Přidat mezi oblíbené</a>');
});

function showFilter(catId)
{
//return false;
//	$('#filterWrapper').empty();
//	$('#filterWrapper').html('<img src="/pages/frontend/img/loader.gif" style="margin-left: 270px" alt="nabídka se načítá..." />');
	$.ajax({
		type : "GET",
		url : "index.php?filterInit=1&cat="+catId,
		cache: false,
		success : function(result) {

			$('#filterWrapper').html(result);      

		}	
	});

}

function test() {

	window.sidebar.addPanel
	(document.title,location.href,'');

}
function getUrlVars()
{
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
	{
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}
$(document).ready(function(){
	//initial hide tabs
	var $var = "";
	if(getUrlVars()["page"]) {
		$var =  getUrlVars()["page"];
	}
   
	$('.tabsHide').each(function() {
		$(this).css('display', 'none');
	})

	// linkTo = (window.location.hash );

	if(window.location.hash == '') {
		//initial show first tab
 
		//ulozim si hodnotu pro pozdejsi pouziti v dalsim documnet ready bloku...
		var pageParam = $var; 
         
		if($var != "hodnoceni#ceni") {

			if($('#charakteristiky')) {
             
				$('#charakteristiky').css('display','block');
    
				$('div[lang="charakteristiky"]').addClass('detail_zalozka_active');
			}
		} 

		if($('#orders')) {
               
			$('#orders').css('display','block');
    
			$('div[lang="orders"]').addClass('detail_zalozka_active');
		}

		if($('#rated')) {
             
			$('#rated').css('display','block');
    
			$('div[lang="rated"]').addClass('detail_zalozka_active');
		}
	/* if($('#ceni')) {
             
			     $('#hodnoceni').css('display','block');
    
                 $('div[lang="hodnoceni"]').addClass('detail_zalozka_active');
           }
           */
           
	} else {
		// lang = window.location.hash;
		// lan = lang.replace("#","");
		lang = window.location.hash.slice(1);
		lan = lang.replace("NaN","");  
		if(lan == 'ceni') {
			lan = 'hodnoceni';
		} 
         
         
		$('div[lang='+lan+']').addClass('detail_zalozka_active');
		$('#'+lan).css('display','block');
	}
    

	$('div.ll').live('click',function(e) {
         
		 
		  
		  
		$('div.detail_zalozka').each(function() {
               
			$(this).removeClass('detail_zalozka_active');
        
		});
          
		lang =  $(this).attr('lang'); 
		$(this).addClass('detail_zalozka_active');
          
		$('.tabsHide').each(function() {
                           
                       
			$(this).css('display','none');
		});

		$('#'+lang).css('display','block');
          
		window.location.hash = +'#'+lang;
          
		if(window.location.hash.slice(1) != 'NaNhodnoceni') {
          	
			if($(this).hasClass('ss')) {
			  	
			}else {
				$hod = $var.substr(0,9);
					  
				if($hod != "hodnoceni") {
					e.preventDefault();
				}
			}
			   
				
		}
          

	});

	/* MD: zakomentovano kvuli zaktivneni zalozky pri tvaru page=hodnoceni
});


$(document).ready(function() {
*/

	    
	if(getUrlVars()["action"]) {
	 
		$var =  getUrlVars()["action"];
	}
      
	if(window.location.hash == '') {
		//initial show first tab
         
 
	
             
		$('#charakteristiky').css('display','block');
    
		$('div[lang="charakteristiky"]').addClass('detail_zalozka_active');
	}else {
           	   
		var err = $("li.basket-notice").text();
		if(err == "") { 
           	     
					
			if(!$var.substring(0,7) == 'ratings' ) {           
           		         
				window.location.hash = 'universal';
			}
		} else {
           			
			window.location.hash = 'errors';
		}
	}

	//MD: nesmi se zaktivnovat zalozka CHARAKTERISTIKY pri page=hodnoceni  
	if(pageParam == "hodnoceni") {
		$('div[lang="charakteristiky"]').removeClass('detail_zalozka_active');
	}  
          
});


/**
 * Pouziva se v PersonalPage na hlasovani.
 *
 */   
function setRating(id, root_url)
{
	window.open(root_url+"system/elements/personalPage/ratings.php?id=" + id, "rating", "width=600,height=250,menubar=no,resizable=no,left=100,top=100");
}

function setRating2(id, root_url)
{
	window.open(root_url+"system/elements/personalPage/ratings.php?id=" + id, "rating", "width=600,height=250,menubar=no,resizable=no,left=100,top=100");
}

/**
*
*  Javascript open window
*  http://www.webtoolkit.info/
*
*  Pouziva se napr. v detailu vyrobku pro "Poslat priteli"
**/

function openWindow(anchor, options) {

	var args = '';

	if (typeof(options) == 'undefined') {
		var options = new Object();
	}
	if (typeof(options.name) == 'undefined') {
		options.name = 'win' + Math.round(Math.random()*100000);
	}

	if (typeof(options.height) != 'undefined' && typeof(options.fullscreen) == 'undefined') {
		args += "height=" + options.height + ",";
	}

	if (typeof(options.width) != 'undefined' && typeof(options.fullscreen) == 'undefined') {
		args += "width=" + options.width + ",";
	}

	if (typeof(options.fullscreen) != 'undefined') {
		args += "width=" + screen.availWidth + ",";
		args += "height=" + screen.availHeight + ",";
	}

	if (typeof(options.center) == 'undefined') {
		options.x = 0;
		options.y = 0;
		args += "screenx=" + options.x + ",";
		args += "screeny=" + options.y + ",";
		args += "left=" + options.x + ",";
		args += "top=" + options.y + ",";
	}

	if (typeof(options.center) != 'undefined' && typeof(options.fullscreen) == 'undefined') {
		options.y=Math.floor((screen.availHeight-(options.height || screen.height))/2)-(screen.height-screen.availHeight);
		options.x=Math.floor((screen.availWidth-(options.width || screen.width))/2)-(screen.width-screen.availWidth);
		args += "screenx=" + options.x + ",";
		args += "screeny=" + options.y + ",";
		args += "left=" + options.x + ",";
		args += "top=" + options.y + ",";
	}

	if (typeof(options.scrollbars) != 'undefined') {
		args += "scrollbars=1,";
	}
	if (typeof(options.menubar) != 'undefined') {
		args += "menubar=1,";
	}
	if (typeof(options.locationbar) != 'undefined') {
		args += "location=1,";
	}
	if (typeof(options.resizable) != 'undefined') {
		args += "resizable=1,";
	}

	var win = window.open(anchor, options.name, args);
	return false;

}

function showTemaNews(eshopUrl, isInit)
{
	//  $('#linkTemaTop').removeClass('detail_zalozka_active');
	//  $('#linkTemaNews').addClass('detail_zalozka_active');
	showRoller(eshopUrl + "index.php?action=ajaxShowTema&type=news", isInit);
	return false;
}

function showTemaTop(eshopUrl, isInit)
{
	//  $('#linkTemaNews').removeClass('detail_zalozka_active');
	//  $('#linkTemaTop').addClass('detail_zalozka_active');
	showRoller(eshopUrl + "index.php?action=ajaxShowTema&type=topTen", isInit);
	return false;
}


function showRoller(url, isInit)
{
	$('#slideshow').empty();
	$('#slideshow').append('<img class="preloader" src="/pages/frontend/img/loader.gif" alt="nabídka se načítá..." />');
         
	$.ajax({
		type : "GET",
		url : url,
		cache: false,
		success : function(result) {

			$('#slideshow').html(result);      

			//po ajaxovem volani musim znovu inicializovat roller    
			$('#slideshow').serialScroll({
				items:'li',
				prev:'#screen2 a.prev',
				next:'#screen2 a.next',
				offset:0, //(from the left)
				start:0, //as we are centering it, start at the 1nd
				duration:300,
				force:true,
				stop:true,
				lock:false,
				cycle:false, //don't pull back once you reach the end
				easing:'easeOutQuart', //use this easing equation for a funny effect
				jump: false //click on the images to scroll to them
			});

      if(isInit != undefined && $("#homepage #filterWrapper").length > 0)
      {
        showFilter($("#filterWrapper").attr("class"));
      }  

		}	
	});
}


/**
 * Polorozevrene menu (top 3 polozky). 
 */ 
//pro opetovne rozbehani staci odkomentovat!!!
/* 
$(document).ready(function(){
  // menu 
  $('ul#menukat ul').each(function(){
      var status = true;
      var el = $(this);
      var count = 0;
      var langs = {
          cz:{
              open: 'Zobrazit další'
             ,close: 'Skrýt další'
          }
         ,en:{
              open: 'Show categories'
             ,close: 'Hide categories'
          } 
      };
      var langcode = 'cz';//$('html').attr('lang');
      var newUl = $('<ul></ul>')
      
      $('li', this).each(function(i){
          if(i>2){
              newUl.append($(this));
              if($(this).hasClass('.active')){
                  count++;
              }
          }
      });
      
      if(count<=0){
          newUl.hide();
          status = false;
          el.append('<li><a href="#" class="category-show-hide">'+ langs[langcode]['open'] +'</a></li>');
      }
      else{
          el.append('<li><a href="#" class="category-show-hide">'+ langs[langcode]['close'] +'</a></li>');
      }
      el.append(newUl);
      
      $('.category-show-hide', this).click(function(){
          if(status)
          {
              newUl.slideUp()
              status = false;
              $(this).text(langs[langcode]['open'])     
          }
          else
          {
              newUl.slideDown()
              $(this).text(langs[langcode]['close'])
              status = true;
          }
          return false;
      });
  });
});
*/
