// JavaScript Document
//for use with jQuery
/*This script loads the header and footer into every page.  Pages that don't use this are: "home", "working", and "template" */

(function($) {
   
	$.fn.rwutemplate = function(thisBrand) {
		
		/*This disables all links in the footwear main container.  We need to decide if we want to add contact on click.  Maybe enlarged pictures of the shoes?*/
		$(".productPage a").attr("href", "javascript:;");
		
 		// merge default and user parameters 
		thisBrand = $.extend({
			hook: "",
			gender: ""
		}, thisBrand);
		
		/*make gender default to both - otherwise it should expect "men", "women", or "both"*/
		
		if(!thisBrand.gender){
			thisBrand.gender = "both";
		}
		
		//setup headerMural img list
		function makeMural(){
			var headerMuralImgs = ['a','b','c','d','e','f'];
			var LI = [];
			$.each(headerMuralImgs, function() {
				var url = '../images/header/mural-' + this + '.jpg';
				var childClass = '';
				var switchVar = this + "";
				switch (switchVar)
				{
				case 'a':
					childClass=' class="firstChild"';
				  break;
				case 'f':
					childClass=' class="lastChild"';
				  break;
				default:
					childClass='';
				}
				LI.push('<li' + childClass + '><img src="' + url + '" /></li>');
			});
			var headerMural = LI.join(''); 
			return headerMural;
		}
		
		//setup menu List
		function makeMenu(){
			var menuItems = ['Home','Footwear','Elite Team','Club Team','Partners','Recycle Shoes','About Us','Contact Us'];
			var LI = [];
			$.each(menuItems, function() {
				var url = this.toLowerCase().split(' ').join('-') + '.html';
			   	LI.push('<li><div><a href="../' + url + '"><span>' + this + '</span></a></div></li>');
			});
			var menuHTML = LI.join('');
			return menuHTML;
		}
		
		var theMenu = '';
		theMenu += '<ul>';	
		theMenu += makeMenu();
		theMenu += '</ul>';
			
		function BrandData(){
			this.hook = "";
			this.name = "";
			this.mensURL = "";
			this.womensURL = "";
		}
		
		/*This list will be the brand variable name hooks*/
		var brandList = [];
		brandList = ['xc','asics','brooks','kSwiss','newBalance','adidas','zoot','avia','mizuno','etonic','salomon','newton','pearlIzumi','puma','saucony'];
		
		var brandName = [];
		brandName = ['xc','asics','brooks','k-swiss','new-balance','adidas','zoot','avia','mizuno','etonic','salomon','newton','pearl izumi','puma','saucony'];
	
		var brandMensURL = [];
		brandMensURL = [
		 '../xc/xc.html',
 		 '../Asics/asicsproducts.html',
		 '../Brooks/brooksproducts.html',
		 '../K-Swiss/K-Swiss Products.html',
		 '../New Balance/newbalancefootwear.html',
		 '../Adidas/adidasproducts.html',
		 '../Zoot/zootsports.html',
		 '../Avia/aviafootwear.html',
		 '../Mizuno/mizunofootwear.html',
		 '../Etonic/etonicfootwear.html',
		 '../Salomon/salomonfootwear.html',
		 '../Newton/newtonfootwear.html',
		 '../Pearl Izumi/pearlizumi.html',
		 '../Puma/pumafootwear.html',
		 '../Saucony/sauconyfootwear.html'];
		
		var brandWomensURL = [];
		brandWomensURL = [
		  '../xc/women-xc.html',
		  '../Asics/womensasicsproducts.html',
		  '../Brooks/womensproducts.html',
		  '../K-Swiss/K-Swiss Products.html',
		  '../New Balance/nb-women-footwear.html',
		  '../Adidas/womenfootwear.html',
		  '../Zoot/zootsports.html',
		  '../Avia/aviafootwear.html',
		  '../Mizuno/womensfootwear.html',
		  '../Etonic/etonicfootwear.html',
		  '../Salomon/salomonfootwear.html',
		  '../Newton/newtonfootwear.html',
		  '../Pearl Izumi/womensfootwear.html',
		  '../Puma/pumafootwear.html',
		  '../Saucony/womenfootwear.html'];
		
		var brands = [];
		for (var i=0; i<brandList.length; i++)
		{
			brands[i] = new BrandData;
			brands[i].hook = brandList[i];
			brands[i].name = brandName[i];
			brands[i].mensURL = brandMensURL[i];
			brands[i].womensURL = brandWomensURL[i];
		}; 
	
		//setup sidebar
		function makeSidebar(){
			/*brand list made of JSON objects that were built above*/
			/*JSON object "thisBrand" was passed as a parameter*/
			var LI = [];
			$.each(brands, function() {
				var currentBrandClass = "";
				var currentBrandGenderMensClass = "";
				var currentBrandGenderWomensClass = "";
				if(this.hook==thisBrand.hook){
					currentBrandClass = ' class="currentBrand"';
					
					currentBrandGenderMensClass = ' class="currentBrandGender"';
					currentBrandGenderWomensClass = ' class="currentBrandGender"';
					/*if one gender is set - clear the other one*/
					if(thisBrand.gender=="men"){
						currentBrandGenderWomensClass = '';
					}
					else if(thisBrand.gender=="women"){
						currentBrandGenderMensClass = '';
					}
					
				}
			
		
				LI.push('<li' + currentBrandClass + '><a class="brandHook" href="' + this.mensURL + '">' + this.name + ':</a><p><a href="' + this.mensURL + '"><span' + currentBrandGenderMensClass + '>men</span></a> | <a href="' + this.womensURL + '"><span' + currentBrandGenderWomensClass + '>women</span></a></p></li>');
			});
			var theSidebar = LI.join(''); 
			return theSidebar;
		}

				
		var header = '';
		header += '<div id="headerBox">';
		header += '<div class="headerBoxLeft">';
		header += '<div id="headerLogo"><a href="../home.html">';
		header += '<img id="rwuLogo" src="../images/rwu-logo.jpg" alt="run with us store logo" /></a></div>';
		header += '<div id="logoDesc"><span>Footwear and Apparel Store</span></div></div>';
		/*<!--end headerBoxLeft -->*/
		header += '<div class="headerBoxRight">';
		header += '<div><a target="_blank" href="../images/full-mural-final.jpg">';
		header += '<ul id="headerMural">';
		header += makeMural();
		header += '</ul></a></div>';
		header += '<div id="headerInfo">';
		header += '<p><span>235 N. Lake Ave, Pasadena CA 91101 : Tel (626) 568-3331</span></p>';
		header += '</div>';
		header += '</div>';
	/*<!--end headerBoxRight -->*/
		header += '</div>';
   	/*<!--end headerBox-->*/
		
		header += '<div id="menuMain" class="menu">';
		header += theMenu;
		header += '</div>';
   		/*<!--end menuMain -->*/

		$('#header').html(header);
		
		var sidebar = '';
		sidebar += '<div class="upsLogo"><a href="../contact-us.html">';
		sidebar += '<img alt="free shipping from ups" src="../images/ups-logo.gif"/>';
		sidebar += '</a></div><h2 id="shoeBrandsTitle">Shoe Brands</h2>';
		sidebar += '<ul id="shoeBrands">';
		sidebar += makeSidebar();
		sidebar += '</ul>';
		$('#sidebar').html(sidebar);



		var footer = '';
		footer += '<div id="menuFooter" class="menu">';	
		footer += theMenu;
		footer += '</div>';	
		footer += '<div id="copyright"><p>';
		footer += 'Copyright &copy; 2000-2010 Run With Us. All Rights Reserved.  All other trademarks and copyrights are the property of their respective holders.';
		footer += '</p></div>';	
		$('#footer').html(footer);
		
		/*important to keep this last 'return this' --> it maintains the jquery chain*/
		return this;
	};
 
})(jQuery);