/* Author: Clark Pan
	http://www.redboxdigital.com.au
*/
$(document).ready(function(){
	$('.callouts').sidebarScroll({
		updateSelector : '.panel-left',
		offOpacity : .5
	});
	$('a').smoothScroll({
		offset : -20
	});
	
	if($.fancybox){
	var pattern = /stain=(.+?)$/i;
		$('.stain-list a').each(function(){
			$(this).attr('href').match(pattern);
			var id = RegExp['$1'];
			if(id){
				$(this).attr('href', '#lightbox-'+id);
				$(this).fancybox({width:600, padding:3});
				$(this).bind('click.stain-list', function(e){
					e.preventDefault();
				});
			}
		});
	}
	
	/* Product Info */
	$('.product-info').each(function(){
		var productInfo = $(this);
		$('.product-info-inner', productInfo).append('<div class="product-info-overlay"><a class="product-info-close">Close</a><div class="product-info-overlay-inner"></div></div><div class="product-info-blocker"></div>');
		$('.product-info-overlay', productInfo).hide();
		$('.product-info-blocker', productInfo).hide().css('opacity', .25).bind('click', {productInfo:productInfo}, productInfoClose);
		$('.product-info-close', productInfo).bind('click', {productInfo:productInfo}, productInfoClose);
		$('.product-info-inner li', productInfo).each(function(i, e){
			$(this).append('<div class="over"><div class="shape"></div>');
			$('.over', this).hide();
			$(this).hover(productInfoOver, productInfoOut);
			$(this).bind('click', {productInfo:productInfo, i:i}, productInfoClick);
		});
	});
	
	function productInfoOver(e){
		if(!$.browser.msie){
			$('.over', this).stop();
			$('.over', this).fadeTo(400, 1);
		} else {
			$('.over', this).show();
		}
	}
	
	function productInfoOut(e){
		if(!$.browser.msie){
			$('.over', this).stop();
			$('.over', this).fadeTo(400, 0);
		} else {
			$('.over', this).hide();
		}
	}
	
	function productInfoClick(e){
		var productInfo = e.data.productInfo;
		var i = e.data.i;
		e.preventDefault();
		if(Math.floor(i/5)){
			$('.product-info-overlay').addClass('green');
		} else {
			$('.product-info-overlay').removeClass('green');
		}
		
		$('.product-info-overlay-inner', productInfo).empty().append($('.product-info-text', this).html());
		var height = $('.product-info-overlay', productInfo).show().outerHeight();
		$('.product-info-overlay', productInfo).hide().css('top', 64 + Math.floor((445 - height)/2));
		
		
		$('.product-info-overlay', productInfo).stop().fadeTo(400, 1);
		$('.product-info-blocker', productInfo).stop().fadeTo(400, .25);
	}
	
	function productInfoClose(e){
		var productInfo = e.data.productInfo;
		e.preventDefault();
		$('.product-info-overlay', productInfo).stop().fadeTo(400, 0, function(e){$(this).hide()});
		$('.product-info-blocker', productInfo).stop().fadeTo(400, 0, function(e){$(this).hide()});
	}
	
	/* End Product Info */
	
	$('.index-hero-tc').click(function(e){
		e.preventDefault();
		window.open($(this).attr("href"), '_blank', 'directories=0,location=0,menubar=0,resizable=0,status=0,titlebar=0,toolbar=0,width=600,scrollbars=1');
	});
});
