$(document).ready(function(){
  // wstawiamy flash na splash
  node = document.getElementById('splashWrapper');
  if (node){
    var splash = new SWFObject("{$SYS_url}pics/flash/splash.swf", "splashSwf", "997", "375", "7", "#ffffff");
    splash.addParam("wmode","transparent");
    splash.write("splashWrapper");
  }


  // usuwamy tekst z przycisku OK
  $("#searchSubmit").attr('value', '');
  // dodajemy funkcję usuwającą text 'szukaj' po kliknięciu w pole wyszukiwarki
  //$("#searchString").attr("onfocus", "this.value = '';");
  // dodajemy akcję anulującą wysyłanie formularza wyszukiwarki gdy nie wpisano frazy
  $("#searchForm").submit( function(){ return $("input", this).val().length > 0; });
  // dodajemy :hover dla IE6
  addOver('searchSubmit');
  addOver('smSend');
  // ukrywamy wiersze z detalami w opisie produktu
  hideProductDetails();
  // kolorujemy tabelki i listy w zebrę
  tableStripe();

  // ustawiamy wyświetlanie podpowiedzi przy ikonach
  var iconHome = document.getElementById('iconHome');
  iconHome.onmouseover = function(){ $("#iconTxt").html($("#iconHome").attr('title')) };
iconHome.onmouseout  = function(){ $("#iconTxt").html('&nbsp;') };
  var iconEmail = document.getElementById('iconEmail');
  iconEmail.onmouseover = function(){ $("#iconTxt").html($("#iconEmail").attr('title')) };
  iconEmail.onmouseout  = function(){ $("#iconTxt").html('&nbsp;') };
  var iconDownload = document.getElementById('iconDownload');
  iconDownload.onmouseover = function(){ $("#iconTxt").html($("#iconDownload").attr('title')) };
  iconDownload.onmouseout  = function(){ $("#iconTxt").html('&nbsp;') };
  var iconSitemap = document.getElementById('iconSitemap');
  iconSitemap.onmouseover = function(){ $("#iconTxt").html($("#iconSitemap").attr('title')) };
  iconSitemap.onmouseout  = function(){ $("#iconTxt").html('&nbsp;') };

  // przypisujemy akcję do linków showDetails w opisie produktu
  $("#productTypes a.showAllDetails").bind("click", function(){ toggleProductDetails('all'); });
  $("#productTypes a.showDetails").click(function(){ toggleProductDetails($(this)); return false; })

  // przypisujemy akcję do linków showPhotos w opisie produktu
  $("#productTypes a.showPhotos").click(function(){ showProductPhotos($(this)); return false; })
  $("#productTypes a.shownPhotos").click(function(){ showProductPhotos($(this)); return false; })

  // przypisujemy akcję do linków more opisie akcesoriach
  $(".accesoriesItem a.more").click(function(){ showAccesoriesMore($(this)); return false; })

});

// IE fix for hover
function addOver(nodeId){
  if (document.all && document.getElementById){
    node = document.getElementById(nodeId);
    if (node){
      node.onmouseover = function(){
        this.className += " over";
      }
      node.onmouseout=function(){
        this.className=this.className.replace(" over", "");
      }
    }
  }
}

// funkcja ukrywa szczegóły produktu (gdy nie ma js pozostają widoczne)
function hideProductDetails(){
  $("#productTypes tr.subRow").toggleClass('invisible');
}

// funkcja rozwija tabelę z opisem produktu
function toggleProductDetails(item){
  // jesli rozwijamy wszystkie
  if (item == 'all'){
    if ($("#toggleAllDetails").attr("class") == "showAllDetails"){ $("#productTypes a.showDetails").each(function(){toggleProductDetails(this);}); }
    else { $("#productTypes a.hideDetails").each(function(){toggleProductDetails(this);}); }
    $("#toggleAllDetails").attr('class', function(){ if ($("#toggleAllDetails").attr('class') == 'showAllDetails'){ return 'hideAllDetails'; } else { return 'showAllDetails'; } });
  }
  // jesli rozwijamy pojedynczo
  else {
    $(item).attr('class', function(){ if ($(item).attr('class') == 'showDetails'){ return 'hideDetails'; } else { return 'showDetails'; } });
    var row = $(item).parent().parent();
    var nextRow = $(row).next();
    while($(nextRow).attr('class') == 'subRow' || $(nextRow).attr('class') == 'subRow invisible'){
      $(nextRow).filter(".subRow").toggleClass('invisible');
      nextRow = $(nextRow).next();
    }
  }
}

// funkcja pokazuje galerię zdjęć danego typu produktu
function showProductPhotos(item){

  $("a.shownPhotos").attr('class', 'showPhotos');
  $(item).attr('class', 'shownPhotos');
  $("div.galleryVisible").attr('class', 'galleryInvisible');
  var buttonId = $(item).attr('id');
  buttonId = '#productTypeGallery' + buttonId.substr(15);
  $(buttonId).attr('class', 'galleryVisible');

  scrollTo( $target ,  10 );

}

// funkcja pokazuje opis akcesoriów
function showAccesoriesMore(item){
  $(item).attr('class', function(){ if ($(item).attr('class') == 'more'){ return 'less'; } else { return 'more'; } });
  var contentId = $(item).attr('id');
  contentId = '#accesoriesContent' + contentId.substr(14);
  $(contentId).toggleClass('invisible');
}

// zebra tables in jQuery
function tableStripe(){
  // koloruj tabelę
  $("table.stripeMe tr").mouseover(function(){$(this).addClass("overColor");}).mouseout(function(){$(this).removeClass("overColor");});
  $("table.stripeMe").find("tr:not(.subRow):even").addClass("oddColor");
//  $(".stripeMe tr").mouseover(function(){$(this).addClass("overColor");}).mouseout(function(){$(this).removeClass("overColor");});
//  $(".stripeMe").find("tr:not(.subRow):even").addClass("oddColor");
  // koloruj listę
  $(".stripeMe li").mouseover(function(){$(this).addClass("overColor");}).mouseout(function(){$(this).removeClass("overColor");});
  $(".stripeMe li:nth-child(even)").addClass("oddColor");
  // koloruj tabelę z listą plików do pobrania
  $("table.files tr").mouseover(function(){$(this).addClass("overColor");}).mouseout(function(){$(this).removeClass("overColor");});
  $("table.files").find("tr:not(.subRow):even").addClass("oddColor");
}

function disable_div (item) {
    node = document.getElementById(item);
  if (node){
        node.style.display = 'none';
    }

}

//------------------------------------------------------------------------------------

