$(function() {

	//TABS
	var tabs = $('.descTabsContent .tab');
	var links = $('.descTabs a');
	
	tabs.hide();
	tabs.eq(0).show();
	links.eq(0).addClass('current');
	
	links.click(function() {
	
		var target = $(this).attr('href');
		tabs.hide();
		links.removeClass('current');
		$(target).show();
		$(this).addClass('current');
		
		return false;
	
	});
	
	//GALLERY
	var imgBox = $('.zoomImg');
	
	imgBox.bind('mouseover',zoomDrag);
	imgBox.bind('mouseout',unZoomDrag);
	
	var zoomOutX = 550;
	var zoomOutY = 510;
	
	function zoomDrag() {		
		imgBox.find('img').stop().animate({
			width: zoomOutX*2,
			height: zoomOutY*2,
			left:-zoomOutX/2,
			top:-zoomOutY/2
		},'fast', function() {
			var path = $(this).attr('src').replace('normal', 'zoom');
			$(this).attr('src', path);
			imgBox.bind('mousemove',moveImg);
		});
	}
	
	function moveImg(e) {
		var offset = $(this).offset();
	
		var mouseX = e.pageX - offset.left;
		var mouseY = e.pageY - offset.top;
		
		$(this).find('img').css({
			left:-mouseX,
			top:-mouseY
		});		
	}
	
	function unZoomDrag() {

		imgBox.find('img').stop().animate({
			width: zoomOutX,
			height: zoomOutY,
			left:0,
			top:0
		},'fast', function() {
			var path = $(this).attr('src').replace('zoom', 'normal');
			$(this).attr('src', path);
		});
		imgBox.unbind('mousemove');
	}
	
	if ($('.colorSelector a').length)
	{
		var existingColor = $('.colorSelector a').eq(0).attr('href').replace('#','');
		
		$('.colorSelector a').click(function() {
			
			var newColor = $(this).attr('href').replace('#','');
			var newImagePath = imgBox.find('img').attr('src').replace(existingColor,newColor);
			imgBox.find('img').attr('src', newImagePath);
			
			var newLightboxPath = $('.productImg a.lightbox').attr('href').replace(existingColor,newColor);
			$('.productImg a.lightbox').attr('href', newLightboxPath);
			
			existingColor = newColor;
			
		});
	
	}
	
	$('a.lightbox').lightBox();
	
	
	//FIX BANNERS
	$('.boxes .box .banner').eq(0).css({display:'block'});
});
