//Initiating jQuery to work with Prototype;
//var $ = jQuery.noConflict(); located inside jquery-1.3.2.min.js file

$(document).ready(function() { onDocumentLoad(); });
$(window).load(function() { onWindowLoad(); });

//Global Variables

/*
 * Standard page loading functions for prototype / jQuery
 */
function onDocumentLoad(){
	//removes the last li tag in the advertising menu to remove the last diamond
	$('#advertisingWrap li:last').hide();
	$('#advertisingWrap li:not(:last)').show();//doing this so it loads nicer

	//removes the last li tag in the footer menu to remove the last |
	$('#footerMenu li:last').hide();
	$('#footerMenu li:not(:last)').show();//doing this so it loads nicer

	$(".linkButtonMiddle p a:empty").parent().hide();
	$(".linkButtonMiddle p a:not(:empty)").parent().show();

	startList('mainMenuUl');

	/*$('#bannerFlash').html(flashBanner);*/

	if($("#headerFlashViewFinder").length > 0){
		$('#headerFlashViewFinder').html(flashHeaderVF);
	}

	if($("#headerFlash").length > 0){
		$('#headerFlash').html(flashHeader);
	}
}

//Stuff put into this function doesnt run until the entire document is loaded flash and all
function onWindowLoad(){
	//Updates the show home count based on the quantity of showhomes
	if($('.showhomes').length >= 2) {
		$('#showhomeWrap h2').html($('.showhomes').length+' Impressive show homes');
	} else if ($('.showhomes').length == 1) {
		$('#showhomeWrap h2').html('Impressive<br />show home');
	}

	$('a.external').attr('target','_blank');
	$('a.nolink').attr('href','javascript:void(0)');

	if($('#advertisingWrap ul li').html().length >= 1){
//		$('#advertisingWrap').css({'height':'20px','margin-top':'0px'});
//		$('#coopersCrossingLogo').css({'margin-top':'-64px'});
		$('#advertisingWrap').css({'height':'44px','margin-top':'30px'});
		$('#coopersCrossingLogo').css({'margin-top':'-110px'});
	}

	//$('#mainContentWrap').fadeOut(100).delay(500).slideDown('slow');
	//window.setTimeout("$('#mainContentWrap').slideDown('slow')", 1000);
	//$('#mainContentWrap').fadeIn('slow');
}

startList = function(name)
{
	var navId = name;

	if ( document.all && document.getElementById ) {
		navRoot = document.getElementById( navId );

		for ( i = 0; i < navRoot.childNodes.length; i++ ) {
			node = navRoot.childNodes[i];

			if ( node.nodeName == 'LI' && node.className.indexOf('level1') != -1 ) {
				node.onmouseover = function() {
					this.className+=" hover";
				}

				node.onmouseout = function() {
					this.className=this.className.replace( ' hover', '' );
				}
			}

		}
	}
}