/**
Changelog:
- added page URL bind support for case studies & press
- added preloading for the bg images to avoid flicker issues on IE
- added tab management and overriding
- added hover image 

*/
var DDSPEED = 10;
var DDTIMER = 15;

/* system settings */
var systemSettings = {
	/* left nav management */
	leftNav : {
			/*sets the opacity of the thumbnail on the left nav mouseover */
			/*range: 0 - 1 */
			collectionThumbOpacity : '0.5'
	}
}

// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  
  opval = currh / c.maxh;
  if (opval > 0.9){
  	opval = 0.9;
  }
  
  c.style.opacity = opval;
  c.style.filter = 'alpha(opacity=' + (opval * 100) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
}


//bind to the dropdown pages
Event.observe(window,'load',function(){
	$('dd_prod5').observe('click',function(){
		document.location.href='reroofing.htm';
	});
	$('dd_prod6').observe('click',function(){
		document.location.href='press.htm';
	});
	$('dd_prod7').observe('click',function(){
		document.location.href='products_Search.html';
	});
	
	//preload the BG images
	im1 = new Image();
	im1.src = '/images/menu_image_bg.png';
	im2 = new Image();
	im2.src = '/images/menu_image_on_bg.png';
});





//left-tab compatibility
var leftNav = {
	isColorMode : false
	,	
	showColorMode : function(){
		leftNav.isColorMode = true;
		
		leftNav.populateCollectionsTab();
		
		return false;
	}
	,	
	showStyleMode : function(){
		leftNav.isColorMode = false;
		
		leftNav.populateCollectionsTab();
		
		return false;
	},
	setSpecificProduct : function(coll,prod_no){
		if (document.location.href.indexOf('products_eagleProducts') == -1){
			//no match, redirect
			document.location.href='/products_eagleProducts.htm#preload_product=' + coll + '~product_num=' + prod_no;
		}else{
			hash = new hashStateHandler();
			hash.updateValue('product_num',prod_no);
			eagleProducts.loadProducts(coll,'userclick');
		}
	},
	checkTabExists : function(tabname){
		if (!$('tab' + tabname + '_container')){
			//append this container
			dv = document.createElement('DIV');
			dv.id = 'tab' + tabname + '_container';
			dv.className='tabFeatured_container';
			dv.style.display = 'none';
			$('Nav_Panel_container').appendChild(dv);
		}

		$('tab' + tabname + '_container').style.position = 'absolute';
		$('tab' + tabname + '_container').style.top = '0px';
		$('tab' + tabname + '_container').style.left = '0px';
		$('tab' + tabname + '_container').style.width = '218px';
		$('tab' + tabname + '_container').style.height = '384px';
	}
	,
	populateCollectionsTab : function(){
		/*
		 * Prepare to populate the collections tab
		 * if we have a zip, we list real info. If we don't, we show the lightbox
		 */
		if (leftNav._isZipAvailable()){
			//populate the zip code box in the design..
			if ($('zipCode')){
				$('zipCode').value = leftNav._zipCode();
			}
			
			//get content
			new Ajax.Updater('tabCollection_container','/data/getCollections.php', 
				{
					parameters: 
						{
							zip : leftNav._zipCode(),
							isColorMode : leftNav.isColorMode
						},
					onComplete : function(){
						//update all passed nav collection images
						$$('img[class="leftNavCollectionImage"]').each(function (ele){
							//update each image
							ele.setStyle({cursor: 'pointer'});
							
							//make clickable
							ele.observe('click',leftNav.collectionGalleryClick);
							
							//preload the hover image
							MM_preloadImages('/data/dark-image.php?url=' + ele.src.substr(ele.src.indexOf('cts')-6));
						});
						$$('img[class="leftNavProductImage"]').each(function (ele){
							//update each image
							ele.setStyle({cursor: 'pointer'});
							
							//make clickable
							ele.observe('click',leftNav.collectionProductClick);
							
							//preload the hover image
							if (ele.src.indexOf('ons') !== -1){
								MM_preloadImages('/data/dark-image.php?url=' + ele.src.substr(ele.src.indexOf('ons')-9));
							}else{
								MM_preloadImages('/data/dark-image.php?url=' + ele.src.substr(ele.src.indexOf('ery')-5));
							}
						});
						
						//to support collabsable panels, we need to hide all but the 1st element
						
						//first, remove any click handling already setup
						Event.stopObserving('expand_standardweight_img','click');
						Event.stopObserving('expand_standardweight_img','mouseover');
						Event.stopObserving('expand_standardweight_img','mouseout');
						
						//init and process
						if ($('expand_standardweight').select('DIV').length > 1){

							//show only the first item
							$('expand_standardweight').setStyle({overflow : 'hidden', height : '20px'});
							
							//add a pointer for UX hinting
							$('expand_standardweight_img').setStyle({cursor: 'pointer'});
							
							//watch for expansion requests
							$('expand_standardweight_img').observe('click',function(e){
								$('expand_standardweight_img').fire('clicks:expand_standardweight_img')
							});
							//underlying request
							$('expand_standardweight_img').observe('clicks:expand_standardweight_img',function(e){
								new Effect.Tween('expand_standardweight',$('expand_standardweight').getHeight(),($('expand_standardweight').select('DIV').length*23),function(p){$('expand_standardweight').style.height = p + 'px'});
								
								//flip the image around
								$('expand_standardweight_img').src = 'images/collectionsPanel/gfx_header_01_standardWeight_off2.gif';
								
								$('expand_standardweight_img').addClassName("int_active");
								
								//if this happens, we need to also disable the lightweight area..
								if ($('expand_lightweight') && $('expand_lightweight').select('DIV').length > 1) {
									new Effect.Tween('expand_lightweight', $('expand_lightweight').getHeight(), 20, function(p){
										$('expand_lightweight').style.height = p + 'px'
									});
									
									//flip the image around
									$('expand_lightweight_img').src = 'images/collectionsPanel/gfx_header_02_lightweight_off.gif';
									
									$('expand_lightweight_img').removeClassName("int_active");
								}
								
								//handle cedur, but only if multiple items are listed
								if ($('expand_cedur').select('DIV').length > 1){
									
									//if this happens, we need to also disable the lightweight area..
									new Effect.Tween('expand_cedur',$('expand_cedur').getHeight(),20,function(p){$('expand_cedur').style.height = p + 'px'});
									
									//flip the image around
									$('expand_cedur_img').src = 'images/collectionsPanel/gfx_header_03_ceDUR_off.gif';

									$('expand_cedur_img').removeClassName("int_active");
									
								}
							});
							
							//watch for mouseovers
							$('expand_standardweight_img').observe('mouseover',function(e){
								//flip the image around
								if (!Event.element(e).hasClassName('int_active')){
									$('expand_standardweight_img').src = 'images/collectionsPanel/gfx_header_01_standardWeight_on.gif';
								}
							});
							$('expand_standardweight_img').observe('mouseout',function(e){
								//flip the image around
								if (!Event.element(e).hasClassName('int_active')){
									$('expand_standardweight_img').src = 'images/collectionsPanel/gfx_header_01_standardWeight_off.gif';
								}
							});
						}else{
							//only 1 item exists, no point offering to view all
							$('expand_standardweight_img').src = 'images/collectionsPanel/gfx_header_01_standardWeight_off2.gif';
						}
						
						//first, remove any click handling already setup
						Event.stopObserving('expand_lightweight_img','click');
						
						//init and process
						if ($('expand_lightweight') && $('expand_lightweight').select('DIV').length > 1){
							
							//show only the first item
							$('expand_lightweight').setStyle({overflow : 'hidden', height : '20px'});
							
							//add a pointer for UX hinting
							$('expand_lightweight_img').setStyle({cursor: 'pointer'});
							
							//watch for expansion requests
							$('expand_lightweight_img').observe('click',function(e){
								$('expand_lightweight_img').fire('clicks:expand_lightweight_img');
							});
							
							//underlying event
							$('expand_lightweight_img').observe('clicks:expand_lightweight_img',function(e){
								new Effect.Tween('expand_lightweight',$('expand_lightweight').getHeight(),($('expand_lightweight').select('DIV').length*23),function(p){$('expand_lightweight').style.height = p + 'px'});
								
								//flip the image around
								$('expand_lightweight_img').src = 'images/collectionsPanel/gfx_header_02_lightweight_off2.gif';
								
								$('expand_lightweight_img').addClassName("int_active");
								
								//if this happens, we need to also disable the stdweight area..
								new Effect.Tween('expand_standardweight',$('expand_standardweight').getHeight(),20,function(p){$('expand_standardweight').style.height = p + 'px'});
								
								//flip the image around
								$('expand_standardweight_img').src = 'images/collectionsPanel/gfx_header_01_standardWeight_off.gif';
								
								$('expand_standardweight_img').removeClassName("int_active");
								
								//handle cedur, but only if multiple items are listed
								if ($('expand_cedur').select('DIV').length > 1){
									
									//if this happens, we need to also disable the lightweight area..
									new Effect.Tween('expand_cedur',$('expand_cedur').getHeight(),20,function(p){$('expand_cedur').style.height = p + 'px'});
									
									//flip the image around
									$('expand_cedur_img').src = 'images/collectionsPanel/gfx_header_03_ceDUR_off.gif';

									$('expand_cedur_img').removeClassName("int_active");
									
								}

							});
							
							//watch for mouseovers
							$('expand_lightweight_img').observe('mouseover',function(e){
								//flip the image around
								if (!Event.element(e).hasClassName('int_active')){
									$('expand_lightweight_img').src = 'images/collectionsPanel/gfx_header_02_lightweight_on.gif';
								}
								
							});
							$('expand_lightweight_img').observe('mouseout',function(e){
								//flip the image around
								if (!Event.element(e).hasClassName('int_active')){
									$('expand_lightweight_img').src = 'images/collectionsPanel/gfx_header_02_lightweight_off.gif';
								}
								
							});
						}else if ($('expand_lightweight')){
							//only 1 item exists, no point offering to view all
							$('expand_lightweight_img').src = 'images/collectionsPanel/gfx_header_02_lightweight_on.gif';
						}
						
						
						//first, remove any click handling already setup
						Event.stopObserving('expand_cedur_img','click');
						
						//init and process
						if ($('expand_cedur').select('DIV').length > 1){
							
							//show only the first item
							$('expand_cedur').setStyle({overflow : 'hidden', height : '20px'});
							
							//add a pointer for UX hinting
							$('expand_cedur_img').setStyle({cursor: 'pointer'});
							
							//watch for expansion requests
							$('expand_cedur_img').observe('click',function(e){
								$('expand_cedur_img').fire('clicks:expand_cedur_img');
							});
							
							//underlying event
							$('expand_cedur_img').observe('clicks:expand_cedur_img',function(e){
								new Effect.Tween('expand_cedur',$('expand_cedur').getHeight(),($('expand_cedur').select('DIV').length*23),function(p){$('expand_cedur').style.height = p + 'px'});
								
								//flip the image around
								$('expand_cedur_img').src = 'images/collectionsPanel/gfx_header_03_ceDUR.gif';
								
								$('expand_cedur_img').addClassName("int_active");
								
								//if this happens, we need to also disable the stdweight area..
								new Effect.Tween('expand_standardweight',$('expand_standardweight').getHeight(),20,function(p){$('expand_standardweight').style.height = p + 'px'});
								
								//flip the image around
								$('expand_standardweight_img').src = 'images/collectionsPanel/gfx_header_01_standardWeight_off.gif';
								
								$('expand_standardweight_img').removeClassName("int_active");
								
								//if this happens, we need to also disable the lightweight area..
								new Effect.Tween('expand_lightweight',$('expand_lightweight').getHeight(),20,function(p){$('expand_lightweight').style.height = p + 'px'});
								
								//flip the image around
								$('expand_lightweight_img').src = 'images/collectionsPanel/gfx_header_02_lightweight_off.gif';
								
								$('expand_lightweight_img').removeClassName("int_active");
								
								
							});
							
							//watch for mouseovers
							$('expand_cedur_img').observe('mouseover',function(e){
								//flip the image around
								if (!Event.element(e).hasClassName('int_active')){
									$('expand_cedur_img').src = 'images/collectionsPanel/gfx_header_03_ceDUR_on.gif';
								}
								
							});
							$('expand_cedur_img').observe('mouseout',function(e){
								//flip the image around
								if (!Event.element(e).hasClassName('int_active')){
									$('expand_cedur_img').src = 'images/collectionsPanel/gfx_header_03_ceDUR_off.gif';
								}
								
							});
						}else{
							//only 1 item exists, no point offering to view all
							$('expand_cedur_img').src = 'images/collectionsPanel/gfx_header_03_ceDUR.gif';
						}
						
						document.fire('eagle:leftNavCollectionTabReady');
					}
				}
			);
		}else{
			$('tabCollection_container').innerHTML = 'Please enter your zipcode to continue';
			document.fire('eagle:leftNavCollectionTabReady');
		}
			
	},
	collectionGalleryClick : function (callee){
		ele = Event.element(callee);
		
		//get name info
		data = ele.name.split('|');

		//index 1 is the main image
		if (document.location.href.indexOf('products_eagleProducts') == -1){
			//no match, redirect to the product page, which will then load the data from the hash
			if (document.location.href.indexOf('products_eagleCEDUR') != -1){ // redirect for CE DUR only page 1-28-10
				eagleProducts.loadCollectioncedur(data[2],'userclick');
			}else if (document.location.href.indexOf('products_CeDUR') != -1){
			//match, Go To CE DUR Page
				document.location.href='/products_eagleCEDUR.html#~isColorMode=false~cedurpreload_gallery=CE_DUR';
			}else if (data[0] == 'ltwcoll'){
				document.location.href='/products_eagleProducts.htm#ltwpreload_gallery=' + data[1] + '~isColorMode=' + leftNav.isColorMode;
			}else if (data[0] == 'cedurcoll'){
				document.location.href='/products_eagleProducts.htm#cedurpreload_gallery=' + data[2] + '~isColorMode=' + leftNav.isColorMode;
			}else{
				document.location.href='/products_eagleProducts.htm#preload_gallery=' + data[1] + '~isColorMode=' + leftNav.isColorMode;
			}
		}else{
			//we're already on the product page, load up the data directly
			if (data[0] == 'ltwcoll'){
				eagleProducts.loadCollectionLTW(data[1],'userclick');
			}else if (data[0] == 'cedurcoll'){
				eagleProducts.loadCollectioncedur(data[2],'userclick');
			}else{
				eagleProducts.loadCollection(data[1],'userclick');
			}
		}
		Event.stop(callee);
	},
	collectionProductClick : function (callee){
		ele = Event.element(callee);
		
		//get name info
		data = ele.name.split('|');
		
		//index 1 is the main image
		//$$('td[width="692"]')[0].innerHTML
		
		if (document.location.href.indexOf('products_eagleProducts') == -1){
			//no match, redirect
			if (document.location.href.indexOf('products_eagleCEDUR') != -1){ // redirect for CE DUR only page 1-28-10
				eagleProducts.loadProductscedur(data[2],'userclick');
			}else if (document.location.href.indexOf('products_CeDUR') != -1){
			//match, Go To CE DUR Page
				document.location.href='/products_eagleCEDUR.html#~isColorMode=false~cedurpreload_product=CE_DUR';
			}
			else if (data[0] == 'ltwprod'){
				document.location.href='/products_eagleProducts.htm#ltwpreload_product=' + data[1] + '~isColorMode=' + leftNav.isColorMode;
			}else if (data[0] == 'cedurprod'){
				document.location.href='/products_eagleProducts.htm#cedurpreload_product=' + data[1] + '~isColorMode=' + leftNav.isColorMode;
			}else{
				document.location.href='/products_eagleProducts.htm#preload_product=' + data[1] + '~isColorMode=' + leftNav.isColorMode;
			}
			
		}else{
			if (data[0] == 'ltwprod'){
				eagleProducts.loadProductsLTW(data[1],'userclick');
			}else if (data[0] == 'cedurprod'){
				eagleProducts.loadProductscedur(data[2],'userclick');
			}else{
				eagleProducts.loadProducts(data[1],'userclick');
			}
		}
		Event.stop(callee);
		
	},
	populateSampleTab : function(coll,tile_no,removeSampleID){
		if (leftNav._isZipAvailable()){
			new Ajax.Updater('tabSample_container','/data/getSamples.php', 
				{
					parameters: 
						{
							zip : leftNav._zipCode(),
							coll : coll,
							tile_no : tile_no,
							removeSample : removeSampleID
						}
				}
			);
		}else{
			$('tabSample_container').innerHTML = 'Please enter your zipcode to continue';
		}
	},
	
	populateFeaturedTab : function(){
		//populate the specific featured tab info 
		//upgrade the left nav
		img = $$('img[src="images/gfx_tab_featured_coolRoofTile.gif"]');
		if (img){
			if (img[0]){
				img[0].src='/images/spacer.gif';
				img[0].width = '218';
				img[0].height='118';
			}
		}
		$('tabFeatured_container').innerHTML = $('tabFeatured_container').innerHTML + '<div class="featureTab_imgLink_crrc"><a onmouseover="MM_swapImage(\'featuredTab_imgLink_02\',\'\',\'images/gfx_tab_featured_coolRoofTile_on.gif\',1)"  onmouseout="MM_swapImgRestore()" href="greenBld_coolRoofTile.htm"><img height="129" border="0" width="227" id="featuredTab_imgLink_02" name="featuredTab_imgLink_02" alt="Eagle Cool Roof Tile" src="http://www.eagleroofing.com/images/gfx_tab_featured_coolRoofTile_off.gif"/></a></div>';
		
		//upgrade the featured tab
		img = $$('img[src="images/img_tab_featured.jpg"]');
		if (img){
			if (img[0]){
				img[0].src='/images/spacer.gif';
				img[0].width = '218';
				img[0].height='88';
			}
		}
		$('tabFeatured_container').innerHTML = $('tabFeatured_container').innerHTML + '<div class="featureTab_imgLink_solarroof"><a onmouseover="MM_swapImage(\'featuredTab_imgLink_01\',\'\',\'images/img_tab_featured_on.jpg\',1)" onmouseout="MM_swapImgRestore()" href="greenBld_eagleSolarRoof.htm"><img height="98" border="0" width="228" id="featuredTab_imgLink_01" name="featuredTab_imgLink_01" alt="Eagle Solar Roof" src="http://www.eagleroofing.com/images/img_tab_featured_off.jpg"/></a></div>';
		
		//cache the left-side hovers
		MM_preloadImages('images/img_tab_featured_on.jpg');
		MM_preloadImages('images/gfx_tab_featured_coolRoofTile_on.gif');
		
		//make the cool roof table look clickable
		$('TNcoolRoofTile').setStyle({cursor : 'pointer'});
		$('TNcoolRoofTile').observe('click', function(){
			//switch to cool roof tiles
			if (document.location.href.indexOf('products_eagleProducts') == -1){
				//no match, redirect
				document.location.href='/products_eagleProducts.htm#preload_product=Cool_Roof_Tile';
			}else{
				eagleProducts.loadProducts('Cool_Roof_Tile','userclick');
			}
		});
		$$('.textTN')[0].setStyle({cursor : 'pointer'});
		$$('.textTN')[0].observe('click', function(){
			//switch to cool roof tiles
			if (document.location.href.indexOf('products_eagleProducts') == -1){
				//no match, redirect
				document.location.href='/products_eagleProducts.htm#preload_product=Cool_Roof_Tile';
			}else{
				eagleProducts.loadProducts('Cool_Roof_Tile','userclick');
			}
		});
		
		//update the solar text tab
		//$$('div[class="tabFeatured_txt_1 textSmall"]')[0].absolutize();
		$$('div[class="tabFeatured_txt_1 textSmall"]')[0].setStyle({width : '219px'})
		$$('div[class="tabFeatured_txt_1 textSmall"]')[0].innerHTML = "Significantly reduces your monthly energy bill.<br>Receive sizable rebates and tax incentives.";
		
		//update the padding of the 'top 3 selling products' image
		try{
			if ($$('img[src="images/txt_tab_featured_title2.gif"]')){
				$$('img[src="images/txt_tab_featured_title2.gif"]')[0].setStyle({paddingLeft:'1px'});
			}
		}catch(e){
			
		}
		
		//request the featured products in the area
		if (!$('tabFeatured_container_featuredproducts')){
			tmpdiv = document.createElement('DIV');
			tmpdiv.id = 'tabFeatured_container_featuredproducts';
			tmpdiv.className = "featureTab_featured_products";
			$('tabFeatured_container').appendChild(tmpdiv);
		}
		
		new Ajax.Updater('tabFeatured_container_featuredproducts','/data/getFeaturedProducts.php', 
				{
					parameters: 
						{
							zip : leftNav._zipCode()
						}
				}
			);		
		
	}
	
	,
	_isZipAvailable : function(){
		if (!leftNav._zipCode()){
			return false;
		}else{
			return true;
		}
	},
	
	_setZip : function(zipcode){
		jar = new CookieJar({
			expires: 7776000,
			path : '/'
		});
		
		zip = {zip : zipcode};
		
		zipdata = jar.put('zipdata',zip)
		
		//fire a zipUpdated event
		document.fire('eagle:zipupdated');
	}
	,
	
	_zipCode : function(){
		jar = new CookieJar({
			expires: 7776000,
			path : '/'
		});
		
		zipdata = jar.get('zipdata');
		
		if ((zipdata) && (zipdata.zip != '')){
			return zipdata.zip;
		}else{
			return false;
		}
		
	},
	
	showTab : function(tabname){
		//setup the correct tab image
		if (tabname == 'Featured'){			imgsegment = 'featured';		}
		if (tabname == 'Collection'){			imgsegment = 'collections';		}
		if (tabname == 'Sample'){			imgsegment = 'samples';		}
		$('gfx_nav_tab_featured_on').src = '/images/gfx_nav_tab_' + imgsegment + '_on.gif';

		//hide all non-used tabs
		if (tabname != 'Featured'){
			leftNav._hideTabID('Featured');
		}
		if (tabname != 'Sample'){
			leftNav._hideTabID('Sample');
		}
		if (tabname != 'Collection'){
			leftNav._hideTabID('Collection');
		}

		leftNav._showTabID(tabname);
		
		/**
		 * If we have no zip code, we need to show a zipcode input box
		 */
		if (!leftNav._isZipAvailable()){
			/*
			 * display lightbox
			 * removed: 			 
			 */
			$$('.contentWell')[0].setStyle({position: 'relative'});
			
			if (!$('lightbox')){
				lightboxoverlay = document.createElement('div');
				lightboxoverlay.style.position = 'absolute';
				lightboxoverlay.style.left = '7px';
				lightboxoverlay.style.top = '7px';
				lightboxoverlay.style.width = '693px';
				lightboxoverlay.style.backgroundColor = '#000';
				lightboxoverlay.style.height = ($$('.contentWell')[0].getHeight()-14) + 'px';
				lightboxoverlay.id = 'lightboxoverlay';
				lightboxoverlay.style.zIndex = 10000;
				lightboxoverlay.innerHTML = 'x';
				
				
				lightbox = document.createElement('div');
				lightbox.style.position = 'absolute';
				lightbox.style.left = '7px';
				lightbox.style.top = '7px';
				lightbox.style.width = '693px';
				lightbox.style.height = ($$('.contentWell')[0].getHeight()-14) + 'px';
				lightbox.id = 'lightbox';
				lightbox.style.zIndex = 10001;
				lightbox.innerHTML = 				
								'<table width="100%" border="0" height="100%">' +
									'<tr>' +
										'<td align="center" valign="top">' +
											'<table border="0" width="400" height="300">' +
												'<tr><td><img src="/images/spacer.gif" width="1" height="139"></td></tr><tr>' +
													'<td align="center" id="#zipEntryBoxText">' +
														'<font color=white style="font-family: arial; font-size:11px;">' +
															'<font style="font-family: arial;font-size:14px; line-height:1em" size=4>Please confirm or change your zip code<br>to see Eagle products in your area</font><img src="/images/spacer.gif" style="display: block" height=12>' +
															'<table border="0" style="width:200px; height:36px;" background="/images/gfx_lightbox_formBkgPanel.gif"><tr><td align="right" width="155"><input type=text id="zipEntryBox" style="border: 1px solid #D4D0A3;width:140px; text-align: center;"></td><td align="left"><img id="zipEntryButton" src="/images/gfx_btn_go_off.png" onMouseOver="this.src=\'/images/gfx_btn_go_on.png\'" onMouseOut="this.src=\'/images/gfx_btn_go_off.png\'" alt="(go)"></td></tr></table><img src="/images/gfx_btn_go_on.png" style="display: none;">' +
															'<img src="/images/spacer.gif" height=11 style="display: block"><div class="lightbox_smallTxt">Notice: To ensure your satisfaction with your tile choice,<br>we request that you order an actual tile sample or samples<br>from your roofing contractor, distributor, or through this site.</div><img src="/images/spacer.gif" height=10 style="display: block">' +
															'<div class="lightbox_smallTxt">Please do not order a color based on a photo you see on<br>this site or have printed at home. Color selection should be<br>made using actual samples.</div>' +
														'</font>' +
													'</td>' +
												'</tr>' +
											'</table>' +
										'</td>' +
									'</tr>' +
								'</table>';
	
				
				$$('.contentWell')[0].insert(lightboxoverlay);
				$$('.contentWell')[0].insert(lightbox);
				
				$('lightboxoverlay').setOpacity(0.7);
				$('lightbox').setOpacity(0.99);
				
				
				//onclick, update the zip data
				$('zipEntryButton').observe('click',function(){
					
					//figure out what the zip code is
					if (!parseInt($('zipEntryBox').value)){
						zip = 92377;
					}else{
						zip = $('zipEntryBox').value;
					}
					
					//set the zip cookie
					leftNav._setZip(zip);
					
					//call populate*tabs
					leftNav.populateCollectionsTab();
					leftNav.populateSampleTab();
					leftNav.populateFeaturedTab();
					
					//hide the lightbox
					$('lightbox').fade();
					$('lightboxoverlay').fade();
				});
				
				//preselect the zip
				new Ajax.Request('/data/geoip.php',{
					onSuccess : function(transport){
						var json = transport.responseText.evalJSON();
						if (json.postal_code != '' ){
							// $('zipEntryBox').value = json.calc_zip;
							$('zipEntryBox').value = json.postal_code;
						}
					}
				});
			}
		}
	},

	_hideTabID : function(tabid){
		if ($('tab' + tabid + '_container').style.display == ''){
			$('tab' + tabid + '_container').fade();
		}
	},
	
	_showTabID : function(tabid){
		$('tab' + tabid + '_container').appear();
	},

	importCSS : function(){
		if(document.createStyleSheet) {
	
			document.createStyleSheet('/leftnav.css');
	
		}else {
		
			var styles = "@import url(' /leftnav.css ');";
		
			var newSS=document.createElement('link');
		
			newSS.rel='stylesheet';
		
			newSS.href='data:text/css,'+escape(styles);
		
			document.getElementsByTagName("head")[0].appendChild(newSS);
	
		}
	},
	submitSample : function(){
		/**
		 * Submit a sample request and return the response
		 */
		
		//validate..
		if (!leftNav.sampleValidateForm()){
			//no successful validation.. show the 'error' message
			//disabled due to design constraints $('sample_form_error').appear();
			$('required_sample').appear();
		}else{
			//form is valid
			if ($('sample_form_error').style.display != 'none'){
				//disabled due to design constraints - $('sample_form_error').hide();
			}
			$('required_sample').fade();
			//run submission
			$('progress_bar').setStyle({opacity: 0.8,display:''});
			pageTracker._trackPageview("/sampleRequest/Submit");
			new Ajax.Updater({ success: 'tabSample_container'},'/data/submitSampleRequest.php',{
					parameters : Form.serialize('sampleFormFrm',true),
					onFailure : function(transport){	
						$('tabSample_container').innerHTML = '<font color=red>Error!</font><br>An error was encountered submitting your request. Please contact us for assistance.';
						$('progress_bar').fade();
						
					},
					onComplete: function(transport) {
      					$('progress_bar').fade();
						
  					}

			});
		}			
	},
	sampleValidateForm : function(){
		/**
		 * validate the form
		 */
		var ar = new Array('sample_name','sample_user','sample_project','sample_phone','sample_address','sample_city','sample_state','sample_zip','sample_email');
		var foundError = false;
		
		//validate normal fields
		ar.each(function(ar_id){
			 
			if ($(ar_id).getValue() == ''){
				$(ar_id + '').addClassName('sampleFormInput_error'); 
				foundError = true;
				
			}else{
				
				$(ar_id + '').removeClassName('sampleFormInput_error');
			}
			
		});
		
		return !foundError;
	}
	
}

Event.observe(document,'dom:loaded',function(){
	//import the left nav css
	leftNav.importCSS();
	
	//update the tabFeatured_container with the correct id
	$$('div[class="tabFeatured_container"]').each(function (ele){
		ele.id = 'tabFeatured_container';
	});
		
	//override the default tabs
	for (j=0; j < $('Nav_Tab_container').getElementsByTagName('area').length; j++){
		ele = $($('Nav_Tab_container').getElementsByTagName('area')[j]);
		
		//override each tab
		if (ele.href.indexOf('samples.htm') != -1){
			ele.observe('click',function (event){
				Event.stop(event);
				leftNav.showTab('Sample');
			});
		}
		if (ele.href.indexOf('index.htm') != -1){
			ele.observe('click',function (event){
				Event.stop(event);
				leftNav.showTab('Featured');
			});
		}
		if (ele.href.indexOf('collections.htm') != -1){
			ele.observe('click',function (event){
				Event.stop(event);
				leftNav.showTab('Collection');
			});
		}
	};
	
	//create children in Nav_Panel_container for featured / collections / samples
	leftNav.checkTabExists('Featured');
	leftNav.checkTabExists('Collection');
	leftNav.checkTabExists('Sample');

	//populate the tabs
	leftNav.populateCollectionsTab();
	leftNav.populateSampleTab();
	leftNav.populateFeaturedTab();

	//preload the various bg images
	MM_preloadImages('/images/gfx_nav_tab_featured_on.gif');
	MM_preloadImages('/images/gfx_nav_tab_collections_on.gif');
	MM_preloadImages('/images/gfx_nav_tab_samples_on.gif');
	
	//observe users clicking the 'new zip code' button on the top segment of the page
	//onclick, update the zip data
	$('zipCodeButton').observe('click',function(){
		
		//figure out what the zip code is
		if (!parseInt($('zipCode').value)){
			zip = 92377;
		}else{
			zip = $('zipCode').value;
		}
		
		//set the zip cookie
		leftNav._setZip(zip);
		
		//call populate*tabs
		leftNav.populateCollectionsTab();
		leftNav.populateSampleTab();
		leftNav.populateFeaturedTab();
		
		//hide the lightbox
		if ($('lightbox')){
			$('lightbox').fade();
		}
	});
	
});

//Cookie support
var CookieJar = Class.create();

CookieJar.prototype = {

	/**
	 * Append before all cookie names to differntiate them.
	 */
	appendString: "__CJ1_",

	/**
	 * Initializes the cookie jar with the options.
	 */
	initialize: function(options) {
		this.options = {
			expires: 3600,		// seconds (1 hr)
			path: '',			// cookie path
			domain: '',			// cookie domain
			secure: ''			// secure ?
		};
		Object.extend(this.options, options || {});

		if (this.options.expires != '') {
			var date = new Date();
			date = new Date(date.getTime() + (this.options.expires * 1000));
			this.options.expires = '; expires=' + date.toGMTString();
		}
		if (this.options.path != '') {
			this.options.path = '; path=' + escape(this.options.path);
		}
		if (this.options.domain != '') {
			this.options.domain = '; domain=' + escape(this.options.domain);
		}
		if (this.options.secure == 'secure') {
			this.options.secure = '; secure';
		} else {
			this.options.secure = '';
		}
	},

	/**
	 * Adds a name values pair.
	 */
	put: function(name, value) {
		name = this.appendString + name;
		cookie = this.options;
		var type = typeof value;
		switch(type) {
		  case 'undefined':
		  case 'function' :
		  case 'unknown'  : return false;
		  case 'boolean'  : 
		  case 'string'   : 
		  case 'number'   : value = String(value.toString());
		}
		var cookie_str = name + "=" + escape(Object.toJSON(value));
		try {
			document.cookie = cookie_str + cookie.expires + cookie.path + cookie.domain + cookie.secure;
		} catch (e) {
			return false;
		}
		return true;
	},

	/**
	 * Removes a particular cookie (name value pair) form the Cookie Jar.
	 */
	remove: function(name) {
		name = this.appendString + name;
		cookie = this.options;
		try {
			var date = new Date();
			date.setTime(date.getTime() - (3600 * 1000));
			var expires = '; expires=' + date.toGMTString();
			document.cookie = name + "=" + expires + cookie.path + cookie.domain + cookie.secure;
		} catch (e) {
			return false;
		}
		return true;
	},

	/**
	 * Return a particular cookie by name;
	 */
	get: function(name) {
		name = this.appendString + name;
		var cookies = document.cookie.match(name + '=(.*?)(;|$)');
		if (cookies) {
			return (unescape(cookies[1])).evalJSON();
		} else {
			return null;
		}
	},

	/**
	 * Empties the Cookie Jar. Deletes all the cookies.
	 */
	empty: function() {
		keys = this.getKeys();
		size = keys.size();
		for(i=0; i<size; i++) {
			this.remove(keys[i]);
		}
	},

	/**
	 * Returns all cookies as a single object
	 */
	getPack: function() {
		pack = {};
		keys = this.getKeys();

		size = keys.size();
		for(i=0; i<size; i++) {
			pack[keys[i]] = this.get(keys[i]);
		}
		return pack;
	},

	/**
	 * Returns all keys.
	 */
	getKeys: function() {
		keys = $A();
		keyRe= /[^=; ]+(?=\=)/g;
		str  = document.cookie;
		CJRe = new RegExp("^" + this.appendString);
		while((match = keyRe.exec(str)) != undefined) {
			if (CJRe.test(match[0].strip())) {
				keys.push(match[0].strip().gsub("^" + this.appendString,""));
			}
		}
		return keys;
	}
};

