// HP Creative Studio Main Navigation
// this code needs Mootools to work properly



var cs_pagestatus = 'category';			// 'category' or 'product'
var cs_navstatus = 'open';				// 'open' or 'closed'

var cs_main_page = 0;
var cs_main_page_max = 0;
var cs_width_products = 0;
var cs_visual_products = 0;
var cs_specialproduct=0;

var cs_visual_products_width = 0;

var cs_products_virtual_length = 0;

var cs_product_remainder=0;
var cs_width_subtract=0;

function cs_setup_mainarea() {

	// ############# determine page and nav status
	cs_products = $$('*').filterByClass('csproduct');
	cs_categories = $$('*').filterByClass('cscategory');
	// ############# 3/25/2009 array of all product images
	cs_product_images=$$('*').filterByClass('csproduct').getElement('img');
    // ############# 3/31/2009 array of all category images    
	cs_product_categories=$$('*').filterByClass('cscategory').getElement('img');
	
	// ############# don't show full breadcrumb in gallery page if name of page is too long
//	if (cs_products.length > 0  &&  $('csmainbreadcrumbyellow') != null) {
//	 	if ($('csmainbreadcrumbyellow').innerHTML.length < 30) {
//			$('csmainbreadcrumbyellow').setStyle('display','inline');
//		}
//	}
	
	// ############# prune and clean object collection
	cs_itemholder = document.getElementById('cscataloginnerholder');
	if (cs_products.length > 0) {
		for (csa=0;csa<cs_products.length;csa++) {
			if (cs_products[csa].innerHTML == '') {						// remove empty products divs
				cs_itemholder.removeChild(cs_products[csa]);
			}
		}
	} else {
		for (csa=0;csa<cs_categories.length;csa++) {
			if (cs_categories[csa].innerHTML == '') {					// remove empty category divs
				cs_itemholder.removeChild(cs_categories[csa]);
			} else {
				if (cs_categories[csa].innerHTML.indexOf('http') != -1) {	// add targets to external links (categories only, since they have a mix of internal and external links)
					cs_itemlinks = $$(cs_categories[csa].getElementsByClassName('cscategoryimage')).getElementsBySelector('a');
					cs_itemlinks[0].setProperty('target', '_blank');
					cs_itemlinks = $$(cs_categories[csa].getElementsByClassName('cscategorytext')).getElementsBySelector('a');
					cs_itemlinks[0].setProperty('target', '_blank');
				}
			}
		}
	}

	// ############# re-determine number of items after removing empty divs
	cs_products = $$('*').filterByClass('csproduct');
	cs_categories = $$('*').filterByClass('cscategory');
	cs_product_images=$$('*').filterByClass('csproduct').getElement('img');
	cs_product_categories=$$('*').filterByClass('cscategory').getElement('img');
	
	// ############# initialize objects holder divs (length depends on number of objects), determine number of pages, add filter hint objects
	if (cs_products.length > 0) {										// products
		cs_visual_products_width = 785;
		// set filter display
		$('filterleftclosed').setStyle('visibility','visible');
		$('filterleftopen').setStyle('visibility','visible');
		$('csmainfilterlegend1').setStyle('visibility','visible');
		cs_products_virtual_length = cs_products.length;

		// determine presence of special image, which is the size of 6 product icons
		cs_specialproduct = $$('*').filterByClass('csspecialimage');
		if (cs_specialproduct.length > 0) {
			cs_products_virtual_length = cs_products_virtual_length + 3;
		}
		cs_pagestatus = 'product';
		cs_main_page_max = Math.floor((cs_products_virtual_length-1)/10);
		cs_visual_products = cs_products_virtual_length;
		
	} else {																	// categories
		cs_visual_products_width = 785;
		// set filter display if this is not a theme page
		if (this.location.href.indexOf('/theme') == -1 && cs_pagestatus=='product') {
			$('filterrightclosed').setStyle('visibility','visible');
			$('filterrightopen').setStyle('visibility','visible');
			$('csmainfilterlegend1').setStyle('left','625px');
			$('csmainfilterlegend1').setStyle('visibility','visible');
		}
		cs_products_virtual_length = cs_categories.length + 1;
		if (this.location.href.indexOf('/theme') != -1) {
			cs_info = '<div class="csspecialinfo"><img src="media\/images\/chrome\/mainarea\/filterexplanations_big_yellow.gif" width="140" height="120" border="0" alt=""><\/div>';
		} else {
			cs_info = '<div class="csspecialinfo"><img src="media\/images\/chrome\/mainarea\/filterexplanations_big_red.gif" width="140" height="120" border="0" alt=""><\/div>';
		}

		if (this.location.href.indexOf('/theme') != -1) {						
			cs_products_virtual_length = cs_products_virtual_length - 1;		
		}

		cs_main_page_max = Math.floor((cs_products_virtual_length-1)/10);
		cs_visual_products = cs_products_virtual_length;

	}

	// display correct "Page: "... links based on number of items
	cs_set_pagelinks();

	// ############# show arrow buttons if necessary
	if (cs_main_page_max > 0) {
		if (cs_pagestatus == 'product') {
			cs_arrow_vpos = 225;
		} else {
			cs_arrow_vpos = 220;
		}
		$('csmainarrowleftglow').setStyle('top',cs_arrow_vpos+'px');
		$('csmainarrowleftoff').setStyle('top',cs_arrow_vpos+'px');
		$('csmainarrowlefthit').setStyle('top',cs_arrow_vpos+'px');
		$('csmainarrowrightglow').setStyle('top',cs_arrow_vpos+'px');
		$('csmainarrowrightoff').setStyle('top',cs_arrow_vpos+'px');
		$('csmainarrowrightoff').setStyle('visibility','visible');
		$('csmainarrowrighthit').setStyle('top',cs_arrow_vpos+'px');
		$('csmainarrowrighthit').setStyle('visibility','visible');
	}

	// ############## 3/25/09 find visible projects to show images
	if(cs_pagestatus=='product'){
		//set two indexes - one for the top row of images visible, one for the bottom row
		var firstIndex=0;
		cs_product_remainder = cs_visual_products%10;
		if(cs_product_remainder>5){
			cs_product_remainder=5;	
		}
		var secondIndex=(Math.floor(cs_visual_products/10)*5)+(cs_product_remainder);
		//subtract 2 from second index if there's a special hero image
		if(cs_specialproduct.length>0) {
		   firstIndex=1;
		   secondIndex-=1;
		}
		loadTheImages(firstIndex,secondIndex);
		
		// display correct checkboxes
		cs_display_available_checkboxes();
	} else {
		// ################ 3/31/09 find visible categories to show images
		//set up two indexes for when we break it to two rows
		var firstIndex=0;
		cs_product_remainder = cs_visual_products%10;
		if(cs_product_remainder>5){
			cs_product_remainder=5;	
		}
		var secondIndex=(Math.floor(cs_visual_products/10)*5)+(cs_product_remainder);
	}
	
	// ############# reveal object holder with first page of objects
	if (cs_pagestatus == 'product') {									// products display
		// set initial product table
		$('cscataloginnerholder').setStyle('height','380px');
		cs_product_remainder = cs_products_virtual_length%10;
		if(cs_product_remainder>0){
			cs_width_subtract=(Math.ceil(cs_product_remainder/2)*157);	
		} else {
			cs_width_subtract=0;	
		}
		if(cs_product_remainder>5){
			cs_product_remainder=5;	
		}
		// establish width in number of products
		cs_width_products = Math.ceil(cs_products_virtual_length/2);

		if(cs_width_products*157 < 785){
			$('cscataloginnerholder').setStyle('width',785+'px');
		} else {
			$('cscataloginnerholder').setStyle('width',((cs_width_products*157)+(cs_product_remainder*157)-cs_width_subtract)+'px');
		}

		$('cscatalogouterholder').setStyle('left','66px');
		$('cscatalogouterholder').setStyle('top','77px');
		$('cscatalogouterholder').setStyle('opacity','0');
		$('cscatalogouterholder').setStyle('visibility','visible');

		// display product table
		cs_display_catalog();

        //overwrite cs_filterleftcall with querystring to accommodate
        //automatic display of selected filter when loading the page
        //rudi sugiato
       cs_filterleftcall = extract_parameter('filterleft');        
        if (cs_filterleftcall != null) {
            cs_options_fullname = '';
		    cs_options = $$('.filterleftlink a');
		    for (csa=0;csa<cs_options.length;csa++) {
			    cs_options_text = cs_options[csa].innerHTML;
				cs_options_content=(cs_options[csa]).toString();
				if (cs_options_content.indexOf(cs_filterleftcall) != -1) {
					cs_options_fullname=cs_options_text;
				}
		    }
			cs_options_finalname=cs_options_fullname.substr(2);
		    // run filter (filter code will call cs_display_catalog())
		    cs_filter_catalog(cs_filterleftcall,'left',cs_options_finalname);
        }
		//now we should check querystring for right filters too
		cs_filterright1call = extract_parameter('right1');
		cs_filterright2call = extract_parameter('right2');
		if(cs_filterright1call){
			cs_filter_catalog(cs_filterright1call,'right1','att-free');
		}
		if(cs_filterright2call){
			cs_filter_catalog(cs_filterright2call,'right2','att-useyourphotos');
		}
	} else {																		// category display
		// set initial product table
		$('cscataloginnerholder').setStyle('height','380px');
		cs_product_remainder = cs_products_virtual_length%10;
		if(cs_product_remainder>0){
			cs_width_subtract=(Math.ceil(cs_product_remainder/2)*157);	
		} else {
			cs_width_subtract=0;	
		}
		if(cs_product_remainder>5){
			cs_product_remainder=5;	
		}
		// establish width in number of products
		cs_width_products = Math.ceil(cs_products_virtual_length/2);
		if(cs_width_products*157 < 785){
			$('cscataloginnerholder').setStyle('width',785+'px');		
		} else {
			$('cscataloginnerholder').setStyle('width',((cs_width_products*157)+(cs_product_remainder*157)-cs_width_subtract)+'px');
		}
//+(Math.ceil((cs_product_remainder*157)/2)

		$('cscatalogouterholder').setStyle('left','66px');
		$('cscatalogouterholder').setStyle('top','72px');
		$('cscatalogouterholder').setStyle('opacity','0');
		$('cscatalogouterholder').setStyle('visibility','visible');

		cs_display_catalog();
	}
}


// ############# catalog reveal animation
function cs_display_catalog() {
	// display product table
	FX_catalogreveal = new Fx.Style('cscatalogouterholder', 'opacity', {
		duration: 2000,
		fps: 12,
		transition: Fx.Transitions.Cubic.easeOut
	});
	FX_catalogreveal.start(0,1);
}


// ############# populate numbered list of links to pages
function cs_set_pagelinks() {
	cslinks = '';
	//3/31/09 pagination now only goes to 5, then adds last number
	var lowerLimit=0;
	var upperLimit=0;
	var showDots=true;
	if(cs_main_page_max>4){
		if(cs_main_page!=0){
			cslinks = cslinks + '<a href="javascript:cs_main_go('+(cs_main_page-1)+')"><img src="media\/images\/chrome\/mainarea\/prevarrow_on.gif" width="5" height="8" alt="Next" border="0" \/><\/a>     ';	
		} else {
			cslinks = cslinks + '<span style="color: #666;"><img src="media\/images\/chrome\/mainarea\/prevarrow_off.gif" width="5" height="8" alt="Next" border="0" \/><\/span>     ';	
		}
		if(((cs_main_page+1)>3)&&cs_main_page_max!=5){
			cslinks += '<a href="javascript:cs_main_go(0)">1<\/a> <span class="dots">...<\/span> ';
			if((cs_main_page-2)>1){
				lowerLimit=cs_main_page-2;
			} else {
				if((cs_main_page-1)>1){
					lowerLimit=cs_main_page-1;	
				} else {
					lowerLimit=cs_main_page;	
				}
			}
		}
		if(lowerLimit+4>=cs_main_page_max){
			upperLimit=(cs_main_page_max-1);
		} else {
			upperLimit=lowerLimit+4;
		}
		if(upperLimit==(cs_main_page_max-1)){
			showDots=false;
			if(cs_main_page_max!=5){
				lowerLimit+=1;
			}
		}
		if(upperLimit-lowerLimit<4){
			if(upperLimit-lowerLimit<3){
				if(upperLimit-lowerLimit<2){
					if(upperLimit-lowerLimit<1){	
						lowerLimit-=3;		
					} else {
						lowerLimit-=2;
					}
				} else {
					lowerLimit-=1;	
				}
			}
		}
	} else {
		lowerLimit=0;
		upperLimit=cs_main_page_max;
	}
	for(csa=lowerLimit;csa<=upperLimit;csa++){
		if (csa != cs_main_page) {
			cslinkstart = '<a href="javascript:cs_main_go('+csa+')">';
			cslinkend = '<\/a>';
		} else {
			cslinkstart = '';
			cslinkend = '';
		}
		cslinks = cslinks + cslinkstart + (csa+1) + cslinkend + ' ';
	}
	if(cs_main_page_max>4){
		if(cs_main_page==cs_main_page_max){
			cslinks+=(cs_main_page_max+1);
		} else {
			if(!showDots){
				cslinks = cslinks + '<a href="javascript:cs_main_go('+cs_main_page_max+')">'+(cs_main_page_max+1)+'<\/a>';		
			} else {
				cslinks = cslinks + '<span class="dots">...<\/span><a href="javascript:cs_main_go('+cs_main_page_max+')">'+(cs_main_page_max+1)+'<\/a>';		
			}
		}
		if(cs_main_page<cs_main_page_max){
			cslinks = cslinks + '     <a href="javascript:cs_main_go('+(cs_main_page+1)+')"><img src="media\/images\/chrome\/mainarea\/nextarrow_on.gif" width="5" height="8" alt="Next" border="0" \/><\/a>';
		} else {
			cslinks = cslinks + '     <span style="color: #666"><img src="media\/images\/chrome\/mainarea\/nextarrow_off.gif" width="5" height="8" alt="Next" border="0" \/><\/span>';	
		}
	}
	if(cs_main_page_max>0) {
		$('csmainpagelinksnumbers').setHTML(cslinks);
	} else {
		$('csmainpagelinksnumbers').setHTML('');
	}
}

function loadTheImages(firstIndex,secondIndex){
	//loop through each row, set the src of the image to the class, set class to loaded
	//set up a variable w/number of images to increment, based on hero image, size of imgs etc
	//alert(firstIndex + ", " + secondIndex);
	var theIncrement=5;
	if(cs_specialproduct.length>0&&cs_main_page==0) {
		theIncrement=3;
	} else {
		theIncrement=5;	
	}
	for(var x=firstIndex;x<firstIndex+theIncrement;x++){
		if(cs_product_images[x]&&cs_product_images[x].className!=""&&cs_product_images[x].className!="imgLoaded"){
			var tempClass=cs_product_images[x].className;
			cs_product_images[x].setAttribute('src',tempClass);
			cs_product_images[x].className="imgLoaded";
		}
	}
	for(var y=secondIndex;y<secondIndex+theIncrement;y++){
		if(cs_product_images[y]&&cs_product_images[y].className!=""&&cs_product_images[y].className!="imgLoaded"){
			var tempClassY=cs_product_images[y].className;
			cs_product_images[y].setAttribute('src',tempClassY);
			cs_product_images[y].className="imgLoaded";
		}
	}	
}

// ########################## info handlers

var cs_mouseinproduct = false;
var cs_mouseininfo = false;

function attachEvents(){
	document.onmouseup=cs_close_info2;
	$$(".hoverarea").addEvents({
		'mouseover':function(){
			cs_product_rollover(this);
		},'focus':function(){
			cs_product_rollover(this);
		},'mouseout':function(){
			cs_product_rollout();
		},'blur':function(){
			cs_product_rollout();
		}
	});
	$$(".csquickinfo").addEvents({
			'mouseout':function(){
				cs_quickinfo_rollout()
			},
			'blur':function(){
				cs_quickinfo_rollout()
			}
	});
}

// ############# called from product rollover, pull meta info and display info panel
function cs_product_rollover(cs_product_object) {
	cs_product_object=cs_product_object.getParent('div');
	if(cs_product_object.getFirst('div').className!='csspecialimage'){
		//alert(cs_product_object.getFirst('a').onmousedown);
		var cslink;
		//cs_mouseinproduct = true;
		cs_offset = (window.getWidth() - 886) /2;
		//show the quickinfo box
		cs_product_object.getElements('div.csquickinfo').setStyle('display','inline');

		cs_product_object.getElements('div.csquickinfo').addEvent('click',function(){
			cs_product_click(cs_product_object);
		});
	}
}

// ############# called from click on quickinfo rollover (above function
function cs_product_click(cs_product_object){
	$('filterleftclosed').setStyle('display','none');
	$('filterleftopen').setStyle('display','none');
	$('cspopback').setStyle('display','block');
	$('cspopback').setStyle('opacity',0);
	$('cspopback').setStyle('visibility','visible');
	FX_popfilterreveal = new Fx.Style('cspopback', 'opacity', {
		duration: 2000,
		fps: 12,
		transition: Fx.Transitions.Cubic.easeOut
	});
	if (ie4) {
		popfilteropacity = 0.5;
	} else {
		popfilteropacity = 1;
	}
	FX_popfilterreveal.start(0,popfilteropacity);
	cs_mouseinproduct = true;
	csmeta = cs_product_object.getElements('div.csproductmeta');
	cslink=cs_product_object.getElements('a');
    if(csmeta&&csmeta!=null&&csmeta!=""){
		$('csproductinfo').setHTML(csmeta[0].innerHTML + '<img src="media/images/chrome/mainarea/close_btn.gif" width="14" height="14" alt="Close" id="infoclose" onmousedown="cs_close_info2();" \/><a href="'+cslink[0]+'" target="_blank"><img src="media/images/chrome/mainarea/select_btn.png" width="92" height="19" alt="Select" border="0" id="select" class="pngfix" \/><\/a>'); 
		cs_offset = (window.getWidth() - 886) /2;
	
		if (cs_product_object.getLeft() > 600+cs_offset) {						// is this the right-most info panel
			cs_offset2 = 100;
		} else {
			cs_offset2 = 0;
		}
		if($('csproductinfo').getFirst('div').getFirst('img').className!="imgLoaded"){
			var tempClass=$('csproductinfo').getFirst('div').getFirst('img').className;
			$('csproductinfo').getFirst('div').getFirst('img').setAttribute('src',tempClass);
			$('csproductinfo').getFirst('div').getFirst('img').className="imgLoaded";
		}
		$('csproductinfo').setStyle('visibility','visible');
		$('csproductinfo').setStyle('display','block');
	}	
}

// ############# called from object rollout, wait 1/2 sec and then close rollover
function cs_product_rollout() {
	cs_close_info();
}

// ############# called from 1/2 sec timer, hide rollover layers
function cs_close_info() {
	$$('.csquickinfo').setStyle('display','none');
}
function cs_close_info2(){
	$('csproductinfo').setStyle('display','none');
	$('cspopback').setStyle('visibility','hidden');
	$('cspopback').setStyle('display','none');
	$('filterleftclosed').setStyle('display','block');
}

// ############# remove flag, and set timer to close info panel
function cs_info_rollout() {
	cs_close_info();
}
function cs_quickinfo_rollout() {
	cs_close_info();
}


// ######################## arrow/slide handlers

// called from numbered page links
function cs_main_go(cspage) {
	// determine direction
	if (cspage > cs_main_page) {
		csdist = cspage - cs_main_page;
		cs_main_go_right_core(csdist);
	} else {
		csdist = cs_main_page - cspage;
		cs_main_go_left_core(csdist);
	}
}

function cs_main_go_left() {
	cs_main_go_left_core(1);
}

function cs_main_go_right() {
	cs_main_go_right_core(1);
}

function cs_main_go_left_core(csn) {
	cs_oldpos = cs_main_page;
	cs_main_page = cs_main_page - csn;
	//set up indexes to load images if not already loaded
	//again, check for hero image and change math based on this
	firstIndex=cs_main_page*5;
	cs_product_remainder = cs_visual_products%10;
	if(cs_product_remainder>5){
		cs_product_remainder=5;	
	}
	secondIndex=(Math.floor(cs_visual_products/10)*5)+(cs_product_remainder)+(cs_main_page*5);
	if(cs_specialproduct&&cs_specialproduct.length>0&&cs_main_page!=0) {
		firstIndex-=1;
		secondIndex-=3;
	} else if (cs_specialproduct&&cs_specialproduct.length>0&&cs_main_page==0) {
		firstIndex=1;
		secondIndex-=2;
	}
	loadTheImages(firstIndex,secondIndex);
	if (cs_main_page == 0) {
		// disable left arrow
		$('csmainarrowleftoff').setOpacity(0);
		$('csmainarrowlefthit').setStyle('visibility','hidden');
	}
	if (cs_main_page < cs_main_page_max) {
		// enable right arrow
		$('csmainarrowrightoff').setOpacity(1);
		$('csmainarrowrighthit').setStyle('visibility','visible');
	}
	FX_main_slide = new Fx.Style('cscataloginnerholder', 'margin-left', {
		duration: 1000, 
		transition: Fx.Transitions.Cubic.easeInOut
	});
	FX_main_slide.start(-cs_oldpos * cs_visual_products_width,-cs_main_page * cs_visual_products_width);
	cs_set_pagelinks();
}

function cs_main_go_right_core(csn) {
// console.log(cs_main_page)
	cs_oldpos = cs_main_page;
	cs_main_page = cs_main_page + csn;
	
	//set up indexes to load images if not already loaded
	firstIndex=cs_main_page*5;
	cs_product_remainder = cs_visual_products%10;
	if(cs_product_remainder>5){
		cs_product_remainder=5;	
	}
	secondIndex=(Math.floor(cs_visual_products/10)*5)+(cs_product_remainder)+(cs_main_page*5);
	if(cs_specialproduct&&cs_specialproduct.length>0&&cs_main_page!=0) {
		firstIndex-=1;
		secondIndex-=3;
	} else if (cs_specialproduct&&cs_specialproduct.length>0&&cs_main_page==0) {
		firstIndex=1;
		secondIndex-=2;
	}
	loadTheImages(firstIndex,secondIndex);
	if (cs_main_page == cs_main_page_max) {
		// disable right arrow
		$('csmainarrowrightoff').setOpacity(0);
		$('csmainarrowrighthit').setStyle('visibility','hidden');
	}
	if (cs_oldpos == 0) {
		// enable left arrow
		$('csmainarrowleftoff').setOpacity(1);
		$('csmainarrowlefthit').setStyle('visibility','visible');
	}
	FX_main_slide = new Fx.Style('cscataloginnerholder', 'margin-left', {
		duration: 1000, 
		transition: Fx.Transitions.Cubic.easeInOut
	});
	FX_main_slide.start(-cs_oldpos * cs_visual_products_width,-cs_main_page * cs_visual_products_width);
	cs_set_pagelinks();
}


var FX_mainarrowrollover
function cs_main_arrow_rollon(csarrow) {
	if (FX_mainarrowrollover) {
		FX_mainarrowrollover.stop();
	}
	$('csmainarrow'+csarrow+'glow').setOpacity(0);
	FX_mainarrowrollover = new Fx.Style('csmainarrow'+csarrow+'glow', 'opacity', {
		duration: 500, 
		transition: Fx.Transitions.Cubic.easeOut
	});
	FX_mainarrowrollover.start(0,1);
}

function cs_main_arrow_rolloff(csarrow) {
	if (FX_mainarrowrollover) {
		FX_mainarrowrollover.stop();
	}
	$('csmainarrow'+csarrow+'glow').setOpacity(0);
	FX_mainarrowrollover = new Fx.Style('csmainarrow'+csarrow+'glow', 'opacity', {
		duration: 150, 
		transition: Fx.Transitions.Cubic.easeOut
	});
	FX_mainarrowrollover.start(1,0);
}


// #################### filter handlers

cs_filteropen = new Array();
cs_filteropen['left'] = false;
cs_filtervalue = new Array();
cs_filtervalue['left'] = '';
cs_checkstatus = new Array();
cs_checkstatus['right1'] = 'off';
cs_checkstatus['right2'] = 'off';
cs_checkstatus['right3'] = 'off';
cs_checkvalue = new Array();
cs_checkvalue['right1'] = 'att-printathome';
cs_checkvalue['right2'] = 'att-useyourphotos';
cs_checkvalue['right3'] = 'att-downloadonline';

function cs_openfilter(cs_filter) {
	// find all options for filter
	if (this.location.href.indexOf('/theme') != -1) {
		cs_options = $$('*').filterByClass('filter'+cs_filter+'option');
	} else {
		cs_options=$$('*').filterByClass('nolink');
	}
	cs_height = 27 * cs_options.length+2;

	if (cs_filteropen[cs_filter]) {		// close filter
		cs_closefilter(cs_filter);
	} else {							// open filter
		if(cs_filter=='left'){
			$('filter'+cs_filter+'open').setStyle('display','block');
			if(cs_options.length>15){
				$('filter'+cs_filter+'open').setStyle('height','405px');
				$('filter'+cs_filter+'open').setStyle('width','150px');
				$('filter'+cs_filter+'open').setStyle('overflow','auto');
			}
			cs_filteropen[cs_filter] = true;
		} else {
			$('filter'+cs_filter+'openholder').setStyle('margin-top',-cs_height+'px');
		
			FX_filter_slide = new Fx.Style('filter'+cs_filter+'open', 'height', {
				duration: 600, 
				transition: Fx.Transitions.Cubic.easeOut
			});
			
			cs_height_clipped = cs_height;	// clip dropdowns if too long
			/*if (cs_height > 287) {
				cs_height_clipped = 287;
			}*/
	
			FX_filter_slide.start(1,cs_height_clipped);
			FX_filter_innerslide = new Fx.Style('filter'+cs_filter+'openholder', 'margin-top', {
				duration: 600, 
				transition: Fx.Transitions.Cubic.easeOut
			});
			FX_filter_innerslide.start(-cs_height,0);
			cs_filteropen[cs_filter] = true;
		}
	}
}

function cs_closefilter(cs_filter) {
	if(filterMousePos){
		// find all options for filter
		if (this.location.href.indexOf('/theme') != -1) {
			cs_options = $$('*').filterByClass('filter'+cs_filter+'option');
		} else {
			cs_options=$$('*').filterByClass('nolink');
		}
		cs_height = 27 * cs_options.length+2;
		if(cs_filter=="left"){
			$('filter'+cs_filter+'open').setStyle('display','none');
			cs_filteropen[cs_filter] = false;
		} else {
			FX_filter_slide = new Fx.Style('filter'+cs_filter+'open', 'height', {
				duration: 600, 
				fps: 12,
				transition: Fx.Transitions.Cubic.easeOut
			});
			FX_filter_slide.start(cs_height,1);
			FX_filter_innerslide = new Fx.Style('filter'+cs_filter+'openholder', 'margin-top', {
				duration: 600, 
				fps: 12,
				transition: Fx.Transitions.Cubic.easeOut
			});
			FX_filter_innerslide.start(0,-cs_height);
			cs_filteropen[cs_filter] = false;
		}
	}
}

// only on page load, go through list of all items in the page and disable all checkboxes if there are not items with that class
function cs_display_available_checkboxes() {
	cs_items = $$('*').filterByClass('csproduct');
	// create a list of all classes that exist within the items in the page that are display:block
	cs_displayed_list = new Array();
	for (csa=0;csa<cs_items.length;csa++) {
//		cs_classes = cs_items[csa].getProperties('class');
// vista issue:		cs_classes_set = cs_classes.class.split(' ');

		cs_classes = cs_items[csa].getProperty('class');
		cs_classes_set = cs_classes.split(' ');
		for (csb=0;csb<cs_classes_set.length;csb++) {
			cs_displayed_list[cs_classes_set[csb]] = 'yes';
		}
	}
	// see if any of the checkboxes has to be disabled since none of the current items has the necessary class
	if (cs_displayed_list['att-printathome'] == null && cs_displayed_list['att-downloadonline'] == null) {
		$('check-att-free').getElement('.check').setStyle('margin-top','-21px');
		$('check-att-free').getElement('div[class=checkboxinnertext]').setStyle('color','#cccccc');
		cs_checkstatus['right1'] = 'off';
	} else {
		$('check-att-free').getElement('.check').setStyle('margin-top','-43px');
		$('check-att-free').getElement('div[class=checkboxinnertext]').setStyle('color','#ffffff');
		cs_checkstatus['right1'] = 'empty';
	}
	if (cs_displayed_list['att-useyourphotos'] == null) {
		$('check-att-useyourphotos').getElement('.check').setStyle('margin-top','-21px');
		$('check-att-useyourphotos').getElement('div[class=checkboxinnertext]').setStyle('color','#cccccc');
		cs_checkstatus['right2'] = 'off';
	} else {
		$('check-att-useyourphotos').getElement('.check').setStyle('margin-top','-43px');
		$('check-att-useyourphotos').getElement('div[class=checkboxinnertext]').setStyle('color','#ffffff');
		cs_checkstatus['right2'] = 'empty';
	}
}

//due to SEO tracking, we made it so that the page refreshes everytime
//a filter gets called - rudi sugiato
function cs_filter_catalog2(cs_filterclass,cs_filter,cs_option_name) {
	var checkString='';
	//adding code to add the checkbox filters to the querystring
	for (var check=1;check<3;check++) {
		if (cs_checkstatus['right'+check] == 'checked') {
			checkString+="&right"+check+"="+cs_checkvalue['right'+check];
		}
	}
    //document.location.href = "?filterleft=" + cs_filterclass + checkString;
    cs_filter_catalog(cs_filterclass,cs_filter,cs_option_name);
}
function cs_filter_catalog(cs_filterclass,cs_filter,cs_option_name) {
	cs_disabled = false;
	
    // don't filter anything if the checkbox was disabled
	if (cs_filter.indexOf('right') != -1) {
		if (cs_checkstatus[cs_filter] == 'off') {
			cs_disabled = true;
		}
	}
	
	if (!cs_disabled) {
		// hide product table
		$('cscatalogouterholder').setStyle('opacity','0')
	
		// hide arrows
		$('csmainarrowleftoff').setStyle('visibility','hidden');
		$('csmainarrowlefthit').setStyle('visibility','hidden');
		$('csmainarrowrightoff').setStyle('visibility','hidden');
		$('csmainarrowrighthit').setStyle('visibility','hidden');
	
		cs_visual_products = 0;
	
		cs_filtervalue[cs_filter] = cs_filterclass;
		var linkTag2=cs_option_name.split(": ");
		if(linkTag2.length>1){
			cs_option_name=linkTag2[0];
		}
		if (cs_filter == 'left') {
			$('filter'+cs_filter+'closed').setHTML(cs_option_name);
		}
		// show new checkbox status
		if (cs_filter.indexOf('right') != -1) {
			if (cs_checkstatus[cs_filter] == 'empty') {
				cs_checkvalue[cs_filter] = cs_filterclass;
				cs_checkstatus[cs_filter] = 'checked';
				if($chk($('check-'+cs_filterclass))){
					$('check-'+cs_filterclass).getElement('.check').setStyle('margin-top','-63px');
				}
			} else {
				cs_checkvalue[cs_filter] = '';
				cs_checkstatus[cs_filter] = 'empty';
				if($chk($('check-'+cs_filterclass))){
					$('check-'+cs_filterclass).getElement('.check').setStyle('margin-top','-43px');
				}
			}
		}
		
		// collect all class attributes to be filtered by
		cscheckset = new Array();														// array of all allowable classes for this filter pass
		cscheckset[0] = '';																// default value if none of the checkboxes or dropdown options has been selected
		csy = 0;

		// checkboxes
		for (csx=1;csx<3;csx++) {
			if (cs_checkstatus['right'+csx] == 'checked') {
				cscheckset[csy++] = cs_checkvalue['right'+csx];
			}
		}

	
		// filter items
		if (cs_filtervalue['left'] != ''  ||  cs_filtervalue['right'] != '') {
			if (cs_pagestatus == 'product') {									// product display
				cs_products = $$('*').filterByClass('csproduct');
	
				cs_special_status = false;
				for (csa=0;csa<cs_products.length;csa++) {
					cs_filtertemp = false;									// true if either left or right filter hits
					var checkfalse_flag=true;                               //used to create the AND statement for combination of checks and dropdown filters
					if((cs_filtervalue['left'] == '') && (cscheckset[0]=='')){
						cs_filtertemp = true;
					} else {
						if (cs_filtervalue['left'] != '') {
							if (cs_products[csa].hasClass(cs_filtervalue['left'])) {
								cs_filtertemp = true;
							} else {
								checkfalse_flag=false;
								cs_filtertemp = false;
							}
						}
						if (cscheckset[0] != '') {
							//this if statement will set the class (for visible) on the projects if only one checkbox selected
							
								for (a=0;a<cscheckset.length;a++) {
									//if the att-free checkbox is checked, it covers two classes of FREE things - printathome and downloadonline. check em both
									if(cscheckset[a]=="att-free"){
										if ((cs_products[csa].hasClass("att-printathome")||cs_products[csa].hasClass("att-downloadonline"))&&checkfalse_flag==true) {
											cs_filtertemp = true;
										} else {
											checkfalse_flag=false;
											cs_filtertemp = false;
										}
									} else {
										if (cs_products[csa].hasClass(cscheckset[a])&&checkfalse_flag==true) {
											cs_filtertemp = true;
										} else {
											checkfalse_flag=false;
											cs_filtertemp = false;
										}
									}
									
								}
						}
					}
					if (cs_filtertemp  ||  cs_products[csa].hasClass('csspecialinfo')) {
						cs_products[csa].setStyle('display','inline');
						
						//bhaley adding code to load these images
						if(cs_product_images[csa]&&cs_product_images[csa].className!=""&&cs_product_images[csa].className!="imgLoaded"){
							var tempClass=cs_product_images[csa].className;
							cs_product_images[csa].setAttribute('src',tempClass);
							cs_product_images[csa].className="imgLoaded";
						}
						
						// make sure special image is accounted for 
						if (cs_products[csa].hasClass('csspecialimage')||cs_products[csa].childNodes[0].hasClass('csspecialimage')) {
							cs_special_status = true;
							cs_visual_products = cs_visual_products + 3;
						}
						cs_visual_products++;
					} else {
						cs_products[csa].setStyle('display','none');
					}
				}
				cs_product_remainder = (cs_visual_products)%10;
				//alert(cs_product_remainder);
				if(cs_product_remainder>0){
					cs_width_subtract=(Math.ceil(cs_product_remainder/2)*157);	
				} else {
					cs_width_subtract=0;	
				}
				if(cs_product_remainder>5){
					cs_product_remainder=5;	
				}
				// establish width in number of products
				cs_width_products = Math.ceil((cs_visual_products)/2);
				if(cs_width_products*157 < 785){
					$('cscataloginnerholder').setStyle('width',785+'px');
				} else {
					$('cscataloginnerholder').setStyle('width',((cs_width_products*157)+(cs_product_remainder*157)-cs_width_subtract)+'px');
				}
				cs_main_page_max = Math.floor((cs_visual_products-1)/10);
			} else {															// category display
				cs_categories = $$('*').filterByClass('cscategory');
		
				for (csa=0;csa<cs_categories.length;csa++) {
					if (cs_categories[csa].hasClass(cs_filterclass)  ||  cs_categories[csa].hasClass('csspecialinfo')) {
						cs_categories[csa].setStyle('display','inline');
						cs_visual_products++;
	
					} else {
						cs_categories[csa].setStyle('display','none');
					}
				}
	
				// dirty fix for data issues: if a Most Popular filter runs on load on a category and comes back empty, rerun filter as View all
				if (cs_visual_products == 0  &&  cs_filterclass != '') {			// recursive call of function since the current filter ran empty
					cs_filter_catalog('','right','View All');
				}
				
				// establish width in number of products
				cs_width_products = Math.ceil((cs_visual_products)/2);
				/*if (ie4) {	// for IE, add extra space to avoid categories running over into second line
					cs_width_products = cs_width_products + 15;
				}*/
				if (this.location.href.indexOf('/theme') != -1) {
					cs_products_virtual_length = cs_products_virtual_length - 1;		// in theme pages, filter hint does not exist, reduce one from number of items in page
				}			
				cs_product_remainder = cs_products_virtual_length%10;
				if(cs_product_remainder>0){
					cs_width_subtract=(Math.ceil(cs_product_remainder/2)*157);	
				} else {
					cs_width_subtract=0;	
				}
				if(cs_product_remainder>5){
					cs_product_remainder=5;	
				}
				if(cs_width_products*157 < 785){
					$('cscataloginnerholder').setStyle('width',785+'px');		
				} else {
					$('cscataloginnerholder').setStyle('width',((cs_width_products*157)+(cs_product_remainder*157)-cs_width_subtract)+'px');
				}
	
	
				cs_main_page_max = Math.floor((cs_visual_products-1)/10);
			}
		} else {																		// #### view all was selected (for both filters)
			if (cs_pagestatus == 'product') {
				cs_items = $$('*').filterByClass('csproduct');
			} else {
				cs_items = $$('*').filterByClass('cscategory');
			}
			
			cs_filtered_list = new Array();
			for (csa=0;csa<cs_items.length;csa++) {
				if (cs_pagestatus == 'category') {										// for category pages...
					cs_filtered_item = null;
					if (cs_items[csa].getElements('a').length > 0) {					// find links in the item
						cs_filtered_item = cs_items[csa].getElements('a')[0].href;
					}
					cs_duplicate = false;
					if (cs_filtered_list.length != 0  &&  cs_filtered_item != null) {	// if new link is already in list of filtered items, mark as duplicate
						for (csb=0;csb<cs_filtered_list.length;csb++) {
							if (cs_filtered_list[csb] == cs_filtered_item) {
								cs_duplicate = true;
							}
						}
					}
					if (!cs_duplicate) {												// only show items that are not duplicates
						cs_filtered_list[cs_filtered_list.length] = cs_filtered_item;
						cs_items[csa].setStyle('display','inline');
						cs_visual_products++;
					} else {
						cs_items[csa].setStyle('display','none');
					}
				} else {																// for product pages...
					cs_items[csa].setStyle('display','inline');
					// make sure special image is accounted for 
					if (cs_items[csa].childNodes[0]&&cs_items[csa].childNodes[0].nodeName=="div"){
						if (cs_items[csa].childNodes[0].hasClass('csspecialimage')) {		// look for inner div in current product - if it is a special image, add space for five extra images
							cs_special_status = true;
							cs_visual_products = cs_visual_products + 3;
						}
					}
					cs_visual_products++;
				}
			}
			if (cs_pagestatus == 'product') {
				cs_product_remainder = cs_products_virtual_length%10;
				if(cs_product_remainder>0){
					cs_width_subtract=(Math.ceil(cs_product_remainder/2)*157);	
				} else {
					cs_width_subtract=0;	
				}
				if(cs_product_remainder>5){
					cs_product_remainder=5;	
				}
				cs_width_products = Math.ceil(cs_visual_products/2);
				if(cs_width_products*157 < 785){
					$('cscataloginnerholder').setStyle('width',785+'px');
				} else {
					$('cscataloginnerholder').setStyle('width',((cs_width_products*157)+(cs_product_remainder*157)-cs_width_subtract)+'px');
				}	
				// now reset size of inner holder to align the icons into two rows
				cs_main_page_max = Math.floor((cs_visual_products-1)/10);
			} else {
				cs_product_remainder = cs_products_virtual_length%10;
				if(cs_product_remainder>0){
					cs_width_subtract=(Math.ceil(cs_product_remainder/2)*157);	
				} else {
					cs_width_subtract=0;	
				}
				if(cs_product_remainder>5){
					cs_product_remainder=5;	
				}
				cs_width_products = Math.ceil(cs_products_virtual/2);
				if(cs_width_products*157 < 785){
					$('cscataloginnerholder').setStyle('width',785+'px');
				} else {
					$('cscataloginnerholder').setStyle('width',((cs_width_products*157)+(cs_product_remainder*157)-cs_width_subtract)+'px');
				}
				
				cs_main_page_max = Math.floor((cs_visual_products-1)/10);
			}
		}
	
	
		if (cs_main_page_max > 0) {
			$('csmainarrowrightoff').setStyle('visibility','visible');
			$('csmainarrowrightoff').setStyle('opacity','1');
			$('csmainarrowrighthit').setStyle('visibility','visible');
		}
	
		// reset catalog all the way to the left
		cs_main_page = 0;
		$('cscataloginnerholder').setStyle('margin-left','0');
		
		cs_set_pagelinks();
	
		if (cs_filteropen['left']) {
			cs_closefilter('left');
		}
		if (cs_filteropen['right']) {
			cs_closefilter('right');
		}
	
		cs_display_catalog();
	}
}

var cs_mouse_on_filter = false;
var cs_filtertimer;


function cs_filter_ontimer(cs_filter) {
	clearTimeout(cs_filtertimer);
	cs_mouse_on_filter = true;
}

function cs_filter_offtimer(cs_filter) {
	cs_mouse_on_filter = false;
	cs_filtertimer = setTimeout(cs_filter_timerover_close,2000);
}

function cs_filter_timerover_close() {
	if (!cs_mouse_on_filter) {
		if (cs_filteropen['left']) {
			cs_closefilter('left');
		}
		if (cs_filteropen['right']) {
			cs_closefilter('right');
		}
	}
}
function callOmn(cs_partner,cs_cat,cs_subcat,cs_name){
	s_sendAnalyticsEventKeyInt('','ipg20:cpt:ext-link:'+cs_partner+':'+cs_cat+':'+cs_subcat+':'+cs_name,'cpt|lextcont|l25|'+cs_partner+'|'+cs_cat+'|'+cs_subcat+'|'+cs_name,'event30');
	s_setJumpid('re_r11400/uk/en/hho/ipg/ipg20_cpt_ext-link_'+cs_partner+'_'+cs_cat+'_'+cs_subcat+'_'+cs_name);
}
function showFilterLinks(theFilter, theObj){
	$(theObj).addClass('over');
	$$('.filterleftoption').addEvents({
		'mouseout':function(){
			hideFilterLinks(theObj);	
		}
	});
}	
var filterMousePos=true;
function hideFilterLinks(hideObj){
	$(hideObj).removeClass('over');
}
function filterMouseIn(){
	filterMousePos=false;	
}
function filterMouseOut(){
	filterMousePos=true;	
}