                                                                                                                                                                                                                                                                                                                                                        
var thumbsPerPage = 4;
var totalThumbs = 0;
var thumbWidth = 170;
var currentThumb = 0;
var animSpeed	= 300;
var thedatenum = 'all';

function setPressYear(oDateNum){
	thedatenum = oDateNum;
	filterPressItems();
}
function filterPressItems(){
	$("#navList li").each(function(){
		var myRel = "";
		myRel = $(this).attr("rel");
		if(thedatenum != 'all'){
			if(myRel != thedatenum){
				$(this).fadeOut(1000, function () {
					$(this).hide();
				 });
			} else {
				$(this).show(function () {
					$(this).fadeIn(1000);
				 });
			}
		} else {
			$(this).show(function () {
				$(this).fadeIn(1000);
			 });
		}
	});
	
	resetScroll();
	checkNavArrows();
}

function initScrollPosition() {
	var distance = thumbWidth * (currentThumb) ;
	$('#navList').css('left', "-" + distance + "px");
}			
function getTotalThumbs(){
	var returncount = 0;
	$("#navList li").each(function(){
		var theDisplay = $(this).css('display');
		if(theDisplay != 'none'){returncount++;}
	});
	return returncount;
}
function currentBottomProject() {
	return currentThumb + thumbsPerPage;
}

function checkNavArrows() {
	if (canScrollLeft()) {
		$('.leftControl a').css({ color: "#ffffff",
		cursor: "pointer" });	
	}
	else {	
		$('.leftControl a').css({ color: "#cccccc",
		cursor: "default" });		
	}

	if (canScrollRight()) {
		$('.rightControl a').css({ color: "#ffffff",
		cursor: "pointer" });		
	}
	else {
		$('.rightControl a').css({ color: "#cccccc",
		cursor: "default" });		
	}
}	

function canScrollRight() {
	return (currentThumb > 0);
}			

function canScrollLeft() {
	return (currentBottomProject() < getTotalThumbs());
}			

function resetScroll(){
	$("#navList").animate({
		top: 0,
		left: 0
	}, animSpeed );
	currentThumb = 0;
	checkNavArrows();
}
function scrollRight() {
	var distance = thumbWidth * (currentThumb + 1);

	$("#navList").animate({
		top: 0,
		left: -distance
	}, animSpeed );

	currentThumb += 1;
	checkNavArrows();
}			

function scrollLeft() {
	var distance = thumbWidth * (currentThumb - 1);

	$("#navList").animate({ 
		top: 0,
		left: -distance
	}, animSpeed );

	currentThumb -= 1;					
	checkNavArrows();
}
function removeTheSpaces(string) {
	return string.split(' ').join('');
}
var currentImgType = "";

function showASCPrimerNeeded(){
	var thepaints = ["Audacious","Bamboozled","Bang!","Bonana","BourbonStreet","CanadianFlag","Cayenne","Chargreen","Chutney","CurtainCall","Daffodil","Diva","Fandango","Fetish","Fez","Fireball","Firefly","Infrared","Kismet","Lavish","Leapfrog","LipService","LoveatFirstBite","Madagascar","MataHari","Merlot","Moby Dick","Mojo","Molten","Orleans","Paprika","Persimmon","Raku","Stampede","Tamarind","Tango","Temptation","Torch","VenusEnvy","Vixen"];
	
	var oPaint = $("#colors option:selected").text().split(' ').join('');
	var showDiv = false;
	for(var i=0;i<thepaints.length;i++){
		var thepaint = thepaints[i];
		if(thepaint.indexOf(oPaint) > -1){
			showDiv = true;
			break;
		}
	}
	if(showDiv){
		$("#ascprimerneeded").fadeIn(300);
	} else {
		$("#ascprimerneeded").fadeOut(300);
	}
}

function switchSheenText(){
	
	var oType = $("#sheen option:selected").text();
	
	var oSpecSheet = "";
	var oMSDSSheet = "";
	
	var aSpecSheets = specsheets.split(',');
	var sMSDSSheets = msdssheets.split(',');
	
	for(var i=0;i<aSpecSheets.length;i++){
		var thename = aSpecSheets[i];
		
		if(thename.indexOf(oType) > -1){
			oSpecSheet = aSpecSheets[i];
			break;
		}
	}

	if(sMSDSSheets.length > 1){
		for(var i=0;i<sMSDSSheets.length;i++){
			var theMSDSname = sMSDSSheets[i];

			if(theMSDSname.indexOf(oType) > -1){
				oMSDSSheet = sMSDSSheets[i];
				break;
			}

		}
	} else {
		oMSDSSheet = sMSDSSheets[0];

	}
	
	$('.specsheet').attr("href","/" + oSpecSheet);
	$('.msdssheet').attr("href","/" + oMSDSSheet);
	$('.specs a').each(function(){
		$(this).attr("href",$(this).attr("href").split(",").join(""));
	});
	
	if(currentImgType == ""){
		currentImgType = oType;
		
	} else {
		$('.productimage img').fadeOut(300, function() {
			newImg = $('.productimage img').attr('src');
			oImg = newImg.replace(currentImgType, oType);
			currentImgType = oType;
			$('#loader').show();
			$('.productimage img').attr("src", oImg).css({ margin: "0 0 0 -9999px" }).show(function() {
				$('#loader').hide();
				$('.productimage img').css({ margin: "0", display: "none" }).fadeIn(250);
			});
		});
	}
}

$(document).ready(function() {
	$('.subGiftCertificates').css('padding-left','62px');
	$("a.zoom").fancybox({
		'overlayOpacity' : 0.7,
		'overlayColor' : '#123'
	});
	var theQTY = $(".skuQty").text();
	//alert(theQTY);
	if(theQTY == "" || theQTY == undefined || theQTY == null){
		$(".skuQty").val("1");
	}
	$("#featureditems li").each(function(i){
		$(this).click(function(){
			location.href = $("#featureditems li:eq("+i+") a:first").attr("href");
		});
	});
	$("#quicklinks li").not('.nolink').mouseover(function(){
		$(this).addClass('selected');
	});
	$("#quicklinks li").not('.nolink').mouseout(function(){
		$(this).removeClass('selected');
	});
	$("#quicklinks li").each(function(i){
		var urlName = $("#quicklinks li:eq("+i+") a:first").attr("href");
		if(urlName != "" && urlName != undefined){
			$(this).click(function(){
				location.href = urlName;
			});
		}
	});
	
	$("#couldformats p").each(function(){
		$(this).css("opacity", "0");
		$(this).css("z-index", "-1");
		$(this).hide();
	});
	
	$("#subNav li a").each(function(i){
		var theclass = removeSpaces(this.className);
		if(theclass!="viewcart")
		this.className = 'sub'+theclass;
	});
	$(".subGlossary").attr("href","Glossary?Letter=A");

	$(".navcolumn li a").each(function(){
		$(this).attr("href",replaceSpaces($(this).attr("href")));
	});
	$("#products_grid a").each(function(){
		$(this).attr("href",replaceSpaces($(this).attr("href")));
	});
	
	$("#ulFAQs div a").each(function(){
		var thehref = $(this).attr("href");
		
		if(thehref.indexOf("colorichicago.com") > -1){
			//do nothing
		} else if(thehref.indexOf("www.") > -1){
			//$(this).attr("href",$(this).attr("href")+"\" target=\"_blank");
			$(this).attr("target","_blank");
		}
	});
	
	$("#thoughtsFilter a").each(function(){
		$(this).attr("href",replaceSpaces($(this).attr("href")));
		$(this).html("<strong>" + addBoldTag($(this).html()));
	});
	
	function addBoldTag(string){
		return string.split(' ').join('</strong> ');
	}
	function removeSpaces(string) {
		return string.split(' ').join('');
	}
	function replaceSpaces(string) {
		return string.split(' ').join('+');
	}
	$('#ulFAQs').accordion({ 
		autoHeight: false,
		header: "span"
	});

	$('#sheentypes').accordion({ 
			autoHeight: false 
	});
	



	var thecount = 0;
	var column1text = "";
	var column2text = "";
	
	$("#ourspace li").each(function(){
		var theText = $(this).html();
		if((thecount%2) == 0){
			column1text += "<li>" + theText + "</li>";
		} else {
			column2text += "<li>" + theText + "</li>";
		}
		thecount ++;
	});
	$("#ourspacecontent").html("<ul class=\"column\">"+column1text+"</ul><ul class=\"column\">"+column2text+"</ul>");
	
	/************************	GLOSSARY		*************************/
	var theglossarycount = 0;
	var glossarycolumn1text = "";
	var glossarycolumn2text = "";
	
	$("#ulGlossary li").each(function(){
		var theText = $(this).html();
		if((theglossarycount%2) == 0){
			glossarycolumn1text += "<li>" + theText + "</li>";
		} else {
			glossarycolumn2text += "<li>" + theText + "</li>";
		}
		theglossarycount ++;
	});
	$("#glossarycontent").html("<ul class=\"column\">"+glossarycolumn1text+"</ul><ul class=\"column\">"+glossarycolumn2text+"</ul>");
	
	

	$('#mainNav li a').each(function(i){
		$(this).removeClass('selected');
	});
	
	$("#couldformats span").each(function(){
		this.id = removeSpaces(this.id);
	});
	$("#couldformats a").each(function(){
		this.id = removeSpaces(this.id);
	});
	$("#couldformats p").each(function(){
		this.id = removeSpaces(this.id);
	});
	
	var count = 1000;
	$("#couldformats a").click(function(){
		$("#couldformats p").each(function(){
			var thestyle = $(this).css("opacity");
			if(thestyle == "1"){
				$(this).animate({ opacity: 0}, 500 );
				$(this).css("z-index", "-1");
				$(this).hide();
			}
		});
		var theDiv = this.id;
		$("#p"+this.id).show();
		$("#p"+this.id).css("z-index", count);
		$("#p"+this.id).animate({ opacity: 1}, 500 );
		count++;
	});
	
	
	$('#homeText').innerfade({
		speed: 'slow', 
		timeout: 4000, 
		type: 'sequence', 
		containerheight: '130px' 
	});
	$('#ourspacelist').innerfade({
		speed: 'slow', 
		timeout: 4000, 
		type: 'sequence', 
		containerheight: '479px' 
	});
	$('#professionalsTestimonials').innerfade({
		speed: 'slow', 
		timeout: 6000, 
		type: 'sequence', 

		containerheight: '324px' 
	});
	
	$('#alphabet a:first').css({ padding: "5px 10px 5px 0px" });
	$('#subNav li a').eq(1).css({ padding: "0px 16px 0px 24px" });
	$("#subNav li:last a").css({ border: "none" });

	$('#navList li a.aContainer').click(function() {
		
		if($(this).hasClass('selected')) {} else {
			$('#loading').show();
			newImgList = $(this).attr('galleryImages');
			newColorNameList = $(this).attr('swatchNames');
			newSwatchTitleList = $(this).attr('swatchTitle');
			newSwatchHexList = $(this).attr('swatchHex');
			newCreditText = $(this).attr('gallerycredit');
			
			
			$('#navList li a.selected').removeClass('selected');
			$(this).addClass('selected');
			
			$('#galleryswatches').fadeOut(300);
			$('#galleryCredit').fadeOut(300);
			$('#galleryPhotos').fadeOut(300, function(){
				var newImageArray = newImgList.split(',');
				var swatchNamesArray = newColorNameList.split(', ');
				var swatchTitlesArray = newSwatchTitleList.split(',');
				var newSwatchHexArray = newSwatchHexList.split(',');
				
				var newGalleryImages = '';
				for(var i=0;i<newImageArray.length - 1;i++){
					newGalleryImages += "<img src='/"+newImageArray[i]+"' />";
				}
				$("#galleryPhotos").css({'background': ""+newSwatchHexArray[0]+"" });
				//newGalleryImages = '<span style="display:block;background:'++';">'+newGalleryImages+'</span>';
				
				var swatchesHTML = '';
				
				for(var o=0;o<3;o++){
					swatchesHTML += "<div class='swatch'>";
					swatchesHTML += "<a href='/C2+Paints/C2+LoVo?Color="+swatchNamesArray[o].split(" ").join("+")+"'><div style='background-color:"+newSwatchHexArray[o]+" ;'/><span class='hidden'>"+swatchNamesArray[o]+"</span></a>";
					swatchesHTML += "<strong>"+swatchTitlesArray[o]+"</strong>"+swatchNamesArray[o]+"";
					swatchesHTML += "</div>";
				}
				
				$('#galleryPhotos').html(newGalleryImages).css({'margin': "0 0 0 -9999px" }).show(function() {
					$('#galleryPhotos').css({ 'margin': "0px 0px 0px 10px",'height': "320", 'display': "none" }).fadeIn(250);
					$('#galleryswatches').html(swatchesHTML).fadeIn(250);
					$('#galleryCredit').html(newCreditText).fadeIn(250);
					$('#loading').hide();
				});
				$('#galleryPhotos').cycle({ 
					fx: 'fade', 
					speed: 1000, 
					timeout: 3000, 
					pause: 1
				});
			});
		}
		return false;
	});
	
	
});

    

    

    

    