﻿//-- declarations

var Animation = {};
var Initializers = {};

var Type =
{
	//-- Methods
	IsUndefined : function(oType) {return(typeof(object) == "undefined");}
}

//-- methods

function Initialize()
{
	var cDivs = document.getElementById("mainnavbox").getElementsByTagName("DIV");
	var cAs;
	var eDiv;
	var eA;

	for(var i=0; i<cDivs.length; i++)
	{
		eDiv = cDivs[i];

		if(eDiv.className == "item")
		{
			eDiv.onclick = Item_Click;
			cAs = eDiv.getElementsByTagName("DIV")[0].getElementsByTagName("A");

			for(var j=0; j<cAs.length; j++)
			{
				eA = cAs[j];
				eA.onclick = SubItem_Click;
			}
		}
	}

	for(method in Initializers)
		Initializers[method].call();
}

function WriteAnimatedMasthead(bIsLanding)
{
   document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="743" height="274" id="CityPlace_Masthead" align="middle">\n');
   document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
   document.write('<param name="movie" value="media/' + ((bIsLanding == true) ? 'landing' : 'interior') + 'masthead.swf" />\n');
   document.write('<param name="loop" value="false" />\n');
   document.write('<param name="quality" value="best" />\n');
   document.write('<param name="wmode" value="transparent" />\n');
   document.write('<param name="bgcolor" value="#ffffff" />\n');
   document.write('<embed src="media/' + ((bIsLanding == true) ? 'landing' : 'interior') + 'masthead.swf" loop="false" quality="best" wmode="transparent" bgcolor="#ffffff" width="743" height="274" name="AnimatedMasthead" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');
   document.write('</object>\n');

}

//-- event handlers

function Item_Click(e)
{
	var eItemArrow = this.getElementsByTagName("IMG")[0];
	var isRollout = eItemArrow.src.indexOf("_d") != -1;

	var eSubItemBox = this.getElementsByTagName("DIV")[0];
	var iSubItemCount = eSubItemBox.getElementsByTagName("A").length;

	//FF cannot handle animated masthead with animated navbar (HACK - assert FF if [e] not undefined)
	if(e)
	{
		//sync eItemArrow
		eItemArrow.src = "media/nav_" + (isRollout ? "u" : "d") + ".gif";

		//sync eSubItemBox
		eSubItemBox.style.height = (isRollout ? 0 : (18 * iSubItemCount) + 5) + "px";
	}
	else
	{
		e = window.event;

		if(Type.IsUndefined(Animation.NavRollout))
		{
			//prevent concurrent execution
			Animation.NavRollout = new Animator();

			//sync eItemArrow
			eItemArrow.src = "media/nav_" + (isRollout ? "u" : "d") + ".gif";

			//sync eSubItemBox
			var iHeightMin = 0;
			var iHeightMax = ((18 * iSubItemCount) + 5);

			var iOpacityMin = 0;
			var iOpacityMax = 1;

			with(Animation.NavRollout)
			{
				with(options)
				{
					duration = Math.max(200, (36 * iSubItemCount));
					onComplete = Animation_OnComplete;
				}

				addSubject(new NumericalStyleSubject(eSubItemBox, "height", (isRollout ? iHeightMax : iHeightMin), (isRollout ? iHeightMin : iHeightMax)));
				addSubject(new NumericalStyleSubject(eSubItemBox, "opacity", (isRollout ? iOpacityMax : iOpacityMin), (isRollout ? iOpacityMin : iOpacityMax)));

				play();
			}
		}
	}
}

function SubItem_Click(e)
{
	if(!e) e = window.event;

	e.cancelBubble = true;
}

//-- callbacks

function Animation_OnComplete()
{
	if(!Type.IsUndefined(this))
		delete this;
}
