// Home page silo opened
var homeSilo = false;

// Activate Global SIFR variables
var avenir = { src: 'js/sIFR3/avenir_436.swf' };
var avenir_h1 = { src: 'js/sIFR3/avenir_436_h1.swf' };
var avenir_current = { src: 'js/sIFR3/avenir_436_current.swf' };
sIFR.activate(avenir, avenir_h1);

// Initiate vertical measures
var leftSiloOneHeight, leftSiloTwoHeight, contentHeight;

// Set colour scheme
var bgImage;

function file_name_only(str) {
	str = str.toLowerCase();
	if (str.lastIndexOf('?')>0)
	{
	    str = str.substring(0, str.lastIndexOf('?'));
	}
	
	var slash = '/';
	if (str.match(/\\/)) {
		slash = '\\';
	}
	return str.substring(str.lastIndexOf(slash) + 1, str.lastIndexOf('.'));
}

function sub_cat_only(str) {	
	var hashChar = '#';
	
	if (str.lastIndexOf(hashChar) > 0)
	{
		str = str.substring(str.lastIndexOf(hashChar) + 1, str.length);
		return str;
	}
	else
		return null;
}

String.prototype.replaceAll = function(pcFrom, pcTo){
	var i = this.indexOf(pcFrom);
	var c = this;
	
	while (i > -1){
		c = c.replace(pcFrom, pcTo); 
		i = c.indexOf(pcFrom);
	}
	return c;
}

function singleWord(str) {
	str = str.replaceAll('/', '-');
	str = str.replaceAll(' ', '-');
	str = str.replaceAll("•", '-');
	str = str.replaceAll("·", '-');
	str = str.replaceAll('"', '-');
	str = str.replaceAll('?', '-');
	str = str.replaceAll(",", '-');
	//str = str.replaceAll(".", '-');
	str = str.replaceAll("'", '-');
	
	return str;
}
var colourScheme;

setupBackground = function() {
	// should call this on window.resize (in final.js)
	
	colourScheme = file_name_only(document.getElementById("colourCSSBase").href);
    //var bgColor = document.getElementById('colourCSSBase').style.backgroundColor;
	//var bgColor = document.body.bgColor;
	//var bgColor = document.body.style.backgroundColor;
	//var bgColor = document.body.style.background;
	var bgColor = $("body").css('background-color');
	//alert(bgColor);
    
	/*
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	*/
	
	var vpWidth = screen.width;
	//var vpWidth = myWidth;
	
	//alert(vpWidth);
	
    if (vpWidth <= 1024) {
        bgImage = "url(css/bgphotos/1024x768/" + colourScheme + ".jpg)";
        var css1024 = document.createElement("link")
		css1024.id = 'css1024';
        css1024.href = "css/1024";
		if($('#market').attr('market')!='OUTDOOR')
			css1024.href += "-" + $('#market').attr('market');
		css1024.href += ".css";
        css1024.rel = "stylesheet";
        css1024.type = "text/css";
		document.getElementsByTagName("head")[0].appendChild(css1024);
    }
    else
	{
		$("#css1024").remove();
		if (vpWidth > 1024 && vpWidth <= 1280) {
			bgImage = "url(css/bgphotos/1280x1024/" + colourScheme + ".jpg)";
		}
		else if (vpWidth > 1280 && vpWidth <= 1440) {
			bgImage = "url(css/bgphotos/1440x1050/" + colourScheme + ".jpg)";
		}
		else if (vpWidth > 1440 && vpWidth <= 1680) {
			bgImage = "url(css/bgphotos/1680x1200/" + colourScheme + ".jpg)";
		}
		else if (vpWidth > 1680 && vpWidth <= 1920) {
			bgImage = "url(css/bgphotos/1920x1200/" + colourScheme + ".jpg)";
		}
		else {
			bgImage = "url(css/bgphotos/2560x1600/" + colourScheme + ".jpg)";
		}
	}
	
	if (vpWidth > 1024 && $("#market").attr('market') == "OUTDOOR" && file_name_only(window.location.href) == '.com/') {
		var cssHome = document.createElement("link");
		cssHome.id = 'cssBirdword';
		cssHome.href = "css/birdword.css";
		cssHome.rel = "stylesheet";
		cssHome.type = "text/css";
		document.getElementsByTagName("head")[0].appendChild(cssHome);
	}
	else
		$("#cssBirdword").remove();
	
    document.body.style.background =  bgImage + " " + bgColor + " fixed no-repeat top center";
	
	/*
	var swfLink = document.createElement("script");
	swfLink.id = 'swfobject';
	swfLink.src = 'teaser/files/swfobject.js';
	swfLink.language = 'javascript';
	swfLink.type = 'text/javascript';
	document.getElementsByTagName("head")[0].appendChild(swfLink);
	*/
}

$(document).ready(function() {
	$("noscript").hide();
	
    setupBackground();
	
	// Initalize sIFR headlines
	sifrInit();
	
	// Set theme coloured rss Icon in silo
	var rssIcon = 'css/rss-icons/' + colourScheme + '.png';
	$("#rssIcon").attr('src', rssIcon);
	
	// Hide submenus and attach menu behaviours
	$(".menuSubCat").hide();
	
	// Show current menu's submenus
	$(".current").siblings(".menuSubCat").show();
	
	// Attach footer function behaviours
	$(".footerFunction").click(function() {
		var targetFunction = $(this).attr('target');
		
		if ($("#" + targetFunction).css('display') == 'block')
		{
			$("#" + targetFunction).slideUp("normal", function() {sizeVerticals();});
			$("#footerMinimize").fadeOut();
			
		}
		else
		{
			$(".footerSubContent").slideUp();
			$("#" + targetFunction).slideToggle("normal", function() {sizeVerticals();});
			$("#footerMinimize").fadeIn();
			pageTracker._trackEvent('footer','/footerOpen/' + targetFunction);
		}
	});
	$("#footerMinimize").click(function() { $(".footerSubContent").slideUp("normal", function() {sizeVerticals();}); $("#footerMinimize").fadeOut(); });
	
	// Attach form field background-image behaviours
	$("#search").focus(function() { if($(this).val() == "") { $(this).css('background-image','none'); } });
	$("#search").blur(function() { if($(this).val() == "") { $(this).css('background-image','url(graphics/search.gif)'); } });
	
	$("#EMail").focus(function() { if($(this).val() == "") { $(this).css('background-image','none'); } });
	$("#EMail").blur(function() {	if($(this).val() == "") { $(this).css('background-image','url(graphics/email.gif)'); } });
	
	$("#EMailHeader").focus(function() { if($(this).val() == "") { $(this).css('background-image','none'); } });
	$("#EMailHeader").blur(function() {	if($(this).val() == "") { $(this).css('background-image','url(graphics/email.gif)'); } });
	
	// Clear the background for any textbox or password that has something in it
	$("input[type=text], input[type=password]").each(function() {
		if($(this).val() != "")
		{
			$(this).css('background-image','none');
		}
	});
	
	$("#UserLogin").focus(function() { if($(this).val() == "") { $(this).css('background-image','none'); } });
	$("#UserLogin").blur(function() {	if($(this).val() == "") { $(this).css('background-image','url(graphics/email-username.gif)'); } });
	
	$("#UserPwd").focus(function() { if($(this).val() == "") { $(this).css('background-image','none'); } });
	$("#UserPwd").blur(function() { if($(this).val() == "") { $(this).css('background-image','url(graphics/password.gif)'); } });
	
	$("#formTW").submit(function() {
		/*
		$("#UserLogin").val(""); 
		$("#UserLogin").css('background-image','url(graphics/email-username.gif)');
		
		$("#UserPwd").val("");
		$("#UserPwd").css('background-image','url(graphics/password.gif)');
		*/
	});
	
	// Show tooltips on any links or searchResults that have titles set
	$("a, .searchResult, .thumb, div:not(#footerMinimize)").tooltip();
	
	//alert(file_name_only(window.location.href));
	switch(file_name_only(window.location.href)) {
		case 'product':
			$("div.searchResult").click(function() {
				var targetURL = this.id; // Product.aspx?Mens/Jackets-Vests/Alpha-SL-Jacket
				var catURL = targetURL.substring(0, targetURL.lastIndexOf('/')); // Product.aspx?Mens/Jackets-Vests
				var subCatURL = sub_cat_only(window.location.href); // Insulated-Shell
				var prodURL = targetURL.substr(targetURL.lastIndexOf('/')); // /Alpha-SV-Jacket
				
				/* THIS CODE IS SET TO INSERT THE subCat INSIDE THE URL BETWEEN cat AND PRODUCT NAME
				targetURL = catURL;
				
				if (subCatURL != null)
					targetURL += "/" + subCatURL;
					
				targetURL += prodURL;
				*/
				
				if (subCatURL != null)
					targetURL = targetURL + "#" + subCatURL;
				
				//alert(targetURL);
				window.location = targetURL;
			});
			
			break;
		case 'athletes':
			$(".searchResult").hover(
				function() {
					$(this).children().children(".athleteSRLinks").slideDown('fast');
				},
				function() {
					$(this).children().children(".athleteSRLinks").slideUp('fast');
				}
			);
			
			$("div.searchResult:not(.athleteNews, .athleteSRLink)").click(function() {
				window.location = "Athlete.aspx?" + this.id;
			});
			
			$("div.athleteNews").click(function() {
				window.location = "Article.aspx?article=" + this.id;
			});
			break;
		case 'athlete':
			
			break;
		case 'news':
			$(".searchResult").click(function() {
				window.location = "Article.aspx?article=" + this.id;
			});
			break;
		case 'partners':
			$("div.searchResult").click(function() {
				window.open ('http://'+$(this).attr('lightboxtitle'));
				pageTracker._trackEvent('outbound','/partners/' + $(this).attr('lightboxtitle'));
			});
			break;
		case 'events':
			$("div.searchResult").click(function() {
				window.open ('http://'+$(this).attr('lightboxtitle'));
				pageTracker._trackEvent('outbound','/events/' + $(this).attr('lightboxtitle'));
			});
			break;
		case 'online-dealers':
			$("div.searchResult").click(function() {
				window.open ('http://'+$(this).attr('id'));
				pageTracker._trackEvent('outbound','/online-dealers/' + $(this).attr('id'));
			});
			break;
		case 'where-to-buy':
			$("div.searchResult").click(function() {
				window.open ($(this).attr('id'));
				pageTracker._trackEvent('outbound','/where-to-buy/' + $(this).attr('id'));
			});
			break;
		case 'service-forms':
			//alert('case: service-forms');
			
				var iframe = document.getElementById('frameService');
				var service = $("#frameService").attr('src');
				service = service.substr(service.lastIndexOf("=")+1,service.length);
				//alert(service);
				switch(service)
				{
					case "PROPRCH":
						iframe.style.height = "3000px";
						break;
					case "LEAFFRM":
						iframe.style.height = "1500px";
						break;
					default:
						iframe.style.height = "1000px";
						break;
				}
				
				
//				if (iframe.contentDocument) {
//					// FF
//					// alert(iframe.contentDocument.height);
//					// iframe.style.height = iframe.contentDocument.height + 24 + "px";
//					iframe.style.height = "1000px";
//				}
//				if (iframe.contentWindow.document.body) {
//					// IE7
//					// iframe.style.height = iframe.contentWindow.document.body.scrollHeight + 24 + "px";
//					iframe.style.height = "1000px";
//				}
			
			
			//$('#frameService').attr('height','800');
			break;
		case 'article':
			$("div.searchResult").click(function() {
				window.open ('http://'+$(this).attr('lightboxtitle'));
				pageTracker._trackEvent('outbound','/article/' + $(this).attr('lightboxtitle'));
			});
			break;
		case 'compare':
			$('div.compareResult').click(function() {
				window.location = this.id;
			});
			break;
		case 'video':
			
			
			if(typeof(launchVideo) != 'undefined')
			{
				//alert(dump(launchVideo));
				/*
				Shadowbox.open({
							   	title: launchVideo.title,
								content: launchVideo.HREF,
								moreBeta: launchVideo.moreBeta,
								gallery: launchVideo.gallery
							   }, { gallery: launchVideo.gallery} );
				*/
			}
			
			$(".videoLauncher").click(function() {
				//$(this).children().children('a').click();
				//alert(this.id);
				//alert($(this).attr('lightboxtitle'));
				Shadowbox.open({
							   	title: $(this).attr('lightboxtitle'),
								content: this.id,
								moreBeta: $(this).attr('moreBeta'),
								gallery: 'Videos'
							   }, { gallery: 'Videos'} );
			});
			
			/*
			var videoTitle = $("#videoTitle").attr('value');
			var videoContent = $("#videoContent").attr('value');
			var videoMoreBeta = $("#videoMoreBeta").attr('value')
			*/
			
			/*
			Shadowbox.open({
				title: videoTitle,
				content: videoContent});
			*/
			//alert(videoMoreBeta);
			
			break;
			
		case '.com/':
		case 'home':
			$("div.newsSiloArticle").click(function() {
				window.location = this.id;
			});
			$("div.newsSiloVideo").click(function() {
				//$(this).children().children('a').click();
				Shadowbox.open({
							   	title: $(this).children('.searchResultName').children('a').attr('lightboxtitle'),
								content: this.id,
								gallery: 'Videos'
							   }, { gallery: 'Videos'} );
			});
			
			if($('#market').attr('market')=='URBAN')
			{
				//alert('urban homepage');
				
				$("#content").append('<div id="homeVR"><div id="homeVRviewer"></div></div>');

				//var bgColor = $("body").css('background-color');
				$("body").css('background-image','none');
				//document.body.style.background =  bgImage + " " + bgColor + " fixed no-repeat top center";
				
				$("#homeVRviewer").jmedia(
					{version:"9,0"
					},
					{
						src:"pano/krpano.swf",
						flashVars:'pano=pano/krpano.xml&license=pano/license.xml',
						width: "100%",
						height: "100%",
						wmode: 'transparent',
						id: "krpano"
					}
				);
				/* KRPANO DRAG FIX CODE */
				$(document).mouseup(function(event)
				  {
					  //alert('mouseup');
					if (!$(event.target).is("#krpano")) document.getElementById("krpano").sendToKrpano();
				  });
				/* END KRPANO DRAG FIX CODE */
			}
			break;
			
		case 'veilance-home-test':
			if($('#market').attr('market')=='URBAN')
			{
				$("#content").append('<div id="homeVR"><div id="homeVRviewer"></div></div>');

				//var bgColor = $("body").css('background-color');
				$("body").css('background-image','none');
				//document.body.style.background =  bgImage + " " + bgColor + " fixed no-repeat top center";
				
				$("#homeVRviewer").jmedia(
					{version:"9,0"
					},
					{
						src:"pano/krpano.swf",
						flashVars:'pano=pano/krpano-fix.xml&license=pano/license.xml',
						width: "100%",
						height: "100%",
						wmode: 'transparent',
						id: "krpano"
					}
				);
			}
			/* KRPANO DRAG FIX CODE */
			$(document).mouseup(function(event)
			  {
				  //alert('mouseup');
				if (!$(event.target).is("#krpano")) document.getElementById("krpano").sendToKrpano();
			  });
			/* END KRPANO DRAG FIX CODE */
			break;
	}
});

function openSignup(targetForm, event) {
	//alert(event.type == 'click');
	if (event.keyCode == 13 || event.type == 'click')
	{
		var email = $('#EMail').val();
		
		if (email == '' || email == null)
			email = $('#EMailHeader').val();
		
		/*
		var simplify = '';
		switch($('#market').attr('market')) {
			case "URBAN":
				simplify = "V";
				break;
			case "OUTDOOR": 
			case "LEAF":
				simplify = "Y";
				break;
		}
		*/
		
		Shadowbox.open({
			player:'iframe',
			title:'Sign up for news and offers',
			/*content:'http://tasweb.arcteryx.com/endusersignup.aspx' +'?Simplify=Y&EMail='+email,*/
			
			/*content:targetForm +'?Simplify=' + simplify + '&EMail=' + email,*/
			content:targetForm + '&EMail=' + email,
			width:'900',
			height:'900'
		}, {viewportPadding: 20});
		pageTracker._trackEvent('footer','/footerOpen/' + targetForm);
	}
}

function slideSubMenu(cat) {
	$('.menuCat > li > h3#'+cat).siblings(".menuSubCat").slideToggle('normal', function() {
		sizeVerticals();
	}); 
}

function setupStores() {
	$(".storeDetails").each(function() {
		//alert("index: " + $("div.storeDetails").index(this) + ", % 4 = " + ($("div.storeDetails").index(this) % 4) + ", %4== " + ($("div.storeDetails").index(this) % 4 == 0) );
		 if ($("div.storeDetails").index(this) % 4 == 0)
		 {
			 $(this).css('clear','both');
		 }
	});	
}

function openSilo(targetSilo) {
	// Hide both silos
	$(".silo").css('display', 'none');
	// Show the target silos
	$(".silo[PBType=" + targetSilo + "]").css('display','block');
	// resize verticals
	sizeVerticals();
	// re-initialize sIFR fonts
    sifrInit();
}

function firstFade(targetSilo) {
	if (homeSilo == false)
	{
		$(".silo").css('display', 'none');
		$(".silo[PBType=" + targetSilo + "]").fadeIn('normal', function() { sifrInit(); sizeVerticals(); });
		homeSilo = true;
	}
	else
	{
		openSilo(targetSilo);
	}
}

function searchIt(query) {
	//alert(query);
	query = query.replace(' ', '_');
	query = query.replace('/', '-');
	window.location.href = "Product.aspx?search=" + query;
}

// make divs and other elements clickable
function goTo(address) {
	window.location.href = address;
}

function sifrInit() {
	// H1 (non-current)
	sIFR.replace(avenir_h1, {
		selector: 'h1:not(.current)',
		css: { 
			'.sIFR-root': { 'color': '#000000' },
			'a': { 'color': '#CCCCCC', 'text-decoration': 'none' },
			'a:link': { 'color': '#CCCCCC' },
			'a:hover': { 'color': '#FFFFFF' }
			},
		transparent: 1,
		offsetTop: -5,
		tuneHeight: -5,
		onReplacement : function(){
			//alert('replace');
			//sizeVerticals();
			this.sIFR.doCompleteCheck();
			} 
	});
	
	// H1 (current)
	sIFR.replace(avenir_current, {
		selector: 'h1.current',
		css: { 
			'.sIFR-root': { 'color': sIFRcurrentColor },
			'a': { 'color': sIFRcurrentColor, 'text-decoration': 'none' },
			'a:link': { 'color': sIFRcurrentColor },
			'a:hover': { 'color': sIFRcurrentHover }
			},
		transparent: 1,
		offsetTop: -5,
		tuneHeight: -5,
		onReplacement : function(){
			//alert('replace');
			//sizeVerticals();
			this.sIFR.doCompleteCheck();
			} 
	});
	
	// H2 (non-current)
	sIFR.replace(avenir, {
		selector: 'h2:not(.current)',
		css: { 
			'.sIFR-root': { 'color': '#000000' },
			'a': { 'color': '#CCCCCC', 'text-decoration': 'none' },
			'a:link': { 'color': '#CCCCCC' },
			'a:hover': { 'color': '#FFFFFF' }
			},
		transparent: 1,
		offsetTop: -3,
		tuneHeight: -2,
		onReplacement : function(){
			//alert('replace');
			//sizeVerticals();
			this.sIFR.doCompleteCheck();
			} 
	});
	
	// H2 (current)
	sIFR.replace(avenir_current, {
		selector: 'h2.current',
		css: { 
			'.sIFR-root': { 'color': sIFRcurrentColor },
			'a': { 'color': sIFRcurrentColor, 'text-decoration': 'none' },
			'a:link': { 'color': sIFRcurrentColor },
			'a:hover': { 'color': sIFRcurrentHover }
			},
		transparent: 1,
		offsetTop: -3,
		tuneHeight: -2,
		onReplacement : function(){
			//alert('replace');
			//sizeVerticals();
			this.sIFR.doCompleteCheck();
			} 
	});
	
	// H3 (non-current)
	sIFR.replace(avenir, {
		selector: 'h3:not(.current)',
		css: { 
			'.sIFR-root': { 'color': '#000000' },
			'a': { 'color': '#CCCCCC', 'text-decoration': 'none' },
			'a:link': { 'color': '#CCCCCC' },
			'a:hover': { 'color': '#FFFFFF' }
			},
		transparent: 1,
		offsetTop: -2,
		onReplacement : function(){
			//alert('replace');
			//sizeVerticals();
			this.sIFR.doCompleteCheck();
			} 
	});
	
	// H3 (current)
	sIFR.replace(avenir_current, {
		selector: 'h3.current',
		css: { 
			'.sIFR-root': { 'color': sIFRcurrentColor },
			'a': { 'color': sIFRcurrentColor, 'text-decoration': 'none' },
			'a:link': { 'color': sIFRcurrentColor },
			'a:hover': { 'color': sIFRcurrentHover }
			},
		transparent: 1,
		offsetTop: -2,
		onReplacement : function(){
			//alert('replace');
			//sizeVerticals();
			this.sIFR.doCompleteCheck();
			} 
	});
	
}

sIFR.replacedCount = 0;
sIFR.doCompleteCheck = function(){
	this.replacedCount++;
	if(this.replacedCount>=this.replacements.length)
	{
		this.isDone = true;
		sizeVerticals();
		//alert('done');
	};
}; 


function showText(div) {
	// div = 'divAthleteNews'
	$(".athleteText:not(#" + div + ")").hide();
	$("#" + div).show();
	sizeVerticals();
}

function login_form() {
	document.formTW.submit();
	document.formTW.reset();
	$("#UserLogin").blur();
	$("#UserPwd").blur();
}


function sizeVerticals () {
	
	// detect which silo is shown
	var curSilo = $(".silo:visible").attr('id');
	// reset any inline height styles
	$("#mainContent").removeAttr('style');
	$(".silo").removeAttr('style');
	// re-show a silo that was visible
	$("#" + curSilo).show();
	
	
	// calculate content heights for vertical div heights
	/* CALCULATE ONLY THE HEIGHT IF THAT SILO IS SHOWN */
	leftSiloOneHeight = $("#leftSiloOne").is(':visible') ? $("#leftSiloOne").height() : 0;
	if($("#leftSiloOne").is(':visible') && $("#leftSiloOne").attr('pbtype')=='Headlines' && $("#rss").is(':visible'))
	{
		// on Headlines silo, if RSS link is there, add extra padding to bottom to compensate for absolutely positioned RSS div
		leftSiloOneHeight += 28;
	}
	leftSiloTwoHeight = $("#leftSiloTwo").is(':visible') ? $("#leftSiloTwo").height() : 0;
	
	
	/* CALCULATE THE HEIGHT OF BOTH SILOS 
	leftSiloOneHeight = $("#leftSiloOne").height();
	leftSiloTwoHeight = $("#leftSiloTwo").height();
	*/
	
	/*
	leftSiloOneHeight += parseInt($("#leftSiloOne").css('padding-top')) + $("#leftButtonOne").height();
	leftSiloTwoHeight += parseInt($("#leftSiloTwo").css('padding-top')) + $("#leftButtonTwo").height();
	*/
	leftSiloOneHeight += 58;
	leftSiloTwoHeight += 58;
	
	contentHeight = $("#mainContent").height();
	
	// Calculate viewport height and width
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	// Set vertical heights
	//alert($("#footer").height());
	var vertHeight = myHeight - $("#header").height() - $("#footer").height();
	//alert("vertHeight: " + vertHeight + ", contentHeight: " + contentHeight + ", leftSiloOneHeight: " + leftSiloOneHeight + ", leftSiloTwoHeight: " + leftSiloTwoHeight);
	var maxContentHeight = Math.max(vertHeight, contentHeight, leftSiloOneHeight, leftSiloTwoHeight);
	$("#mainContent").css('height', maxContentHeight + "px");
	var siloHeight = maxContentHeight - $("#leftButtonOne").height() - 27;
	$(".silo").css('height', siloHeight + "px");
}

function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
	
     if(key == 13)
	 {
		 login_form();
          return false;
	 }
     else
          return true;
}

/**
 * Function : dump()
 * Arguments: The data - array,hash(associative array),object
 *    The level - OPTIONAL
 * Returns  : The textual representation of the array.
 * This function was inspired by the print_r function of PHP.
 * This will accept some data as the argument and return a
 * text that will be a more readable version of the
 * array/hash/object that is given.
 * Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php
 */
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}