﻿// for individual collection pages
function swapMainCollectionImage(argThumbID) {
	$("#collectionMainImg").attr("src", $('img#'+ argThumbID).attr("src"));
}

// for product detail tabs
//var currentProdTabName = "Downloads";
//var currentImageTabID = "pdImagesTabColors";
//var currentImageID = "1";

function swapTabClass(argTabId) 
{
	if(obj = document.getElementById(argTabId))
	{
		if (obj.className.indexOf("pdTabSelected") != -1) {
			obj.className = obj.className.replace("pdTabSelected", "pdTabDeSelected");
		} else {
			obj.className = obj.className.replace("pdTabDeSelected", "pdTabSelected");
		}
	}
}

function toggleTab(argTabID, argTabContentID) {
	if (argTabID != currentProdTabID) {
		swapTabClass(currentProdTabID);
		swapTabClass(argTabID);
		hide(currentProdTabContentID);
		show(argTabContentID);
		currentProdTabID = argTabID;
		currentProdTabContentID = argTabContentID;

		var loc = window.location.href;
		if (loc.indexOf('#') > -1) { loc = loc.substring(0, loc.indexOf('#')); }
		loc = loc + "#" + argTabID;
		window.location = loc;
	}
}

function pdImagesTabShow(argImageID, argTabID) {
	if (argTabID != currentImageTabID) {
		// switch tabs look
		if (argTabID == "pdImagesTabColors") {
			show("pdImagesTabColorLimg");
			document.getElementById("pdImagesTabImagesInner").className = "pdImagesTabInnerOff";
			document.getElementById("pdImagesTabImages").className = "";
			document.getElementById("pdImagesTabImagesB").className = "";
			document.getElementById("pdImagesTabColorBL").className = "";
			document.getElementById("pdImagesTabColors").className = "";
			document.getElementById("pdImagesTabBM").className = "";
			document.getElementById("pdImagesTabColorsB").className = "";
			document.getElementById("pdImagesTabColorsInner").className = "pdImagesTabInnerOn";
		} else {
			hide("pdImagesTabColorLimg"); 
			document.getElementById("pdImagesTabColorBL").className = "off";
			document.getElementById("pdImagesTabColors").className = "off";
			document.getElementById("pdImagesTabBM").className = "off";
			document.getElementById("pdImagesTabColorsB").className = "off";
			document.getElementById("pdImagesTabColorsInner").className = "pdImagesTabInnerOff";
			document.getElementById("pdImagesTabImages").className = "on";
			document.getElementById("pdImagesTabImagesB").className = "on";
			document.getElementById("pdImagesTabImagesInner").className = "pdImagesTabInnerOn";
		}
		
		currentImageTabID = argTabID;
	}
	
	// hides the current main image
	hide("pdImageMain" + currentImageID);
	
	// shows the passed main image
	//show("pdImageMain" + argImageID);
	$("#pdImageMain" + argImageID).fadeIn("fast");
	
	// turns off the current thumbnail
	document.getElementById("pdImageThumb" + currentImageID).className = " ";
	
	// turns on the passed thumbnail
	document.getElementById("pdImageThumb" + argImageID).className = "pdSelectedImg";
	
	currentImageID = argImageID;
}

if ($.browser.msie && (parseInt($.browser.version) < 7)) {
	$(document).ready(function(){
		$("div.zoomIcon img").css('display', 'block');
		$("div.zoomIcon img").attr("src","/assets/images/products/zoomIcon.gif");
	});
}


function ContentViewableSlider($, undefined)
{
	var minHeight = 0;
	var maxHeight = 0;
	var currentHeight = 0;
	var duration = "";

	var moreLabel = "view more";
	var lessLabel = "view less";

	var $container = null;
	var $trigger = null;
	var pub =
	{
		ShowMore: function ()
		{
			$container.animate
			(
				{ height: maxHeight + 'px' }
				, duration
				, function () { setCurrentHeight(); }
			);
		}, ShowLess: function ()
		{
			$container.animate
			(
				{ height: minHeight + 'px' }
				, duration
				, function () { setCurrentHeight(); }
			);
		}, ToggleShow: function ()
		{
			if (currentHeight == minHeight || (currentHeight > minHeight && currentHeight < maxHeight))
			{
				pub.ShowMore();
			}
			else if (currentHeight >= maxHeight)
			{
				pub.ShowLess();
			}
		}, TriggerClick: function ()
		{
			var type = "toggle";
			if (arguments.length > 1)
			{
				type = arguments[1];
			}
			if (!type) { type = "toggle"; }

			if (type.toLowerCase() == "more")
			{
				pub.ShowMore();
			}
			else if (type.toLowerCase() == "less")
			{
				pub.ShowLess();
			}
			else
			{
				pub.ToggleShow();
			}
		}
		, Setup: function (contentContainerId, contentTriggerId, triggerTagName, transitionSpeed)
		{
			if (document.getElementById(contentContainerId) && document.getElementById(contentTriggerId))
			{
				$container = $('#' + contentContainerId);
				var contentDiv = $('#' + contentContainerId + ' div')[0];
				$trigger = $(document.getElementById(contentTriggerId).getElementsByTagName(triggerTagName)[0]);

				$trigger.click(function () { pub.ToggleShow(); });

				minHeight = $container.height();
				maxHeight = contentDiv.scrollHeight;

				//This is screwy because we want to store the 'actual' height of the element (minus padding, etc) so we can return to the origial render size of the element.
				//But the max height has to be the full 'realized' height in order to expand to display all hidden text, when present.
				if (maxHeight > 312) //312 is container.height + padd.top + padd.bottom (282 + 15 + 15) and shouldn't be hardcoded...
				{
					$('#' + contentTriggerId).show();

					setCurrentHeight();

					duration = transitionSpeed;
					if (!duration) { duration = "fast"; }
				}
			}
		}
	}


	function totalHeight($container)
	{
		var scrollHeight = $container.height();
		scrollHeight += ValueToInt($container.css("padding-top"), 10) + ValueToInt($container.css("padding-bottom"), 10);
		scrollHeight += ValueToInt($container.css("margin-top"), 10) + ValueToInt($container.css("margin-bottom"), 10);
		scrollHeight += ValueToInt($container.css("borderTopWidth"), 10) + ValueToInt($container.css("borderBottomWidth"), 10);
		return scrollHeight;
	}

	function setCurrentHeight()
	{
		currentHeight = $container.height();

		$trigger.html((currentHeight < maxHeight ? moreLabel : lessLabel ));
	}

	return pub;
}
