document.observe('dom:loaded', function(e) {

	// header
	$$('ul#mainNav li').each(function(v) { 
		 v.observe('mouseover', function(e){
			  $('f').blur()
		 });
	})	

	$('mainNav').dropnav({});

	
	$('countryNav').dropnav({});
         
         try{
                  
                  $$('ul#countryNavFtr ul').each(function(v) { v.setStyle({opacity: 0})})	
                  // footer
                  $('countryNavFtr').dropnav({
                          animate: {
                                  left: -89,
                                  top: -60,
                                  time: 2,
                                  opacity: 1
                          }
                  });
         }catch (err){
                  Event.observe(window, 'load',function(){
                           $$('ul#countryNavFtr ul').each(function(v) { v.setStyle({opacity: 0})})	                           
                           // footer
                           $('countryNavFtr').dropnav({
                                   animate: {
                                           left: -89,
                                           top: -60,
                                           time: 2,
                                           opacity: 1
                                   }
                           });
                  })
         }
	// Observe clicks on H2s to expand/collapse
	if($('leftnav_container') && !Object.isUndefined(window.akURL) && !Object.isUndefined(window.sub_store_code)) {	
		$('leftnav_container').observe('click', function(e) {	// Listen for click events within the leftnav_container
			if(e.target.tagName == 'h2' || e.target.tagName == 'H2') { 
				
				if(Object.isUndefined(e.target.isClosed) || e.target.isClosed == 0){
				//opened now close
					e.target.isClosed = 1
					$(e.target).nextSiblings().invoke('hide');
					/*$(e.target).setStyle({
						backgroundImage: "url('" + akURL + "/images/leftnav/" +$(e.target).up('div').id + "_Off_" + sub_store_code + ".gif')"
					})*/
					$(e.target).className = "closed";
					$(e.target).up('div').setStyle({
						backgroundColor: sub_store_code == 'TRU' ? '#b9d2f3' : '#cec3dc'
					})

					//close parents next siglings
					if($(e.target).up('div').id == 'module_PRTagPros'
                  || $(e.target).up('div').id == 'module_PRTagBestUses'
                  || $(e.target).up('div').id == 'module_PRTagDescribeYourself'){
						$(e.target).up('div').nextSiblings().invoke('hide');
					}
					
				} else {
				//closed now open
					e.target.isClosed = 0
					$(e.target).nextSiblings().invoke('show');
					/*$(e.target).setStyle({
						backgroundImage: "url('" + akURL + "/images/leftnav/" + $(e.target).up('div').id + "_" + sub_store_code + ".gif')"
					})*/
					$(e.target).className = "";
					$(e.target).up('div').setStyle({
						backgroundColor: sub_store_code == 'TRU' ? '#d6e8ff' : '#e0d5ea'
					})

					//close parents next siglings
					if($(e.target).up('div').id == 'module_PRTagPros'
                  || $(e.target).up('div').id == 'module_PRTagBestUses'
                  || $(e.target).up('div').id == 'module_PRTagDescribeYourself'){
						$(e.target).up('div').nextSiblings().invoke('show');
					}
				}
			} 
		});
	}

	// load recently viewed
	if ($('rvSummary')) {
		var ins3 = new Df.Slider('rvProductsSlider');
		ins3.pars.animate = {
			time: false,
			skip: 20,
			pause: 3
		}
		ins3.pars.iterateBy = 900;
		ins3.set();
	}
	
	// product page 
	if ($('tabset_productPage')) {
		
		// add listener to automatically adjust the tabset height for each tab onclick
		$('tabset_productPage').select('dt').each(function(v){
			 v.observe('click', function(e){
				  e.target.up().setStyle({height: e.target.next().scrollHeight + 60 + 'px'})
			 });
		});
		
		// initialize the height of the tabset according to the content within the first tab
		if ($('tab1')) {
			// check product descriptions for "&lt;BR&gt;" and replace with "<br />"
			$('tab1').next().innerHTML = $('tab1').next().innerHTML.replace(/&lt;BR&gt;/g, "<br />");
			$('tabset_productPage').setStyle({height: $('tab1').next().scrollHeight + 60 + 'px'});
		} else if ($('tab2')) {
			$('tabset_productPage').setStyle({height: $('tab2').next().scrollHeight + 60 + 'px'});
		} else if ($('tab3')) {
			$('tabset_productPage').setStyle({height: $('tab3').next().scrollHeight + 60 + 'px'});
		} 
		
	}

});


