$(document).ready(function(){
									
	// Removes SEO text in navItems
	$(".seoText").html("");
	$(".seoText").removeClass("seoText");
	
	// Clears input fields on Focus
	$(".clearField").one("focus", function() {
		$(this).val("");
	});
});

/**** PRODUCT GALLERY ****/
var galleryWidth = 580;
var gallerySpeed = 800;
var gallerySliding = false;

$(document).ready(function(){
	initGallery();
	//setGallery();

	// IMAGE SWITCH
	
	$('#controlNext').click(function() {
		if (!gallerySliding) {
			gallerySliding = true;

			// set Next
			$('#productGallery li.active').next().addClass('next-active');
			if ($('#productGallery li.next-active').length < 1 ) {
				$('#productGallery li:first').addClass('next-active');
			}
			$('#productGallery li.next-active').queue( [ ] ).stop();
			
			// move Active
			$('#productGallery li.active').animate({'left' : '-'+galleryWidth+'px'}, gallerySpeed, function() {
				$('#productGallery li.active').removeClass('active');
			});		
	
			// move Next
			$('#productGallery li.next-active').css('left',galleryWidth+'px');			
			//$('#productGallery li.active').next().removeClass('hidden');
			$('#productGallery li.next-active').animate({'left':'0px'}, gallerySpeed, function() {
				$('#productGallery li.next-active').addClass('active');
				$('#productGallery li.next-active').removeClass('next-active');
				gallerySliding = false;
			});
		};
	});
	
	$('#controlPrev').click(function() {
		if (!gallerySliding) {
			gallerySliding = true;

			// set Next
			$('#productGallery li.active').prev().addClass('next-active');
			if ($('#productGallery li.next-active').length < 1 ) {
				$('#productGallery li:last').addClass('next-active');
			}
			$('#productGallery li.next-active').queue( [ ] ).stop();
			
			// move Active
			$('#productGallery li.active').animate({'left' : galleryWidth+'px'}, gallerySpeed, function() {
				$('#productGallery li.active').removeClass('active');
			});		
	
			// move Next
			$('#productGallery li.next-active').css('left','-'+galleryWidth+'px');				
			//$('#productGallery li.active').next().removeClass('hidden');		
			$('#productGallery li.next-active').animate({'left':'0px'}, gallerySpeed, function() {
				$('#productGallery li.next-active').addClass('active');
				$('#productGallery li.next-active').removeClass('next-active');
				gallerySliding = false;
			});
		};
	});
	
	// CONTROLS HOVER
	$('div#galleryControls a#controlPrev').hover(
		function() {
			$(this).stop().animate({opacity: 1},200);	
		},
		function() {
			$(this).stop().animate({opacity: 0},200);	
		}
	);
	
});

function initGallery() {
	$('div#productGallery li').css('left',galleryWidth+'px');
	$('div#productGallery li:first').addClass('active');
	$('div#productGallery li:first').css('left','0px');
	
	// Controls
	$('div#galleryControls a#controlPrev').css("opacity",0);
	$('div#galleryControls a').css("display","block");
};


/**** PRODUCT LIST ****/
var productThumbWidth = 136;
var productThumbActive;
var productListSpeed = 500;
var productListSliding = false;
var maxWidth = productThumbWidth*6;

var groupPosition;
var groupActive;

$(document).ready(function(){
	initProductList();

	$('div.catalogueGroup a.groupNext').click(function() {
		var groupWidth = (groupActive.find('ul').children().length)*productThumbWidth;
		
		if (!productListSliding && (productThumbActive*productThumbWidth) < parseInt(groupWidth)-maxWidth) {
			productListSliding = true;

			// get Stop Position
			productThumbActive = productThumbActive + 1;
			groupPosition = productThumbActive*productThumbWidth;

			// move Forward
			groupActive.find('ul').animate({'left':'-'+(groupPosition)+'px'}, productListSpeed, function() {
				productListSliding = false;
			});
		};
	});
	
	$('div.catalogueGroup a.groupPrev').click(function() {
		var groupWidth = (groupActive.find('ul').children().length)*productThumbWidth;
		
		if (!productListSliding && (productThumbActive*productThumbWidth) > 0) {
			productListSliding = true;

			// get Stop Position
			productThumbActive = productThumbActive - 1;
			groupPosition = productThumbActive*productThumbWidth;
	
			// move Back
			groupActive.find('ul').animate({'left':'-'+(groupPosition)+'px'}, productListSpeed, function() {
				productListSliding = false;
			});
		};
	});
	
	$('div#catalogueTabs li').click(function() {
		// clear All
		$('div#catalogueTabs li').removeAttr('class');
		// activate This
		$(this).addClass('active');
		// set active Group
		var activeID = $(this).attr('id');
		groupActive = $('#'+activeID+'-group');
		$('div.catalogueGroup').addClass('hidden');
		groupActive.removeClass('hidden');
		// reset position
		productThumbActive = 0;
		groupActive.find('ul').css({'left':'0px'});
	});
	
});

function initProductList() {
	$('div.catalogueGroup').addClass('hidden');
	groupActive = $('.catalogueGroup.active');
	if (groupActive.length == 0) {
		groupActive = $('div.catalogueGroup:first');
	}
	groupActive.removeClass('hidden');
	
	if ($('div#catalogueTabs li.active').length == 0) {
		$('div#catalogueTabs li:first').addClass('active');
	}
	
	$('div.groupItems ul').css('left','0px');
	productThumbActive = 0;
	
};

/**** FOOTER HOVERS ****/
var activeBubble;
var bubblePosition;
var bubbleText;
var arrowPosStart;
var arrowWidth = 42;

$(document).ready(function(){
	arrowPosStart = $('div.socialBubble img').css('padding-left');
	arrowPosStart = parseInt(arrowPosStart.substring(0,(arrowPosStart.length)-2));
	$('div.socialBubble').css({'opacity':0,'top':'-20px'});

	$('div#socialLinks a').hover(
		function() {
			// Find & Set
			activeBubble = $(this).attr("rel").substring(7,($(this).attr("rel").length)-1);
			$('div.socialBubble').css({'opacity':0,'top':'-15px'});
			// Position
			bubblePosition = (parseInt(activeBubble)-1)*arrowWidth+arrowPosStart;
			$('div.socialBubble img').css('padding-left',bubblePosition+'px');
			// Text
			bubbleText = $(this).attr("name");
			$('div.socialBubble p').html(bubbleText);
			// Animate
			$('div.socialBubble').stop().animate({
				opacity: 1,
				top: '-30px'
			}, 300 );
		},
		function() {
			$('div.socialBubble').stop().animate({
				opacity: 0,
				top: '-15px'
			}, 300 );
		}
	);
});

