var txtHideComments = 'Skrýt diskuzi';
var txtShowComments = 'Zobrazit diskuzi';
var infowindow;
var map;
var markers = {};

$(document).ready(function(){
	

  // wait function
  $.fn.wait = function(time, type) {
    time = time || 1000;
    type = type || "fx";
    return this.queue(type, function() {
      var self = this;
      setTimeout(function() {
        $(self).dequeue();
      }, time);
    });
  };

  // font resize
  setUserOptions();
  $("#fx-fontdecr").click(function() {
    switchFontSize('dec');
    return false;
  });
  $("#fx-fontincr").click(function() {
    switchFontSize('inc');
    return false;
  });
  
  // hpFlash
/*  $("#hpFlash ul li a").click(function() {
    var link = $(this);
    $("#hpFlash a.main").attr("href", $(this).attr("rel"));
    $("#hpFlash ul li a").removeClass("active");
    $(this).addClass("active");
    
    $("#hpFlash .h").fadeOut("normal", function() { $(this).text($(link).attr("title")) }).wait(300).fadeIn();
    $("#hpFlash img").fadeOut("normal", function() { $(this).attr("src", $(link).attr("href")) }).wait(300).fadeIn();
    return false;
  });*/
  
  /*$("#hpFlash ul li a").click(function() {
    var link = $(this);
    
    $("#hpFlash").fadeOut("normal", function() {
      $("#hpFlash ul li a").removeClass("active");
      $(link).addClass("active");
    
      $(this).find("a.main").attr("href", $(link).attr("rel")); 
      $(this).find(".h").text($(link).attr("title"));
      $(this).find("img").attr("src", $(link).attr("href"));
    }).wait(200).fadeIn();
    return false;
  });*/
  $("#hpFlash").slideshow({ duration: 3000 });
  
  // products filter
  $("#productsFilter .order .title").click(function() {
    var li = $(this).parents("li");
    if($(li).hasClass("minus")) {
      $(li).find("ul").hide();
      $(li).removeClass("minus").addClass("plus");
    } else {
      $(li).find("ul").show();
      $(li).removeClass("plus").addClass("minus");
    }

    return false;
  });
  $(".col3 .mainMenu li a, .col4 .maninMenu li a").click(function(){
	  if ($("div.order").hasClass("disable")) $(this).attr('href',$(this).attr('href')+"?filteroff=true");
  });
  //$("#productsFilter input:submit").hide();
  $("#productsFilter input:checkbox").change(function() { $("#productsFilter form").submit(); });
  
  $("#productsFilter label").click(function(){
	 $("#"+$(this).attr("for")).attr("checked",!$("#"+$(this).attr("for")).is(":checked"));
	 $("#productsFilter form").submit();
  });
  $("#productsFilter select").change(function() { $("#productsFilter form").submit(); });
  $(".items.categories li").click(function(){
	  $(this).children("input:checkbox").attr("checked",true);
	  $("#productsFilter form").submit();
  });
  
  $(".attrvals li input").each(function(){
	  if ($(this).is(":checked")) $(this).parent().toggleClass("checked");
  });
  
  $(".recommend").click(function() { $(this).parents("li").find(".formBox").slideToggle(); return false; });;
  
  $("#hideComments").click(function() {
    if($(this).hasClass("hideComments")) {
      $(".comments .item").show();
      $("#commentsForm").show();
      $(this).text(txtHideComments);
      $(this).removeClass("hideComments");
    } else {
      $(".comments .item").hide();
      $("#commentsForm").hide();
      $(this).text(txtShowComments);
      $(this).addClass("hideComments");
    }
    return false;
  });
  
  // lightbox gallery
//  $(".gallery li a").lightBox({ imageLoading:	'/app/templates/images/lightbox/lightbox-ico-loading.gif', imageBtnPrev:	'/app/templates/images/lightbox/lightbox-btn-prev.gif', imageBtnNext:	'/app/templates/images/lightbox/lightbox-btn-next.gif', imageBtnClose: '/app/templates/images/lightbox/lightbox-btn-close.gif', imageBlank:	'/app/templates/images/lightbox/lightbox-blank.gif', txtImage:	'Obrázek', txtOf: 'z'});
  
$('a.highslide').each(function() {
	this.onclick = function() {
		return hs.expand(this,config1);
	};
});
  
if ($("#productDetail img.main").length > 0) {
	if ($("#productDetail #gallery").length > 0) {
		$("#productDetail img.main").css("cursor","pointer");
		$("#productDetail img.main").click(function(){
			$("#gallery a.highslide:first").trigger("click");
			return false;
		});
	}
}
  // ochrana proti spamu
  $("#formChecking").hide();
  $("#formChecking select option").each(function() {
    if($(this).attr("value") == 3*9) $(this).attr("selected", "selected");
  });
  $("#basketOrder input:submit[name='submit']").hide();
  var sub = $("#basketOrder input:submit[name='submit']").clone().show();
  $("#basketOrder input:submit[name='action']").after(sub);
  
  
  $("#productsList .item").hover(
    function() {
      $(this).find(".detail").show();
    }, 
    function() {
      $(this).find(".detail").hide();
  });
  
  $(".mapapop").click(function(){

	  if ($("#mapaop").length == 0) {
			 $pop = $('<div id="mapaop"><div id="mapa"></div><a id="close">X</a></div>');
			 $pop.children("a").click(function(){ $("#mapaop").fadeOut();  });
			 
			 $("body").append($pop);
		 	 var myOptions = {
				    zoom: 17,
				    center: new google.maps.LatLng(50.105625, 14.484737),
				    mapTypeId: google.maps.MapTypeId.ROADMAP,
				    scrollwheel: false
				};
		 	 	infowindow = new google.maps.InfoWindow();
				map = new google.maps.Map(document.getElementById("mapa"),myOptions);	  
		    	var myLatLng = new google.maps.LatLng(50.105625, 14.484737);
		    	markers[1] = new google.maps.Marker({
		    	    position: myLatLng,
		    	    map: map,
		    	    title: "OBÝVACÍ POKOJE, STOLY A ŽIDLE",
		    	    html: "<h2>Interiérové studio</h2><h3>OBÝVACÍ POKOJE, STOLY A ŽIDLE</h3><p>Sokolovská 175<br />Balabenka - Praha 9, 190 00<br />Tel./fax.: 266 310 147<br />Tel.: 284 824 279, 602 245 858<br /><img src='/app/templates/images/bg-logo.gif' width='50' /></p>",
		    	    zIndex: 100
		    	});		 
		        google.maps.event.addListener(markers[1], 'click', function() {
		        	infowindow.content = markers[1].html; 
		        	infowindow.open(map,markers[1]);
		        });
		    	var myLatLng1 = new google.maps.LatLng(50.105053, 14.484239);
	    	 	
		    	markers[2]= new google.maps.Marker({
		    	    position: myLatLng1,
		    	    map: map,
		    	    title: "KANCELÁŘSKÝ NÁBYTEK",
		    	    html: "<h2>Interiérové studio</h2><h3>KANCELÁŘSKÝ NÁBYTEK</h3><p>Sokolovská 224<br />Praha 8, 182 00<br />Tel./Fax.: 266 310 418, Tel.:  602 690 970<br /><img src='/app/templates/images/bg-logo.gif' width='50' /></p>",
		    	    zIndex: 100
		    	});		 
		        google.maps.event.addListener(markers[2], 'click', function() {
		        	infowindow.content = markers[2].html; 
		        	infowindow.open(map,markers[2]);
		        });		    	
		    	var myLatLng2 = new google.maps.LatLng(50.104654, 14.483926);
	    	 	
		    	markers[3] = new google.maps.Marker({
		    	    position: myLatLng2,
		    	    map: map,
		    	    title: "KUCHYNĚ, LOŽNICE, STOLY A ŽIDLE ",
		    	    html: "<h2>Interiérové studio</h2><h3>KUCHYNĚ, LOŽNICE, STOLY A ŽIDLE</h3><p>Sokolovská 222<br />Balabenka - Praha 9, 190 00<br />Tel./fax.: 284 689 779 Tel.:  724 030 506<br /><img src='/app/templates/images/bg-logo.gif' width='50' /></p>",
		    	    zIndex: 100
		    	});
		        google.maps.event.addListener(markers[3], 'click', function() {
		        	infowindow.content = markers[3].html; 
		        	infowindow.open(map,markers[3]);
		        });
		    	var myLatLng3 = new google.maps.LatLng(50.104626, 14.525017);
	    	 	
		    	markers[4] = new google.maps.Marker({
		    	    position: myLatLng3,
		    	    map: map,
		    	    title: "SKLADOVÝ AREÁL",
		    	    html: "<h2>SKLADOVÝ AREÁL</h2><p>Poděbradská 781/61<br />190 00 Praha 9<br /><img src='/app/templates/images/bg-logo.gif' width='50' /></p>",
		    	    zIndex: 100
		    	});	
		        google.maps.event.addListener(markers[4], 'click', function() {
		        	infowindow.content = markers[4].html; 
		        	infowindow.open(map,markers[4]);
		        });

	  }	  
	  
	  var x = $(this).attr("id").substr(3);
	  google.maps.event.trigger(markers[x], 'click');
	   $("#mapaop").center();
	   $("#mapaop").fadeIn();	    	
	   return false;
  });
  
});
jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}

