/*

	Filename             sitewide.js
	Detail               Site functionality
	Author:              thunder::tech inc.
	License:             CLIENT is defined as the owner of online property from which this file resides or this code is referenced in.
						 ADDITIONAL PARTY is defined as anyone other than thunder::tech or CLIENT.
						 No right is granted to ADDITIONAL PARTY to sell, distribute, modify or otherwise transfer the following source code without explicit written permission by CLIENT or thunder::tech.

*/

/*  ================================
     Sitewide JavaScript
    ================================ */

thunder.client.project.pageLoaded = function()
{
	//thunder.client.project.flashReplace();
	//thunder.client.modify.rollImages();
	//thunder.client.modify.linkOptions();
	//thunder.client.modify.tabSet();
	thunder.client.modify.treeMenu(false);
	//thunder.client.modify.treeMenu(false, [thunder.client.modes.separatorTreeMenu]);
	//thunder.client.modify.treeMenu(false, [thunder.client.modes.imageTreeMenu]);
	//thunder.client.modify.selfLabelFields();
	//thunder.client.modify.requireFields();
	//thunder.client.modify.dropSelector(true);
	thunder.client.modify.scrollFeature(922, 8000, 1000);
	thunder.client.workarounds.alphaImages();
	thunder.client.workarounds.labelAsBrowser();
	
	$(".subNav a").hover(function(){ $("img", this).addClass("subArrow"); }, function(){ $("img", this).removeClass("subArrow"); });
	$(".subNav a:last").css("border-bottom", "none");
	
	
	
	var itemsPerCol = 7; //amount of nav items per column
	$(".nav-dropdown").each(function(){
		var numOfCols= Math.ceil($(".thunder-nav", this).size() / itemsPerCol); //Amounts of columns created
		$(".thunder-nav:last a", this).css("border-bottom", "none");
		
		if(numOfCols == 2){
			$(this).addClass("dd2");
			$(this).append('<img src="/Portals/_default/Skins/AccelMoto/images/dd2-bot.png">');
			itemsPerCol = Math.ceil($(".thunder-nav", this).size() / 2);
			
			//$(this).width(232 * Math.ceil($(".thunder-nav", this).size() / itemsPerCol));
			//var height = (27 * itemsPerCol) + 54;  //27 = height of each individual nav item --- 54 = the extra padding and height of the title
			for (i=0; i< numOfCols; i++){
				$(".thunder-nav", this).slice(i*itemsPerCol, (i+1)*itemsPerCol).wrapAll("<div class='dd-column'></div>");
			}
			$(".thunder-nav", this).prepend('<div class="nav-seperator"></div>');
			
			$(".dd-column", this).wrapAll("<div class='dd-bg'></div>")
			
		} else if(numOfCols >= 3){
			$(this).addClass("dd3");
			$(this).append('<img src="/Portals/_default/Skins/AccelMoto/images/dd3-bot.png">');
			itemsPerCol = Math.ceil($(".thunder-nav", this).size() / 3);
			
			//$(this).width(232 * Math.ceil($(".thunder-nav", this).size() / itemsPerCol));
			//var height = (27 * itemsPerCol) + 54;  //27 = height of each individual nav item --- 54 = the extra padding and height of the title
			for (i=0; i< numOfCols; i++){
				$(".thunder-nav", this).slice(i*itemsPerCol, (i+1)*itemsPerCol).wrapAll("<div class='dd-column'></div>");
			}
			$(".thunder-nav", this).prepend('<div class="nav-seperator"></div>');
			$(".dd-column", this).wrapAll("<div class='dd-bg'></div>");
			
		} else {
			$(this).append('<img src="/Portals/_default/Skins/AccelMoto/images/dd1-bot.png">');
			$(".thunder-nav", this).wrapAll("<div class='dd-column'></div>").prepend('<div class="nav-seperator"></div>');
			$(this).addClass('dd1');
		}
		
		
	});
	
	
	
	
	
	
	
	/*var count = 1;
	$('.slider > li').each(function(){
		$(this).append('<div class="count">' + count + '</div>');
		count +=1;
	});*/
	if($(".slider").length > 0){
		$('.slider').scrollIt({
		    menuHeight: 80,
			menuWidth: 469,
			itemHeight: 71,
			itemWidth: 89,
			initialItem:0,
			itemMargin:6
    	});
	}
}

thunder.client.project.flashReplace = function()
{
	$('.flash-billboard').flash(
		{
			swf: 'flash/billboard.swf',
			height: 200,
			width: 800,
			allowFullScreen: true,
			allowScriptAccess: 'always',
			hasVersion: 9,
			wmode: 'transparent',
			flashvars: {
				basePath: ''
			}
		}
	);
}

$(document).ready(thunder.client.project.pageLoaded);
