
/************************************** GENERAL */
$(document).ready(function(){
									
	// Removes SEO text in navItems
	$(".clearText").html("");
	$(".clearText").removeClass("clearText");
	
	// Clears input fields on Focus
	$(".clearField").bind("blur", function() {
		if ($(this).val()=="") {
			$(this).val($(this).attr("title"));
		};
	});
	$(".clearField").bind("focus", function() {
		if ($(this).val()==$(this).attr("title")) {
			$(this).val("");
		};
	});
});

/************************************** FUN FACT */
$(document).ready(function(){
	function initFunFact() {
		// init all
		$("#funFact #funFactDetail li").css({'position':'absolute','opacity':'0'});
		$("#funFact #funFactDetail li:last").addClass('last');
		// set first
		$("#funFact #funFactDetail li:first").addClass('active');
		$("#funFact #funFactDetail li:first").css({'opacity':'1','display':'block'});
		activeFact = $("#funFact #funFactDetail li:first");
		activeFactHeight = activeFact.height()+15;
		$("#funFact #funFactDetail ul").css({'height':activeFactHeight+'px'});
		numFacts = $("#funFactDetail ul > li").length;
		//alert(numFacts);
		if (numFacts > 0) {
			$("#funFact #funFactNext").css({'display':'block'});
		}
	};
	
	var activeFact;
	var nextFact;
	var nextFactHeight;
	var numFacts;
	initFunFact();	
	
	$("#funFact #funFactNext").click(function () {
		if (!activeFact.hasClass('last')) {
			nextFact = activeFact.next();
		} else {
			nextFact = $("#funFact #funFactDetail li:first");
		}
		nextFactHeight = nextFact.height()+15;
		activeFact
			.animate({opacity:0},"fast","",function(){
				$(this).css({'display':'none'})
			})
			.css({'z-index':'1'})
			.removeClass('active');
		$("#funFact #funFactDetail ul").animate({height:nextFactHeight})
		nextFact
			.animate({opacity:1})
			.css({'z-index':'99','display':'block'})
			.addClass('active')
		activeFact = $("#funFact #funFactDetail li.active");
		
	});
});

/************************************** PRODUCT LIST POPUP */
$(document).ready(function(){
	function initProductHover() {
		$(".hoverProductImage").css('top','5px');
		$(".hoverProductImage").css('opacity',0);
	};
	initProductHover();	
	var hoverSpeed = 200;
	
	$(".hoverProduct").hover(function() {
		//queue().stop();
		$(this).parent().parent().find(".hoverProductImage").stop().animate({
			top:"-5px",
			opacity: 1
		}, hoverSpeed );
	},function() {
		//queue().stop();
		$(this).parent().parent().find(".hoverProductImage").stop().animate({
			top:"5px",
			opacity: 0
		}, hoverSpeed );
	});
});

/************************************** OTHER PRODUCT LIST SLIDE */
$(document).ready(function(){
	var countOtherProducts;
	var countOtherProductsMax = 4;
	var sizeWidthList;
	var sizeWidthItem = 150;
	var positionLeft;
	function initOtherProducts() {
		countOtherProducts = $("div#otherProducts ul > li").length;
		sizeWidthList = countOtherProducts * sizeWidthItem;
		positionLeft = 0;
		//$("div#otherProducts img#otherProdPrev").css({'display':'none'});
		if (sizeWidthList > (countOtherProductsMax*sizeWidthItem)) {
			$("div#otherProducts div.controls img#otherProdNext").css('display','block');
		}
		$("div#otherProducts .area").css({'height':'170px','overflow':'hidden'});
		$("div#otherProducts ul").css({'width':sizeWidthList+'px','position':'absolute','left':positionLeft+'px'});
	};
	initOtherProducts();	
	$("div#otherProducts img#otherProdPrev").click(function () {
		if (positionLeft != 0) {
			positionLeft = positionLeft + sizeWidthItem;
			if (positionLeft == 0) {
				$("div#otherProducts img#otherProdPrev").css({'display':'none'});
			}
			$("div#otherProducts img#otherProdNext").css({'display':'block'});
			$("div#otherProducts ul").animate({left:positionLeft+'px'});
		}
	});
	$("div#otherProducts img#otherProdNext").click(function () {
		if (positionLeft != -(sizeWidthList - (countOtherProductsMax*sizeWidthItem))) {
			positionLeft = positionLeft - sizeWidthItem;
			if (positionLeft == -(sizeWidthList - (countOtherProductsMax*sizeWidthItem))) {
				$("div#otherProducts img#otherProdNext").css({'display':'none'});
			}
			$("div#otherProducts img#otherProdPrev").css({'display':'block'});
			$("div#otherProducts ul").animate({left:positionLeft+'px'});
		}
	});
});

/************************************** PRODUCT SLIDE */
$(document).ready(function(){
  var currentPosition = 0;
  var slideWidth = 192;
  var slides = $('.slide');
  var numberOfSlides = slides.length;

  // Remove scrollbar in JS
  $('#slidesContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slides
    .wrapAll('<div id="slideInner"></div>')
    // Float left to display horizontally, readjust .slides width
	.css({
      'float' : 'left',
      'width' : slideWidth
    });

  // Set #slideInner width equal to total width of all slides
  $('#slideInner').css('width', slideWidth * numberOfSlides);

  // Insert controls in the DOM
  $('#slideshow')
    .prepend('<span class="control" id="leftControl">Clicking moves left</span>')
    .append('<span class="control" id="rightControl">Clicking moves right</span>');

  // Hide left arrow control on first load
  manageControls(currentPosition);

  // Create event listeners for .controls clicks
  $('.control')
    .bind('click', function(){
    // Determine new position
	currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
    
	// Hide / show controls
    manageControls(currentPosition);
    // Move slideInner using margin-left
    $('#slideInner').animate({
      'marginLeft' : slideWidth*(-currentPosition)
    });
  });

  // manageControls: Hides and Shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
	if(position==0){ $('#leftControl').hide() } else{ $('#leftControl').show() }
	// Hide right arrow if position is last slide
    if(position==numberOfSlides-1){ $('#rightControl').hide() } else{ $('#rightControl').show() }
  }	
});


