/*

	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(541, 8000, 1000);
	thunder.client.workarounds.alphaImages();
	thunder.client.workarounds.labelAsBrowser();
	var itemsPerCol = 8; //amount of nav items per column

	$(".thunder-tree-menu > .thunder-nav:first").css("padding-left", "0px");
	
	$(".thunder-tree-menu > .thunder-nav").each(function(){
		if($('.nav-dropdown', this).length <= 0){
			$("a", this).css("border-bottom-width", "4px");
		}
	});
	
	$(".subNav a").hover(function(){ $("img", this).addClass("subArrow"); }, function(){ $("img", this).removeClass("subArrow"); });
	$(".subNav a:last").css("border-bottom", "none");
	
/*	var count = 1;
	$('.slider > li').each(function(){
		$(this).append('<div class="count">' + count + '</div>');
		count +=1;
	});*/
	if($(".slider").length > 0){
		$('.slider').scrollIt({
				menuHeight: 70,
				menuWidth: 399,
				itemHeight: 55,
				itemWidth: 74,
				initialItem:0,
				itemMargin: 7,
				vertical:false
		});
	}
	
	$(".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).prepend('<img src="/portals/_default/skins/lakewood/images/dd2-top.png">');
			$(this).append('<img src="/portals/_default/skins/lakewood/images/dd2-bot.png">');
			itemsPerCol = Math.ceil($(".thunder-nav", this).size() / 2);
			
			$(this).width(256 * Math.ceil($(".thunder-nav", this).size() / itemsPerCol));
			for (i=0; i< numOfCols; i++){
				$(".thunder-nav", this).slice(i*itemsPerCol, (i+1)*itemsPerCol).wrapAll("<div class='dd-column'></div>");
			}
			var height = (27 * itemsPerCol) + 57;  //27 = height of each individual nav item --- 54 = the extra padding and height of the title
			$(".dd-column", this).wrapAll("<div class='dd-bg' style='height:" + height + "px;'></div>")
			
		} /*else if(numOfCols == 3){
			$(this).addClass("dd3");
			$(this).prepend('<img src="images/dd3-top.png">');
			$(this).append('<img src="images/dd3-bot.png">');
			
			$(this).width(232 * Math.ceil($(".thunder-nav", this).size() / itemsPerCol));
			for (i=0; i< numOfCols; i++){
				$(".thunder-nav", this).slice(i*itemsPerCol, (i+1)*itemsPerCol).wrapAll("<div class='dd-column'></div>");
			}
			$(".dd-column", this).wrapAll("<div class='dd3-bg'></div>")
			
		}*/  else if(numOfCols >= 3){
			$(this).addClass("dd3");
			$(this).prepend('<img src="/portals/_default/skins/lakewood/images/dd3-top.png">');
			$(this).append('<img src="/portals/_default/skins/lakewood/images/dd3-bot.png">');
			itemsPerCol = Math.ceil($(".thunder-nav", this).size() / 3);
			
			$(this).width(258 * Math.ceil($(".thunder-nav", this).size() / itemsPerCol));
			for (i=0; i<3; i++){
				$(".thunder-nav", this).slice(i*itemsPerCol, (i+1)*itemsPerCol).wrapAll("<div class='dd-column'></div>");
			}
			var height = (27 * itemsPerCol) + 57;  //27 = height of each individual nav item --- 54 = the extra padding and height of the title
			$(".dd-column", this).wrapAll("<div class='dd-bg' style='height:" + height + "px;'></div>")
			
		} else {
			$(this).prepend('<img src="/portals/_default/skins/lakewood/images/dd1-top.png">');
			$(this).append('<img src="/portals/_default/skins/lakewood/images/dd1-bot.png">');
			$(this).addClass('dd1');
		}
		
		
	});
	
	$(window).load(function(){
		if($('.subNav').height() > 107){
			$('.bg-subNav').height( $('.subNav').height() - 102 );
		}
		
		if($(".page").height() > 954){
		$(".bg-body-left, .bg-body-right").css("height", $(".page").outerHeight() + 300);
		}
	});
}

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);
