


// function for parsing the query string
function getActivePage() {
	var querystring = String (document.location).split('?')[1];
	if (!querystring) {
		return false;
	}
	var activeToggler = String (querystring).split('=')[1];
	if (querystring.match("/")) {
		activeToggler = String(activeToggler).split("/")[0];
	}
	return activeToggler;
}

window.addEvent('domready', function() {
// ===== FLASH CONTENT ===== \\
	if ($('flashContent')) {
		
		if ($('wrapper')) {
			$('wrapper').setStyle('display', 'none');
		}
		
		// remove the elements with the javascript error.
		$$('.jsError').each(function(e) {
			e.remove();
		});

		// flash content variables
		var sPath = "swf/";
		var sWidth = "545";
		var sHeight = "300";
		var sVersion = "8";
		var sBackground = "#ffffff";

		// embed flash player as per page
		if ($('home')) {
			var sHeight = "300";
			var sFilename = "introflash";
		} else if ($('promotions')) {
			var sHeight = "300";
			var sFilename = "index";
		} else if ($('locations')) {
			var sHeight = "300";
			var sFilename = "locations";
		} else if ($('careers')) {
			var sFilename = "careers";
		}

		// embed the flash player
		var so = new SWFObject(sPath+sFilename+".swf", sFilename, sWidth, sHeight, sVersion, sBackground);
		if (so.write("flashContent")) {
			$('flashContent').setStyles("height: "+ sHeight +"px; border: none;");
		} else {
			$('wrapper').setStyle('display', 'block');
		}
	}
	
// ===== SLIDING NAVIGATION ===== \\
	
	// remove the shop navigation cookie if you're not on the shop page
	if ($('index') == null) {
		if (Cookie.get('dufresne_nav')) {
			Cookie.remove('dufresne_nav');
		}
	}

	if ($("shopNavigation")) {		
		
		// loop through the categories, remove the href attribute and make the sublists display as block
		var togglers = $$('a.toggler');
		var toggles = $$('ul.toggle');
		
		var activePage = getActivePage();
		var active = false;
		
		
		togglers.each(function(e, i) {
			e.removeAttribute("href");
			e.getNext().setStyle('display', 'block');
			if (e.id == activePage+"Toggle") {
				active = i;
			}
		})
		
		var shopNav = new Accordion(togglers, '.toggle', {
			display: false,
			opacity: false,
			alwaysHide: true,
			show: active
		}, $('shopNavigation'));

	}
	
// ===== TAB SHELF ===== \\
	if ($('tabShelf')) {
		// instantiate the variables
		var tabShelf = $('tabShelf');
		var tabBox = $('tabBox');

		tabShelf.style.overflow = "hidden";
		tabShelf.style.height = "25px";

		// set up the final width for the tab box
		var tabWidth = document.getElementById('tabWidth').clientWidth+5;
		tabBox.style.width = tabWidth+"px";
		tabBox.style.position = "absolute";

		//adjust this equation to allow for paged sliding....
		
		if (tabWidth > tabShelf.clientWidth) {

			var tabSlider = new Fx.Styles('tabBox', {duration: 1000, transition: Fx.Transitions.Expo.easeOut});
			var tabShelfWidth = tabShelf.clientWidth;
			
			// create the right button
			rightButton = document.createElement("p");
			rightButton.setAttribute("id", "rightButton");
			rightButton.setAttribute("onclick", "testRight()");
			tabShelf.appendChild(rightButton);
			rightButton.innerHTML = "Next &raquo;"

			// create the left button
			leftButton = document.createElement("p");
			leftButton.setAttribute("id", "leftButton");
			leftButton.setAttribute("onclick", "testLeft()");
			tabShelf.appendChild(leftButton);
			leftButton.innerHTML = "&laquo Back";
			
			
			leftButton.style.display = "none";

			leftButton.onclick = function() {
				if (tabBox.offsetLeft < 0) {
					if (tabBox.offsetLeft+tabShelfWidth > 0) {
						tabSlider.start({
							'left': 0
						});
						leftButton.style.display = "none";
					} else {
						tabSlider.start({
							'left': tabBox.offsetLeft + tabShelfWidth
						});
					}
					if (rightButton.style.display == "none") {
						rightButton.style.display = "block";
					}

				}
			};

			rightButton.onclick = function() {
				if (tabBox.offsetLeft > (0-tabWidth)) {
					if (tabBox.offsetLeft-(tabShelfWidth*2) < 0-tabWidth) {
						tabSlider.start({
							'left': 0-tabWidth+tabShelfWidth
						});
						rightButton.style.display = "none";
					} else {
						tabSlider.start({
							'left': tabBox.offsetLeft - tabShelfWidth
						});
					}
					if (leftButton.style.display == "none") {
						leftButton.style.display = "block";
					}
					
				}
			};
		}
	}
// ===== FAQ ACCORDIAN ===== \\
	if ($('answers')) {
		var accordion = new Accordion('p.q', 'div.a', {
			display: false,
			alwaysHide: true,
			onActive: function(toggler, element){
				toggler.setStyle('color', '#ffffff');
			},

			onBackground: function(toggler, element){
				toggler.setStyle('color', '#ffffff');
			}
			
			
		}, $('answers'));
	}
	


	
});


// JavaScript Document