$(document).ready(function(){
									
	// Removes SEO text in navItems
	$(".clearText").html("");
	$(".clearText").removeClass("clearText");
	
	// Clears input fields on Focus
	$(".clearField").bind("blur", function() {
		if ($(this).val()=="") {
			$(this).val($(this).attr("title"));
		};
	});
	$(".clearField").bind("focus", function() {
		if ($(this).val()==$(this).attr("title")) {
			$(this).val("");
		};
	});
});

function displayToggle(idName,effectType,allowReverse) {
	var currentDispProp = $("#" + idName).css("display");
	
	if (currentDispProp == "none") {
		if (effectType == "slide") {
			$("#" + idName).slideDown(1500);
		} else {
			$("#" + idName).fadeIn(1500);
		}
	} else {
		if (allowReverse == true) {
			if (effectType == "slide") {
				$("#" + idName).slideUp(1500);
			} else {
				$("#" + idName).fadeOut(1500);
			}
		}
	}
}

$(document).ready(function(){
/*	var $activeSub;
	$activeSub = false;*/
	$("#subNavContent").css("display","none");
	$("a#navSolutions").css("background-image","url("+rootFolder+"/images/nav_buttons/nav_solutions_sub.gif)");
	
	$("a#navSolutions").hover(
		function() {
			//$("#subNavContent").css("display","block");
			$("#subNavContent").slideDown();
			$("a#navSolutions").css("background-position","bottom");
		},
		function() {
			$("#subNavContent").stop(true,true).css("display","none");
			$("a#navSolutions").css("background-position","top");
		}
	)
	$("#subNavContent").hover(
		function() {
			$("#subNavContent").css("display","block");
			$("a#navSolutions").css("background-position","bottom");
		},
		function() {
			$("#subNavContent").css("display","none");
			$("a#navSolutions").css("background-position","top");
		}
	)

// FAQs -------
// init
$("div#faqList a.answer").prepend("<a class=\"close\">Close</a>");

$("div#faqList a.close").click(function () { 
	//$(this).next().next().slideUp(); 
	$("div.answer").slideUp(); 
	$(this).css("display","none");
});
$("div#faqList li.active h5 a").click(function () { 
	$("div#faqList div.answer").slideDown(); 
	$("div#faqList a.close").css("display","block");
});

})

function subNavToggle() {
	
}

function displayGallerySwap(picPath) {
	$("#productDetailLeft img").fadeOut(1000,function() {
  		$("#productDetailLeft").html("<img src='" + picPath + "' style='display: none;' />");
		$("#productDetailLeft img").fadeIn(1000);
	});
}


function displayHomepageListNext(intervalNumber,direction) {
	$("#ajaxHomeList").fadeOut(1000,function() {
		if (globalPageNext > globalMaxLength) {
			globalPageNext = 0;	
		}
		
  		$("#ajaxHomeList").load(rootFolder + "/ajax/loadHomeProducts.asp",{pageFrom:globalPageNext,intervalNo:intervalNumber});
		if (direction == "next") {
			globalPageNext = globalPageNext + intervalNumber;
		} else {
			globalPageNext = globalPageNext - intervalNumber;
		}

		//alert(globalPageNext)
		$("#ajaxHomeList").fadeIn(1000);
	});

}


var tO = null;
function addProductToCart(pageNo)
{
	$("#addToCartMessage").load(rootFolder + "/ajax/addProductToCart.asp",{productID:prodID,productQty:1,productColour:"-1",productSize:"-1"},
	function(data)
	{
		$("#addToCartContain").fadeIn(1000);
		$("#jqTrans").fadeTo(0, 0.80);
		
		$("#sexpoShopArea").load(rootFolder + "/ajax/getCartSummary.asp");
		// Cancel previous animations.
		if(tO != null)
			clearTimeout(tO);
		
		tO = setTimeout("$('#addToCartContain').fadeOut(1000);tO=null;", 4500);
	});
}

function addColourToProduct(varChoiceID)
{
	$("#colourOptionList > img.clickable").css({"border":"2px solid #312f2f"});
	$("#varOptID"+varChoiceID).css({"border":"2px solid #c1002c"});
	$("#productColour").val(varChoiceID);
}

	
	
//Slider Function -----------------------------
$(document).ready(function(){
	var currentPosition = 0;
	var lastPosition = currentPosition;
	var slideWidth = 220;
	var slides = $('.slide');
	var numberOfSlides = slides.length;
	var timer = null; // = setInterval( "slideSwitch()", 500 );
	timer = setTimeout("$('#rightControl').click()", 5000 );
	//slideSwitch();
	
	// Remove scrollbar in JS
	$('#slidesContainer').css('overflow', 'hidden');
	
	// Wrap all .slides with #slideInner div
	slides
		.wrapAll('<div id="slideInner"></div>')
			// Float left to display horizontally, readjust .slides width
			.css({
				'float' : 'left',
				'width' : slideWidth
		});
	
	// Set #slideInner width equal to total width of all slides
	$('#slideInner').css('width', slideWidth * numberOfSlides);
	
	// Insert controls in the DOM
	$('#controlContain')
		.prepend('<span class="control" id="leftControl">Prev</span>')
		.append('<span class="control" id="rightControl">Next</span>');
	
	// Hide left arrow control on first load
		//manageControls(currentPosition);
	
	// Create event listeners for .controls clicks
	$('.control')
		.bind('click', function(){
			// Determine new position
			lastPosition = currentPosition; /*A*/
			currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
			if (currentPosition<0) currentPosition = numberOfSlides-1;
			if (currentPosition==numberOfSlides) currentPosition = 0;
			slideSwitch();
			// Hide / show controls
			//manageControls(currentPosition);
		});
		
	function slideSwitch(){
		//alert (lastPosition);
		//alert (currentPosition);
		if (lastPosition == currentPosition) {
			currentPosition = currentPosition+1;
			//alert (currentPosition);
		}
		// Move slideInner using margin-left
		$('#slideInner').animate({
			'marginLeft' : slideWidth*(-currentPosition)
		});
		//$('#slidesContainer').addClass(currentPosition);
		//clearInterval(timer);
		if(timer != null)
			clearTimeout(timer);

		timer = setTimeout("$('#rightControl').click()", 5000 );
	}
	
	// manageControls: Hides and Shows controls depending on currentPosition
	function manageControls(position){
		// Hide left arrow if position is first slide
		if(position==0){ $('#leftControl').hide() } else{ $('#leftControl').show() }
		// Hide right arrow if position is last slide
		if(position==numberOfSlides-1) { $('#rightControl').hide() } else { $('#rightControl').show() }
	}	
});
		
