function show(content) 
{
	var thediv = document.getElementById(content);
	if (thediv) {
		thediv.style.display = 'block';
	}
}
function hide(content) {

	var thediv = document.getElementById(content);
	if (thediv) {
		thediv.style.display = 'none';
	}
}

/***** Product Description: Display first few chars *****/
function showMoreText() {
	show('product_all');
	hide('product_blurb');
}
function showLessText() {
	hide('product_all');
	show('product_blurb');
}
function producttextCollapse() {
	if (document.getElementById('productDescription')) {
		var product_all = document.getElementById('productDescription').innerHTML;
	        if (product_all.length > 108) {
	        	var product_blurb = product_all.substring(0, 108);
	                var descriptionLength = product_all.length;
	                document.getElementById('productDescription').innerHTML =
				'<div id="product_blurb">' + product_blurb + '... <a href="#" onclick="showMoreText(); return false;">Show More</a></div>' +
				'<div id="product_all">' + product_all + ' <a href="#" onclick="showLessText(); return false;">Show Less</a></div>';
	        }
	 }
}
	
function InitializeVerticalCarousel(numVisible){
	var ThisCarousel = function(carouselElementID, carouselCfg) {
 		this.init(carouselElementID, carouselCfg);
	};

	ThisCarousel .prototype = {
		   init: function(id, cfg) {
		      var config = {
						numVisible:        numVisible,
					animationSpeed:    0.15,
						scrollInc:         numVisible,
					navMargin:         0, /* DEFAULT: 20 */
					size:              100, /* DEFAULT: 8 */
			 prevButtonStateHandler: this.handlePrevButtonState,
			 nextButtonStateHandler: this.handleNextButtonState
		      };

		      for (var key in cfg) {
			 if (!cfg.hasOwnProperty(key)) { continue; }
			 config[key] = cfg[key];
		      }

		      this.carousel = new YAHOO.extension.Carousel(id, config);

		   },

		   handlePrevButtonState: function(type, args) {
				var enabling = args[0];
				var leftImage = args[1];
				if(enabling) {
						leftImage.src = "/content/global/img/scrolltop-active_green.gif";	
						leftImage.style.cursor="pointer";
				} else {
						leftImage.src = "/content/global/img/scrollup-inactive.gif";	
						leftImage.style.cursor="default";
				}
		   },

		   handleNextButtonState: function(type, args) {
				var enabling = args[0];
				var rightImage = args[1];

				if(enabling) {

							rightImage.src = "/content/global/img/scrolldown-active_green.gif";

							rightImage.style.cursor="pointer";

				} else {

							rightImage.src = "/content/global/img/scrolldown-inactive.gif";

							rightImage.style.cursor="default";

				}
			},

			calculateSize: function() {
				this.carousel.calculateSize();
			}
	};
	return ThisCarousel;
}

function InitializeHorizontalCarousel(numVisible, leftActive, leftInactive, rightActive, rightInactive)
{
	var ThisCarousel = function(carouselElementID, carouselCfg) {
	 		this.init(carouselElementID, carouselCfg);
	};

	ThisCarousel.prototype = {
	   init: function(id, cfg) {
	      var config = {
				numVisible:        numVisible,
				animationSpeed:    0.15,
				scrollInc:         numVisible,
				navMargin:         0, /* DEFAULT: 20 */
				size:              100, /* DEFAULT: 8 */
	         prevButtonStateHandler: this.handlePrevButtonState,
	         nextButtonStateHandler: this.handleNextButtonState
	      };
	
	      for (var key in cfg) {
	         if (!cfg.hasOwnProperty(key)) { continue; }
	         config[key] = cfg[key];
	      }
	
	      this.carousel = new YAHOO.extension.Carousel(id, config);
	
	   },
	
	   handlePrevButtonState: function(type, args) {
			var enabling = args[0];
			var leftImage = args[1];
			if(enabling) {
				leftImage.src = leftActive;
				leftImage.style.cursor="pointer";	
			} else {
				leftImage.src = leftInactive;	
				leftImage.style.cursor="default";
			}
	   },
	
	   handleNextButtonState: function(type, args) {
			var enabling = args[0];
			var rightImage = args[1];
	
			if(enabling) {
				rightImage.src = rightActive;
				rightImage.style.cursor="pointer";
			} else {
				rightImage.src = rightInactive;
				rightImage.style.cursor="default";
			}
		},
		
		calculateSize: function() {
			this.carousel.calculateSize();
	    }
	};
	return ThisCarousel;
}

function swapCarouselImgForProduct(divID,bgUrl)
{

	var divElem = document.getElementById(divID);
	if (divElem)
	{
		divElem.style.backgroundImage = "url('" + bgUrl + "')";
		divElem.style.width=99;
	}
}
function swapCarouselImgForDesign(divID,bgUrl)
{

	var divElem = document.getElementById(divID);
	if (divElem)
	{
		divElem.style.backgroundImage = "url('" + bgUrl + "')";
		divElem.style.width=125;
	}
}

function eraseHistory()
{
	eraseCookie("CP_PRODUCT_HISTORY");
	doWork();

}

function disableHistory()
{
	createCookie("CP_DISABLE_PRODUCT_HISTORY","true",1000);
	doWork();

}

function doWork() {

    document.getElementById('prodHistory').style.display='none';
   
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/" + "; domain=" + window.cafepress.domain;
}