
var Interval = false; var TimeOut = false; var PhotoInterval = false; var MouseX = false; var MouseY = false; var AktPrez = false;

$(window).load(function(){
  if($("#interactive-photos")){ $("#interactive-photos-loader").remove(); MoveToPhoto('false','noanim'); PhotoInterval = setInterval("MoveToPhoto('false','anim')",5000);};
  if($("#interactive-products")){ $("#interactive-products-loader").remove();};
  if($("#aktualita-prezentace")){ $("#aktualita-prezentace").slideDown('slow'); AktPrez = setTimeout("HideAktualitaPrezentace()",7500); };
})

$(document).bind('mousemove',function(e){ MouseX = e.pageX; MouseY = e.pageY;});

$(document).ready(function(){
  var SiteHeight = $(".site").innerHeight(); var HeadHeight = $("#head").innerHeight(); var MenuHeight = $("#menu").innerHeight(); var PrezentationHeight = $("#prezentation").innerHeight();
  var NewHeight = parseInt(SiteHeight - (HeadHeight + MenuHeight + PrezentationHeight)); /*$("#left-content").css('height',parseInt(NewHeight-150)+'px')*/
  
  $(".third").mouseover(function(){
    $(".third-sub").show();
  })
  $(".third").mouseout(function(){
    $(".third-sub").hide();
  })
  
  $(".dwn-table").tablesorter({
    headers: { 3: { sorter: false }},
    sortList: [[0,0]]
  }); 
  
  $(".dwn-table tbody tr").mouseover(function(){
    $(this).addClass('over');
    var $src = $(this).children('.action').children('a').children('img').attr('src');
    $src = $src.replace('.png','-over.png');
    $(this).children('.action').children('a').children('img').attr('src',$src);
  })
  $(".dwn-table tbody tr").mouseout(function(){
    $(this).removeClass('over');
    var $src = $(this).children('.action').children('a').children('img').attr('src');
    $src = $src.replace('-over','');
    $(this).children('.action').children('a').children('img').attr('src',$src);
  })
  
  $("a.nw").click(function(){
    window.open($(this).attr('href'));
    return false;
  })
  
  $("a.group").mouseover(function(){
    TooltipShow($(this));
  })
  $("a.group").mousemove(function(){
    TooltipSetPosition();
  })
  $("a.group").mouseout(function(){
    TooltipHide();
  })
  
  $("#aktualita-prezentace-show-again").click(function(){
    $("#aktualita-prezentace").slideDown('slow');
    $(this).slideUp('medium');
  })
  $("#aktualita-prezentace p.close span").click(function(){
    HideAktualitaPrezentace();
  })

  $(".prezentation-link").click(function(){
    clearInterval(PhotoInterval); PhotoInterval = false; MoveToPhoto($(this),'anim');
  });
  
  
  
  if($("#interactive-products")){
    var ProductPointsX = new Array(); var ProductPointsY = new Array(); var ProductPointsText = new Array();
    ProductPointsX[0] = 55; ProductPointsY[0] = 460; ProductPointsText[0] = "<h4><span class='square okrova'></span>Nádoby na rostliny <a class='products-point-more' href='#manufaktura'>&raquo; více</a><span class='kal-text'>katalog strana 148</span></h4>\
                                                                             <a class='group' rel='nadoby-na-rostliny' title='Nádoby na rostlilny' href='http://www.godelmann.cz/settings/sett.resize.php?img=../interactive-products-foto/nadoba-na-rostliny.jpg&amp;w=700'><img src='http://www.godelmann.cz/settings/sett.resize.php?img=../interactive-products-foto/nadoba-na-rostliny.jpg&amp;h=75' alt='Nádoby na rostlilny' title='Nádoby na rostlilny' /></a>\
                                                                             ";
    ProductPointsX[1] = 265; ProductPointsY[1] = 455; ProductPointsText[1] = "<h4><span class='square cerna'></span>XXL velkodlažební systémy <a class='products-point-more' href='#dlazba'>&raquo; více</a><span class='kal-text'>katalog strana 20</span></h4>\
                                                                              <a class='group' rel='xxl-velkodlazebni-systemy' href='http://www.godelmann.cz/settings/sett.resize.php?img=../products-foto/deska-casado-finerro-1.jpg&amp;w=700'><img src='http://www.godelmann.cz/settings/sett.resize.php?img=../products-foto/deska-casado-finerro-1.jpg&amp;h=75' alt='XXL velkodlažební systémy' title='XXL velkodlažební systémy' /></a>\
                                                                              <a class='group' rel='xxl-velkodlazebni-systemy' href='http://www.godelmann.cz/settings/sett.resize.php?img=../products-foto/deska-verdano-1.jpg&amp;w=700'><img src='http://www.godelmann.cz/settings/sett.resize.php?img=../products-foto/deska-verdano-1.jpg&amp;h=75' alt='xxl-velkodlazebni-systemy' title='XXL velkodlažební systémy' /></a>\
                                                                              ";
    ProductPointsX[2] = 305; ProductPointsY[2] = 575; ProductPointsText[2] = "<h4><span class='square modra'></span>Schody a podesty <a class='products-point-more' href='#schody-a-podesty'>&raquo; více</a><span class='kal-text'>katalog strana 110</span></h4>\
                                                                              <a class='group' rel='schody-a-podesty' href='http://www.godelmann.cz/settings/sett.resize.php?img=../interactive-products-foto/schody.jpg&amp;w=700'><img src='http://www.godelmann.cz/settings/sett.resize.php?img=../interactive-products-foto/schody.jpg&amp;h=75' alt='Schody a podesty' title='Schody a podesty' /></a>\
                                                                              <a class='group' rel='schody-a-podesty' href='http://www.godelmann.cz/settings/sett.resize.php?img=../interactive-products-foto/podesta.jpg&amp;w=700'><img src='http://www.godelmann.cz/settings/sett.resize.php?img=../interactive-products-foto/podesta.jpg&amp;h=75' alt='Schody a podesty' title='Schody a podesty' /></a>\
                                                                              ";
    ProductPointsX[3] = 275; ProductPointsY[3] = 655; ProductPointsText[3] = "<h4><span class='square cerna'></span>Drážky pro svítidla <a class='products-point-more' href='#vodici-systemy'>&raquo;více</a><span class='kal-text'>katalog strana 175</span></h4>\
                                                                              ";
    ProductPointsX[4] = 475; ProductPointsY[4] = 625; ProductPointsText[4] = "<h4><span class='square okrova'></span>Manufaktura <a class='products-point-more' href='#manufaktura'>&raquo; více</a><span class='kal-text'>katalog strana 146</span></h4>\
                                                                              ";
    ProductPointsX[5] = 385; ProductPointsY[5] = 460; ProductPointsText[5] = "<h4><span class='square seda'></span>Systémy pro odvádění vody <a class='products-point-more' href='#vodici-systemy'>&raquo; více</a><span class='kal-text'>katalog strana 167</span></h4>\
                                                                              ";
    ProductPointsX[6] = 555; ProductPointsY[6] = 400; ProductPointsText[6] = "<h4><span class='square olivova'></span>Ekologická dlažba <a class='products-point-more' href='#ekologicka-dlazba'>&raquo; více</a><span class='kal-text'>katalog strana 86</span></h4>\
                                                                              ";
    ProductPointsX[7] = 505; ProductPointsY[7] = 335; ProductPointsText[7] = "<h4><span class='square okrova'></span>Manufaktura <a class='products-point-more' href='#manufaktura'>&raquo; více</a><span class='kal-text'>Desky k ohraničení stromu<br />katalog strana 144</span></h4>\
                                                                              ";
    ProductPointsX[8] = 545; ProductPointsY[8] = 235; ProductPointsText[8] = "<h4><span class='square okrova'></span>Nábytek <a class='products-point-more' href='#manufaktura'>&raquo; více</a><span class='kal-text'>katalog strana 144</span></h4>\
                                                                              ";
    ProductPointsX[9] = 745; ProductPointsY[9] = 235; ProductPointsText[9] = "<h4><span class='square fialova'></span>Zdi a svahová upevnění <a class='products-point-more' href='#zdi-a-svahova-upevneni'>&raquo; více</a><span class='kal-text'>katalog strana 120</span></h4>\
                                                                              <a class='group' rel='zdi-a-svahova-upevneni' href='http://www.godelmann.cz/settings/sett.resize.php?img=../interactive-products-foto/zdi.jpg&amp;w=700'><img src='http://www.godelmann.cz/settings/sett.resize.php?img=../interactive-products-foto/zdi.jpg&amp;h=75' alt='Zdi a svahová upevnění' title='Zdi a svahová upevnění' /></a>\
                                                                              ";
    ProductPointsX[10] = 1045; ProductPointsY[10] = 255; ProductPointsText[10] = "<h4><span class='square fialova'></span>Opěrné systémy <a class='products-point-more' href='#zdi-a-svahova-upevneni'>&raquo; více</a><span class='kal-text'>katalog strana 120</span></h4>\
                                                                                  ";
    ProductPointsX[11] = 965; ProductPointsY[11] = 425; ProductPointsText[11] = "<h4><span class='square zluta'></span>Obloukové klíny <a class='products-point-more' href='#zdi-a-svahova-upevneni'>&raquo; více</a><span class='kal-text'>katalog strana 24/57/59/61/67/109</span></h4>\
                                                                                  ";
    ProductPointsX[12] = 765; ProductPointsY[12] = 460; ProductPointsText[12] = "<h4><span class='square seda'></span>Vodící systémy pro nevidomé <a class='products-point-more' href='#vodici-systemy'>&raquo; více</a><span class='kal-text'>katalog strana 154 - 155</span></h4>\
                                                                                  ";
    ProductPointsX[13] = 815; ProductPointsY[13] = 580; ProductPointsText[13] = "<h4><span class='square seda'></span>Obrubník <a class='products-point-more' href='#vodici-systemy'>&raquo; více</a><span class='kal-text'>katalog strana 152</span></h4>\
                                                                                  ";
    
    $("#move-products-top").mousedown(function(){
      if (Interval == false) { Interval = setInterval("InteractiveProductScroll('top','#move-products-top')", 20); }
    });
    $("#move-products-top").mouseup(function(){ clearInterval(Interval); Interval = false; })
    $("#move-products-right").mousedown(function(){
      if (Interval == false) { Interval = setInterval("InteractiveProductScroll('right','#move-products-right')", 20); }
    });
    $("#move-products-right").mouseup(function(){ clearInterval(Interval); Interval = false; })
    $("#move-products-bottom").mousedown(function(){
      if (Interval == false) { Interval = setInterval("InteractiveProductScroll('bottom','#move-products-bottom')", 20); }
    });
    $("#move-products-bottom").mouseup(function(){ clearInterval(Interval); Interval = false; })
    $("#move-products-left").mousedown(function(){
      if(Interval == false){  Interval = setInterval("InteractiveProductScroll('left','#move-products-left')",20); }
    });
    $("#move-products-left").mouseup(function(){ clearInterval(Interval); Interval = false; })
    
    for(i = 0; i < ProductPointsX.length; i++){
      var Ar = new Array(ProductPointsX[i],ProductPointsY[i],ProductPointsText[i]);
      CreateProductsPoint(Ar);
    };
    
    $(".product-point").click(function(){
      var rel = $(this).attr('rel');
      $("." + rel).toggle('medium');
    });
    $(".product-point-close").click(function(){
      var rel = $(this).attr('rel');
      $("." + rel).hide('medium');
    })
  
  
    $(".products-point-more").click(function(){
      var Href = $(this).attr('href'); var Length = Href.length;
      var Div = Href.substr(1,Length);
      if ($("h3 a[name=" + Div + "]").hasClass('produkty-kategorie-closed')) {
        $("div." + Div).slideToggle('fast');
        if ($("h3 a[name=" + Div + "]").hasClass('produkty-kategorie-closed')) {
          $("h3 a[name=" + Div + "]").removeClass('produkty-kategorie-closed');
          $("h3 a[name=" + Div + "]").addClass('produkty-kategorie-opened');
        }
        else 
          if ($("h3 a[name=" + Div + "]").hasClass('produkty-kategorie-opened')) {
            $("h3 a[name=" + Div + "]").removeClass('produkty-kategorie-opened');
            $("h3 a[name=" + Div + "]").addClass('produkty-kategorie-closed');
          }
      }
    })
  }
  $(".produkty-kategorie").click(function(){
    var Div = $(this).attr('name'); $("div."+Div).slideToggle('fast');
    if($(this).hasClass('produkty-kategorie-closed')){
      $(this).removeClass('produkty-kategorie-closed');
      $(this).addClass('produkty-kategorie-opened');
    }else if($(this).hasClass('produkty-kategorie-opened')){
      $(this).removeClass('produkty-kategorie-opened');
      $(this).addClass('produkty-kategorie-closed');
    }
  });
  $(".produkty-kategorie-close").click(function(){
    var Div = $(this).attr('name'); $("div."+Div).slideUp('fast');
    var Header = $("h3 a[name='"+Div+"']");
    if($(Header).hasClass('produkty-kategorie-closed')){
      $(Header).removeClass('produkty-kategorie-closed');
      $(Header).addClass('produkty-kategorie-opened');
    }else if($(Header).hasClass('produkty-kategorie-opened')){
      $(Header).removeClass('produkty-kategorie-opened');
      $(Header).addClass('produkty-kategorie-closed');
    } 
  });

  $(".homeTrigger").click(function(){
    var Rel = $(this).attr('rel');
    $("#"+Rel).slideToggle('fast');
  });
});

function InteractiveProductScroll(Direction,Trigger){
  var Step = 10; var ScrollSpeed = 'fast'; var FadeSpeed = 'slow'; var Height = - (parseInt($("#interactive-products").innerHeight() - 413)); var Width = - (parseInt($("#interactive-products").innerWidth() - 960));
  var Value = false; var Current = false; var Next = false;
  if(Direction == 'top'){
    Value = 'top';
    Current = parseInt($("#interactive-products").css(Value));
    Next = parseInt(Current + Step);
    if(Next > 0){Next = 0;};    
  }else if(Direction == 'right'){
    Value = 'left';
    Current = parseInt($("#interactive-products").css(Value));
    Next = parseInt(Current - Step);
    if(Next < Width){Next = Width;};
  }else if(Direction == 'bottom'){
    Value = 'top';
    Current = parseInt($("#interactive-products").css(Value));
    Next = parseInt(Current - Step);
    if(Next < Height){Next = Height;};
  }else if(Direction == 'left'){
    Value = 'left';
    Current = parseInt($("#interactive-products").css(Value));
    Next = parseInt(Current + Step);
    if(Next > 0){Next = 0;};
  }
  
  if(Direction == 'top' || Direction == 'bottom'){$("#interactive-products").css({ 'top': Next+"px"});}; if(Direction === 'left' || Direction == 'right'){$("#interactive-products").css({ 'left': Next+"px"});}
  
  if(Direction == 'top'){
    if(Next == 0){$(Trigger).fadeOut(FadeSpeed); clearInterval(Interval); Interval = false;};
    if(Next != Height){$("#move-products-bottom").fadeIn(FadeSpeed);};
  }else if(Direction == 'right'){
    if(Next == Width){$(Trigger).fadeOut(FadeSpeed); clearInterval(Interval); Interval = false;};
    if(Next != 0){$("#move-products-left").fadeIn(FadeSpeed);};
  }else if(Direction == 'bottom'){
    if(Next == Height){$(Trigger).fadeOut(FadeSpeed); clearInterval(Interval); Interval = false;};
    if(Next != 0){$("#move-products-top").fadeIn(FadeSpeed);};
  }else if(Direction == 'left'){
    if(Next == 0){$(Trigger).fadeOut(FadeSpeed); clearInterval(Interval); Interval = false;};
    if(Next != Width){$("#move-products-right").fadeIn(FadeSpeed);};
  }        
}
function CreateProductsPoint(Point){
  var String = "<p id='text-"+Point[1]+"-"+Point[0]+"' class='product-point' style='top:" + Point[1] + "px;left:" + Point[0] + "px;' rel='text-" + Point[1] + "-" + Point[0] + "'>&nbsp;</p>\
  <div id='text-"+Point[1]+"-"+Point[0]+"' class='product-point-text text-" + Point[1] + "-" + Point[0] + "' style='top:" + (Point[1] + 10) + "px;left:" + (Point[0] + 10) + "px;'>\
    <p class='product-point-close' rel='text-" + Point[1] + "-" + Point[0] + "'>zavřít</p>\
    <div class='product-point-main-text'>" + Point[2] + "</div>\
  </div>";
  $(String).appendTo("#interactive-products");
}
function MoveToPhoto(Trigger,Move){
  if(Trigger == 'false'){
    var randomnumber = (Math.floor(Math.random()*6 + 1));
    Trigger = $(".prezentation-link-"+randomnumber);
  }
  
  $(".prezentation-link").removeClass('active'); $(Trigger).addClass('active');  
  var Image = $(Trigger).html(); var Element = $("#interactive-photos"); var Coords = new Array();
    
  if(Image == 1){
    Coords[0] = 0; Coords[1] = 0; 
  }else if(Image == 2){
    Coords[0] = -413; Coords[1] = 0; 
  }else if(Image == 3){
    Coords[0] = 0; Coords[1] = -960; 
  }else if(Image == 4){
    Coords[0] = -413; Coords[1] = -960; 
  }else if(Image == 5){
    Coords[0] = 0; Coords[1] = -1920; 
  }else if(Image == 6){
    Coords[0] = -413; Coords[1] = -1920; 
  }
  if (Move == 'anim') {
    Element.animate({"top": Coords[0] + "px","left": Coords[1] + "px"}, "slow");
  }else{
    Element.css({"top": Coords[0] + "px","left": Coords[1] + "px"});
  }  
}

function TooltipShow(Element){
  $("<p class='group-image-tooltip' style='position:absolute;'>"+$(Element).attr('title')+"</p>").insertAfter(Element);
}
function TooltipHide(){
  $(".group-image-tooltip").remove();
}
function TooltipSetPosition(){
  $(".group-image-tooltip").css({'top':MouseY+'px','left':+MouseX+3+'px'});
}

function NasiPartneri() {

}
function FancyBoxString(currentIndex,currentArray,title){
  return '<span id="fancybox-title-over"><i>fotografie ' +  currentIndex + ' / ' + currentArray + '</i>&nbsp;&nbsp;-&nbsp;&nbsp;<b>' + title + '</b></span>';
}
function HideAktualitaPrezentace(){
  $("#aktualita-prezentace").slideUp('slow',function(){
    $("#aktualita-prezentace-show-again").slideDown('medium')
  });
}
