var scrollelement=null;
var scrolltimeout;
var inanimation=false;
function scrollSlideShow(offset, direction) {
  if (scrollelement) {
    var currentleft = parseInt(scrollelement.css("left"));
    var currentwidth = parseInt(scrollelement.width());

    if (((Math.abs(currentleft) + 900) > currentwidth) && (direction == "-")) {
      return false;
    }

    if ((currentleft >= 0) && (direction == "+")) {
      scrollelement
        .css("left", "0px");

      return false;
    }

    if (!inanimation) {
      inanimation = true;

      scrollelement
        .animate({
          left: direction + '=' + offset
        }, 250, function() {
          inanimation = false;
        });
    }

    return true;
  } else {
    return false;
  }
}

function scrollSlideShowLeft() {
  if (scrollSlideShow(200, '+')) {
    scrolltimeout = setTimeout(scrollSlideShowLeft, 500);
  }
}

function scrollSlideShowRight(offset) {
  if (scrollSlideShow(200, '-')) {
    scrolltimeout = setTimeout(scrollSlideShowRight, 500);
  }
}

jQuery(function() {
  jQuery("#tocbar li a")
    .bind("click", function() {
      jQuery("#tocbar li")
        .removeClass("currenttopic");

      jQuery(this)
        .parent()
        .addClass("currenttopic");

      jQuery("#productdetails .post-entry div")
        .fadeOut()
        .find("h2" + jQuery(this).attr("href") )
        .parent()
        .fadeIn();
      
      return false;
    });

  jQuery("#tocbar li a:first")
    .trigger("click");

  jQuery(".samples-slideshow-scrollleft")
    .bind("click mouseleave", function() {
      if (scrolltimeout) {
        clearTimeout(scrolltimeout);
      }
      scrollelement = null;
    
      return false;
    })
    .bind("mousedown", function() {
      scrollelement = jQuery(this)
        .parent()
        .find(".samples-slideshow-images ul")

      scrollSlideShowLeft();
    })
    .bind("mouseup", function() {
      scrollelement = null;
    });

  jQuery(".samples-slideshow-scrollright")
    .bind("click mouseleave", function() {
      if (scrolltimeout) {
        clearTimeout(scrolltimeout);
      }
      scrollelement = null;
    
      return false;
    })
    .bind("mousedown", function() {
      scrollelement = jQuery(this)
        .parent()
        .find(".samples-slideshow-images ul")

      scrollSlideShowRight();
    })
    .bind("mouseup", function() {
      scrollelement = null;
    });

  var sumwidth = 0;
  jQuery(".samples-slideshow-images img")
    .each(function() {
      sumwidth += jQuery(this).width() + 20;
    });

  jQuery(".samples-slideshow-images ul")
    .width(sumwidth);

  jQuery(".photobooktypes li a")
    .bind("click", function() {
      jQuery("#photobook_hardcover,#photobook_hardcovercameo,#photobook_digitalcover")
        .hide();

      jQuery(".photobooktypes li")
        .removeClass("currenttab");

      var jqthis = jQuery(this);
      jQuery(jqthis.attr("href"))
        .show();
      jqthis
        .parent()
        .addClass("currenttab");

      return false;
    });
});

var thickboxL10n = {
  next: "Következő  &gt;",
	prev: "&lt; Előző",
	image: "Kép",
	of: " - összesen: ",
	close: "Bezár"
}

