var ProductList = new Class({
	initialize : function() {
		this.accordion = new Accordion('li.atStart', 'ul.atStart', {
			opacity: false}, $('accordion'));
		
		// category
		var categoryArray = document.location.href.split("/");
		var cookieName = 'section' + categoryArray[4];	
		var section = 0;
		if ( $('txtHiddenIndex')) {
			section = $('txtHiddenIndex').value;
		}
		else {	
			section = Cookie.get(cookieName);
		}	
		// pull section from url if it exists
		//var sectionArray = document.location.href.split("&section=");
		//if ( sectionArray.length == 2 ) {
			//section = section.split("&");
			//if ( section.length > 0 ) {
	//			this.accordion.display(parseInt(sectionArray[1]));
			//} else {
			//	this.accordion.display(-1);
			//}
	//	} else {
	
			if ( section ) {
				this.accordion.display(section);
			} else {
				this.accordion.display(-1);
			}
	//	}
		// hook up an event to store the cookie
		var i = 0;
		var togglers = $('accordion').getElements('li[class*=toggler]').each( function(item) {
			item.accordionIndex = i++;
			item.getFirst().addEvent('click',function(e) {
				new Event(e).stop();
				this.accordion.display(-1);
				
				
				
				Cookie.remove(cookieName);
				Cookie.set(cookieName,item.accordionIndex,{path : '/'});
				var el = item.getFirst();
				var url = el.getProperty('href');
				
				(function(){
				    this.onClickSection(e,url)
				}.bind(this)).delay(1000);
				
				
				
			}.bind(this));
		},this)
	},
	onClickSection : function(e,url) {
		//alert("here");
		document.location = url;
	}
});

window.addEvent('domready', function(){
	var productList = new ProductList();
});
