$(document).ready(function(){
  $.ga.load($("#ga_id").val());
  $(".select_ms").msDropDown();
  $("#pager").Pager();
  $("#gal_content").Gallery();
  $("#main_image").Vyr_gallery();
  $("a[rel=external]").attr("target","_blank");
  $('.make_cloak').Cloak();
  $(".cloak").css("fontSize","0");
  $('.tTip').betterTooltip({speed: 150, delay: 300});
  $(".tabs").tabs();
  $(".tabs").removeClass("ui-corner-all");
  $("table.striped tr:even").addClass("stripe-odd");
  $("#vyr_tech tr td:odd").css("fontWeight","bold");
  $("#social").jsocial({highlight: false,
buttons: "facebook,twitter,linkuj,linkedin,google,myspace,yahoo,digg,reddit",
imagedir: "html/images/social/",
imageextension: "gif",
blanktarget: true});
  first_time_launch();
  set_mapa();
  set_vedlejsi_vetve();
  $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
      && location.hostname == this.hostname) {
          var $target = $(this.hash);
          $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
          if ($target.length) {
              var targetOffset = $target.offset().top;
              $('html,body').animate({scrollTop: targetOffset}, 500,"swing");
              return false;
          }
      }
  });

  $("#slider_cena").slider({
			range: true,
			min: 1,
			max: $("input[name=cenovy_rozsah_max]").val(),
			values: [1, $("input[name=cenovy_rozsah_max]").val()],
			slide: function(event, ui) {
        $("input[name=cenovy_rozsah_min]").val(ui.values[0]);
	      $("input[name=cenovy_rozsah_max]").val(ui.values[1]);
			}
	});
  $(".btn").button();
  $(".btn_set").buttonset();

  $("li.filtr").click(function(event){
    event.stopPropagation();
    $("#filtr").show();
  });
  $("body").click(function(){
    $("#filtr").hide();
  });
  $("#hledej").focus(function(){
    $(this).css("backgroundPosition","0 -29px");
  });
  $("#hledej").blur(function(){
    $(this).css("backgroundPosition","0 0");
  });
  $("input.hledat").hover(function(){
    $(this).css("backgroundPosition","right -18px");
  });
  $("div.share").mouseover(function(){
    $("#social").show();
  });
  $("div.share").mouseout(function(){
    $("#social").hide();
  });
  $("input.hledat").mouseout(function(){
    $(this).css("backgroundPosition","right 4px");
  });
  $("#tr_basket").mouseover(function(){
    $(this).css("backgroundPosition","-227px -32px");
  });
  $("#tr_basket").mouseout(function(){
    $(this).css("backgroundPosition","-227px 0");
  });
  $("#hlavni_vetve li").mouseover(function(){
    $(this).css("backgroundPosition","0 -274px");
  });
  $("#hlavni_vetve li").mouseout(function(){
    $(this).css("backgroundPosition","0 0");
  });
  $("#vedlejsi_vetve li").mouseover(function(){
    $(this).css("backgroundPosition","0 -274px");
  });
  $("#vedlejsi_vetve li").mouseout(function(){
    $(this).css("backgroundPosition","0 0");
  });
  $(".podvetve li").mouseover(function(){
    $(this).children("h3").css("backgroundPosition","0 -40px");
  });
  $(".podvetve li").mouseout(function(){
    $(this).children("h3").css("backgroundPosition","0 0");
  });
  $("#tr_login").mouseover(function(){
    $(this).css("backgroundPosition","0 -32px");
  });
  $("#tr_login").click(function(){
    $("#login .login_basket_content").toggleClass("tr_show");
  });
  $("#tr_basket").click(function(){
    $("#basket .login_basket_content").toggleClass("tr_show");
  });
  $("a.prev_arrow").mousedown(function(){
    $(this).children("span").css("backgroundPosition","0 -26px");
  });
  $("a.prev_arrow").mouseup(function(){
    $(this).children("span").css("backgroundPosition","0 0");
  });
  $("a.prev_arrow").mouseleave(function(){
    $(this).children("span").css("backgroundPosition","0 0");
  });
  $("a.next_arrow").mousedown(function(){
    $(this).children("span").css("backgroundPosition","-26px -26px");
  });
  $("a.next_arrow").mouseup(function(){
    $(this).children("span").css("backgroundPosition","-26px 0");
  });
  $("a.next_arrow").mouseleave(function(){
    $(this).children("span").css("backgroundPosition","-26px 0");
  });
  $(".subnav").parent("li").mouseover(function(){
    $(this).children("ul.submenu").show();
  });
  $(".subnav").parent("li").mouseout(function(){
    $(this).children("ul.submenu").hide();
  });
  $("#tr_login").mouseout(function(){
    $(this).css("backgroundPosition","0 0");
  });
  $(".kam_content").mouseover(function(){
    var $h = $(this).children("h3");
    $h.css("color","#fff");
  });
  $(".kam_content").mouseout(function(){
    var $h = $(this).children("h3");
    $h.css("color","#9999cc");
  });
  $(".vlozit .add").mouseover(function(){
    $(this).css("backgroundPosition","0 -28px");
  });
  $(".vlozit .add").mouseout(function(){
    $(this).css("backgroundPosition","0 0");
  });
  $(".btm_content").mouseover(function(){
    var $h = $(this).prev();
    var $hspan = $h.children("span");
    if ($h.hasClass("kamkliknout"))
      $(this).prev().children("span").css("backgroundPosition","0 -17px");
    if ($h.hasClass("neprehlednete"))
      $(this).prev().children("span").css("backgroundPosition","-122px -17px");
    if ($h.hasClass("jsmeclenem"))
      $(this).prev().children("span").css("backgroundPosition","-259px -17px");
  });
  $(".btm_content").mouseout(function(){
    var $h = $(this).prev();
    var $hspan = $h.children("span");
    if ($h.hasClass("kamkliknout"))
      $(this).prev().children("span").css("backgroundPosition","0 0");
    if ($h.hasClass("neprehlednete"))
      $(this).prev().children("span").css("backgroundPosition","-122px 0");
    if ($h.hasClass("jsmeclenem"))
      $(this).prev().children("span").css("backgroundPosition","-259px 0");
  });

  $(".printer").click(function(){
    var $titulek = $(this).attr("rel");
    $("#mapa").html("<img src='http://new.audiopro.cz/html/templates/www/content/cs/images/mapa.gif' alt='mapa' />");
    $('.toPrint').printElement({overrideElementCSS: true,pageTitle: $titulek+' | audiopro s.r.o.'});
    set_mapa();
    return false;
  });


  $(".show_prodejna").click(function(){
    set_mapa();
    return false;
  });
  $(".show_sklad").click(function(){
    set_mapa("sklad");
    return false;
  });
  $("a.open_podvetve").click(function(){
    $(this).next().slideToggle();
    return false;
  });
  $("div#all_news").hide();
  $("div.show_all_news").html("<a href='' title='"+$("div.show_all_news").attr("title")+"'>"+$("div.show_all_news").attr("title")+"</a>");
  $("div.show_all_news").css("borderTopStyle","dashed");
  $("div.show_all_news").css("borderBottomStyle","dashed");
  $("div.show_all_news a").click(function(){
    $("div#all_news").show();
    $("div.show_all_news").hide();
    return false;
  });
});

function first_time_launch()
{
  if ($.cookie("first_time")!="true")
  {
    $("#mainbar").append("<div id='first-time'></div>");
    $("#first-time").html("Všimli jste si, že v této liště máte neustálý přístup k <b>produktovému katalogu</b>, <b>řešením</b>, <b>našim dodavatelům</b> a zejména <b>vyhledávání</b> na stránkách? Lišta Vás bude provázet celým webem a vždy ji naleznete umístěnu v horní části prohlížeče. <br /> <br />(Kliknutím na toto upozornění jej zavřete.)");
    $("#first-time").fadeIn("slow");
    $("#first-time").click(function(){
      $(this).fadeOut("slow");
    });
  }
  $.cookie("first_time", "true", { expires: 7 });
}

function set_vedlejsi_vetve()
{
  var vetev = $("#vedlejsi_vetve li");
  vetev.prepend("<div class='inactive'></div>");
  $("div.inactive").mouseover(function(){
    $(this).fadeOut();
  });
}

function set_mapa($typ)
{
  if (!$typ)
  {
    	$("#mapa").googleMaps({
    	latitude: 50.099000,
      longitude: 14.346029,
      markers: {
        latitude: 	50.101138,
        longitude: 14.341790,
        icon: {
        	image: 'http://new.audiopro.cz/html/templates/www/content/cs/images/apro_icon.png',
          iconSize: '30, 30',
        }
      },
      depth: 16,
      scroll: false,
      polyline: {
          color: 			"#0000ff",
          levels: 		"BBBBBBBBBBBBBBBBB",
          points:     "ojwpHceqvAg@Jg@ImAMyAWcBSw@@gGz@gABy@DaAPcAd@yCpDdAhGzAxMAtFm@@",
          weight:     5,
          numLevels:  4,
          zoomFactor: 32
      }
    });
  }else{
    	$("#mapa").googleMaps({
    	latitude: 50.099000,
      longitude: 14.346029,
      markers: {
        latitude: 	50.101138,
        longitude: 14.341790,
        icon: {
        	image: 'http://new.audiopro.cz/html/templates/www/content/cs/images/apro_icon.png',
          iconSize: '30, 30',
        }
      },
      depth: 16,
      scroll: false,
      polyline: {
          color: 			"#FF8A00",
          levels: 		"BBBBBBBBBBBBBBBBBBBBBB",
          points:     "ojwpHceqvAg@Jg@ImAMyAWcBSw@@gGz@gABy@DaAPcAd@yCpDcA~Au@`DKhAAlBObANhAFxA~@DAv@",
          weight:     5,
          numLevels:  4,
          zoomFactor: 32
      }
    });
  }
}