$( document ).ready( function() {

	$("ul.sf-menu").superfish();

	setModPos();
	$(window).resize(setModPos);

	initCatCarousel();
	initItemCarousel();

});

function setModPos() {

	stopTopMargin = 10;
	stopLeftMargin = 100;

	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	//Set height and width to mask to fill up the whole screen
	$("#overlay").css({'width':maskWidth,'height':maskHeight});

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();

	//startToppx = ( winH / 2 ) - ( $("#productContainer").height() / 2 ) ;
	//if (startToppx < stopTopMargin) {startToppx = stopTopMargin;}

	startLeftpx = ( winW / 2 ) - ( $("#productContainer").width() / 2 ) ;
	if (startLeftpx < stopLeftMargin) {startLeftpx = stopLeftMargin;}

	//Set the popup window to center
	//$("#productContainer").css('top', startToppx);
	$("#productContainer").css('left', startLeftpx);
}

/*#### INIT CAROUSELS ####*/
function initCatCarousel () {

	jQuery('#catCarousel').jcarousel({
		scroll:1
	});

	var catCarousel = jQuery('#catCarousel').data('jcarousel');
}

function initItemCarousel () {
	jQuery('#itemCarousel').jcarousel({
		 visible:9, scroll:9, animation:2000
	});

	var itemCarousel = jQuery('#itemCarousel').data('jcarousel');
}

function loadProduct( anchorTag ) {

	var successDiv = $("#pviewPage");

	$.ajax({
		url : $(anchorTag).attr("href"),
		success : function( data ) {

			successDiv.empty();
			successDiv.html( data );

			$("#overlay").fadeIn(1000,
				function callback()
				{
  					$("#productContainer").show(2000,
	  					function callback()
						{
		  					pviewReady();
  							//initItemCarousel();
						}
  					);
				}

			);
		}
	});

	return false;
}

function showSwatch(color, image, name) {
	var background = "url('" + image + "')";

	// if color is available, use instead of the background image.
	if (color.length > 0){
		background = "#" + color;
	}

	document.getElementById('colorChoice').innerHTML = "<b>" + name + "</b>";
}

function hideSwatch() {

	document.getElementById('colorChoice').innerHTML='';

}

function showFeature(image, name) {

	document.getElementById('featureName').innerHTML = "<b>" + name + "</b>";
}

function hideFeature() {

	document.getElementById('featureName').innerHTML='';

}
function showSize(code) {

	document.getElementById('sizeChoice').innerHTML = "<b>" + code + "</b>";
}

function hideSize() {

	document.getElementById('sizeChoice').innerHTML='';

}