// banner class

//------------------------------------------

//==================================================================

//	Create Element / DOM Object

//==================================================================





//------------------------------------------------------------------

//	class

//------------------------------------------------------------------

function Banner(id){

	//--------------------------------------------------------------

	// variables

	//--------------------------------------------------------------

		var isIE = window.ActiveXObject ? true : false;

		

		this._count		= 0;

		this._time		= 5000;

		this._current	= 0;

		

		baseStyle			= "text-align:center;width:19px;height:13px;padding-top:1px;font-size:10px;font-family:Verdana;font-weight:bold;margin-left:5px;float:left;border:solid #FFFFFF 1px;"

		this._offState		= baseStyle + "background:#002888;color:#FFFFFF";

		this._onState		= baseStyle + "background:#FBCF00;color:#002888";





	//--------------------------------------------------------------

	// arrays

	//--------------------------------------------------------------

		this._details	= [

			{

				image:"otr-2010-sponsor-en.jpg",

				x:171,

				y:113,

				type:"learnmore-white-arrow.gif",

				link:"http://www.carrythetorch.com/index.asp"

			},

			{

				image:"amateursport_js.jpg",

				x:140,

				y:141,

				type:"bluebutton.jpg",

				link:"/sponsorship/amateur/index.html"

			},

			{

				image:"paintingcompitition_js.jpg",

				x:292,

				y:156,

				type:"bluebutton.jpg",

				link:"/sponsorship/paintingcompetition/index.html"				

			},

			{

				image:"canadianopen_js.jpg",

				x:200,

				y:141.9,

				type:"bluebutton.jpg",

				link:"/sponsorship/golf/index.html"				

			}

		]



	//--------------------------------------------------------------

	// objects

	//--------------------------------------------------------------





	//--------------------------------------------------------------

	// constructor

	//--------------------------------------------------------------





	//--------------------------------------------------------------

	// methods

	//--------------------------------------------------------------

	

	//	init

	this.init	= function()

	{

		this._count		= this._details.length;	

		this._banner	= this.getObject(id);

				

		this.addNavigation();				

		this.setBanner(this._current);

		

		this.bannerRotation 	= setInterval("Banner.nextBanner()", this._time );	

	}

	

	// add navigation

	this.addNavigation	= function()

	{

		html	= "<div id=\"bannerNav\" style=\"position:absolute;left:16px;top:142px;z-index:900;cursor:pointer;\">";

		for(n = 0; n < this._count; n++)

		{

			style	= n == this._current ? this._onState : this._offState;

			html	+= "<div style=\"" + style + "\"  onclick=\"javascript:Banner.clickBanner(" + n + ")\" onmouseover=\"javascript:Banner.rollOver(this)" + "\"   onmouseout=\"javascript:Banner.rollOut(this, " + n + ")" + "\">" + (n + 1) + "</div>";

		}	

		html += "</div>";

		

		this._banner.innerHTML	+= html;

	}

	

	this.nextBanner			= function()

	{

		this._current < (this._count - 1) ? this._current++ : this._current = 0;

		this.setBanner(this._current)

	}

	

	this.resetNavigation	= function()

	{

		nav	= this.getObject('bannerNav');

		for(n = 0; n < this._count; n++)

		{

			this.rollOut(nav.childNodes[n], n);

		}

	}

	

	this.clickBanner	= function(n)

	{

		clearInterval(this.bannerRotation);

		this.setBanner(n);

	}

	

	// set banner

	this.setBanner	= function(n)

	{

		

		current	= this._details[n];

		html	= "<img id=\"flashBannerImage\" src=\"library/" + current.image + "\" style=\"position:absolute;left:0px;top:0px;z-index:700\" />";

		

		this._current			= n;

		

		!this.getObject('flashBannerImage')  ? this._banner.innerHTML	+= html : this.getObject('flashBannerImage').src	= "library/" + current.image;		

		

		this.resetNavigation();	

		this.addButton();	

	}

	

	// roll over

	this.rollOver	= function(obj)

	{

		obj.style.backgroundColor	= "#FBCF00";

		obj.style.color				= "#002888";		

	}

	

	// roll out

	this.rollOut	= function(obj, n)

	{

		obj.style.backgroundColor	= n == this._current ? "#FBCF00" : "#002888";

		obj.style.color				= n == this._current ? "#002888" : "#FFFFFF";		

	}

	

	// add button

	this.addButton	= function()

	{

		current		= this._details[this._current]

		button		= current.type;

		link		= current.link;

		

		html		= "<div id=\"flashBannerButton\"><a href=\"" + link + "\"><img src=\"library/" +  button + "\" border=\"0\" style=\"position:absolute;left:" + current.x + "px;top:" + current.y + "px;z-index:800;\" /></a></div>";



		!this.getObject('flashBannerButton')  ? this._banner.innerHTML	+= html : this.getObject('flashBannerButton').innerHTML	= html;

	}

	

	// get object

	this.getObject = function(id)

	{

		//	retrieve object

		//------------------------------

		if (document.getElementById){this._obj = document.getElementById(id);}

		else if (document.all){this._obj = document.all[id];}

		else if (document.layers){if (document.layers[id]){this._obj = document.layers[id];}}



		//	return object to caller

		//------------------------------

		return this._obj;

	}

	

	this.init();

}

