/**
 * 
 * Timelord jQuery
 * 
 */ 
(function($) {

jQuery().ready(function() {
	$('img.rollover').image_rollover();
	smooth_scroll();
	product_image();
});


/**
 * Image Rollover
 */
$.fn.image_rollover = function(imgPostfix) {
	imgPostfix = imgPostfix || '_hover'
	var $that = $(this);
	
	$that.not('[src*="'+ imgPostfix +'."]').each(function() {
		var $img = $(this);
		var src_default = $img.attr('src');
		var src_hover = src_default.substr(0, src_default.lastIndexOf('.')) + imgPostfix + src_default.substring(src_default.lastIndexOf('.'));
		$('<img>').attr('src', src_hover);
		$img.hover(
			function() {
				$img.attr('src', src_hover);
			},
			function() {
				$img.attr('src', src_default);
			}
		);
	});
	return $that;
}

/**
 * smooth scroll
 */
function smooth_scroll() {
	jQuery('a[href*=#],area[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = jQuery(this.hash);
			$target = $target.length && $target || jQuery('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				jQuery('html,body').animate({scrollTop: targetOffset}, 500);
				return false;
			}
		}
	});
}


/**
 * Product Slide
 */
function product_image() {
	$('#product-main-image div:eq(0)').addClass('current').siblings('div').hide();
	$('#product-thumbnail li').each(function(i){
		$(this).click(function(){
			if(!$('#product-main-image div').eq(i).hasClass('current')) {
				$('#product-main-image div.current').fadeOut(200).removeClass('current');
				$('#product-main-image div').eq(i).fadeIn(200).addClass('current');
			}
		});
	});
}

})(jQuery);
