// JavaScript Document

// jQuery calls 
$(document).ready(function(){

	// find all panel in #productInfo except the first and slideUp (if content in there).
	$('#productInfo').find('.section:gt(0)').children('.panel').slideUp(100).data('expand', false).siblings('h3').removeClass('open');
	
	if($('#productInfo').find('.section:eq(0)').hasClass('prodFeatEmpty')){
		$('#productInfo .productFeatures .panel').data('expand',false);
		$('#productInfo .productGuide').children('.panel').slideDown(100).data('expand', true).siblings('h3').addClass('open');
	}
	
	$('#productInfo h3').click(function() {  
		var panel = $(this).siblings('.panel');  
		if (panel.data('expand') == false) {  
			$('#productInfo .panel').slideUp(100).data('expand', false);
			panel.data('expand', true).slideDown(100);
			$('#productInfo h3').removeClass('open');
			$(this).addClass('open');
		}
		
	});
	
	// Declaring and calling product zoom on product detail.
	var zoomOptions = {
		zoomWidth:357,
		zoomHeight:448,
		position:'right',
		yOffset:0,
		xOffset:20,
		title:false
	}
	var zoomOptionsWide = {
		zoomWidth:357,
		zoomHeight:448,
		position:'right',
		yOffset:-93,
		xOffset:20,
		title:false
	}
	$('.productDetailVertical .jqzoom').jqzoom(zoomOptions);
	$('.productDetailWide .jqzoom').jqzoom(zoomOptionsWide);
	
	// Adding on state to colour and size select.
	$('#sizeRange .sizeItem').click(function(){
		$('#sizeRange .sizeItem').each(function(){
			$(this).removeClass('on');
		});
		$(this).addClass('on');
	});
	/* Colour selection is postback for now. */
	
	// call jcarousel if more than 2 items for wide, 4 items for normal.
	if($('.productDetailWide').length > 0){
		if($('.productDetailWide #productItems li').size() > 2){
			$('.productDetailWide #productItems').jcarousel();
		}
	}else{
		if($('#productItems li').size() > 4){
			$('#productItems').jcarousel();
		}
	}
	
	// enabling share this and print
	$('#productDetailControls .shareThis, #productDetailControls .print').show();
	
	// Share This hover on detail page
	$('#productDetailControls .shareThis').hover(function(){
		$('ul', this).show();
		$(this).addClass('shareThisOn');
	}, function(){
		$('ul', this).hide();
		$(this).removeClass('shareThisOn');
	});
	
	// closing detail cart messages
	$('#selectionAction .close').click(function(){
		$(this).parent('.message').fadeOut('fast');
	});
	
	// Rollover thumbnails on Detail pages
	$('#productImageThumbs').find('li:eq(0)').children('a').children('img').addClass('on');
	$('#productImageThumbs li').click(function(){
		$('#productImageThumbs li img').each(function(){
			$(this).removeClass('on');
		});
		$('img', this).addClass('on');
	});
	
	// homepage rollover
	$('#splitterBox .split').hover(function(){
		$('.shade', this).css({'opacity':'0.35'}).fadeIn(100);
		$('ul', this).show();
	}, function(){
		$('.shade', this).css({'opacity':'0.35'}).fadeOut(100);
		$('ul', this).hide();
	});
	
	// display rollover text with javascript
	$('#productImageThumbs p').show();
	
	// show add to cart/wishlist buttons.
	$('#selectionAction a').show();
	
});