var promoCW2 = function(id)
{
	this.myid = id;
	this.updateTime = 50;
	this.imageArray = ["images/frontpage/crawler_promo_big.jpg", "images/frontpage/crawler_promo_big2.jpg"];
	//this.stringArray = strings;
	//this.fontArray = fonts
	//this.myTarget = target;
	this.currentOpacity = 100;
	this.activeImage = 0;
	this.activeTime = 0;
	this.minutes = new Date().getMinutes();
	//create the ticker
		// date and time box top = 184, bottom = 241`, left = 60, right = 140
	this.ticker = new promoTicker(id + ".ticker", "promo1_ticker", "&nbsp;", 219, (119 + 40), 259, (426 + 40));
	this.state = 0; //idle
	this.dateTimeColour = "#ffffff";
	this.myTimeStamp;
	this.toggle;
	
	this.setOpacity = function(imageId, opacity)
	{
		// update opacity -  opacity:0.4; filter:alpha(opacity=40)
		document.getElementById(imageId).style.opacity=opacity/100;
		//imageArray[activeImage].style.filter="alpha(opacity=50"+ currentOpacity + ")";
		document.getElementById(imageId).style.filter="alpha(opacity="+ opacity + ")";
	}

	this.nextTime = function()
	{
		this.activeTime++;
		if (this.activeTime >= this.timeArray.length)
		{
			this.activeTime = 0;
		}
	}
	
	this.prepNextImage = function()
	{
		// set the current image to the top and full opacity
		document.getElementById(this.myTarget+"_top").src = this.imageArray[this.activeImage];
		this.currentOpacity = 100;
		this.setOpacity(this.myTarget+"_top", this.currentOpacity);
		// set the next image on the bottom
		this.activeImage++;
		if (this.activeImage >= this.imageArray.length)
		{
			this.activeImage = 0;
		}
		document.getElementById(this.myTarget+"_bottom").src = this.imageArray[this.activeImage];
	}
	
	this.formatNowAsDate = function()
	{
		var now = new Date();
		var day = now.getDate().toString();
		var month = now.getMonth();
		switch(month)
		{
		case 1:
			month = "Jan";
			break;
		case 2:
			month = "Feb";
			break;
		case 3:
			month = "Mar";
			break;
		case 4:
			month = "Apr";
			break;
		case 5:
			month = "May";
			break;
		case 6:
			month = "Jun";
			break;
		case 7:
			month = "Jul";
			break;
		case 8:
			month = "Aug";
			break;
		case 9:
			month = "Sep";
			break;
		case 10:
			month = "Oct";
			break;
		case 11:
			month = "Nov";
			break;
		defalt:
			month = "Dec";
			break;			
		}
		var year = now.getYear().toString();
		year = year.substring(year.length - 2);
		return day + " " + month + " " + year;
	}
	
	this.formatNowAsTime = function()
	{
		var now = new Date();
		var hour = now.getHours().toString();
		var minute = now.getMinutes().toString();
		if (hour.length == 1)
		{
			hour = "0" + hour;
		}
		if (minute.length == 1)
		{
			minute = "0" + minute;
		}
		return (hour + ":" + minute);
	}
	this.initDateAndTime = function(color)
	{
		// date and time box top = 184, bottom = 241`, left = 60, right = 140
		this.updateDateAndTime(color);
		// how tall is the text?
		var timetall = document.getElementById('promo1_time').clientHeight;
		var datetall = document.getElementById('promo1_date').clientHeight;
		//spacing is
		var gap  = (40 - (timetall + datetall))/3;
		document.getElementById('promo1_time').style.top = (219 + gap) + "px";
		document.getElementById('promo1_date').style.top = (219 + (gap*2) + timetall) + "px";
		//how wide is the text
		var timewide = document.getElementById('promo1_time').clientWidth;
		var datewide = document.getElementById('promo1_date').clientWidth;
		document.getElementById('promo1_time').style.left = (51 + 40 + (((118-51)-timewide)/2)) + "px";
		document.getElementById('promo1_date').style.left = (51 + 40 + (((118-51)-datewide)/2)) + "px";
	}
	this.updateDateAndTime = function(color)
	{
		document.getElementById('promo1_date').innerHTML = "<SPAN style='font-size:12px; color:" + color + ";'>" + this.formatNowAsDate() + "</SPAN>";
		document.getElementById('promo1_time').innerHTML = "<SPAN style='font-size:18px; color:" + color + ";'>" + this.formatNowAsTime() + "</SPAN>";
	}
}
	
promoCW2.prototype.updateBPAnim = function()
{
	// are we running fast enough?
	var loopTime = (new Date().valueOf() - (this.myTimeStamp.valueOf() + this.updateTime));
	if (loopTime > this.updateTime*1.2)
	{
		//taking too long to get back to me
		this.updateTime += 2;
	}
	else if (loopTime < this.updateTime*1.1)
	{
		this.updateTime -= 1;
	}
	var string;
	var interval = new Date().valueOf() - this.myTimeStamp.valueOf();
	interval = interval*3/50;
	switch(this.state)
	{
		case 1: // init fade off the content for people with no java no strap is top
			this.currentOpacity = 100;
			var anchor = document.getElementById("promo1_anchor").href;
			anchor = anchor.charAt(anchor.length - 8);
			if (anchor == "T")
			{
				this.toggle = false;
			}
			else
			{
			
				this.toggle = true;
			}
			this.state++;
		break;	
		case 2: // run the xfade
			// fade down top 
			if (this.currentOpacity != 0)
			{
				this.currentOpacity-=interval;
				if (this.currentOpacity < 0)
				{	
					this.currentOpacity = 0;
				}
				this.setOpacity("promo1_top", this.currentOpacity);
				if (this.toggle == false)
				{
					this.setOpacity("promo1_date", 100 - this.currentOpacity);
					this.setOpacity("promo1_time", 100 - this.currentOpacity);				
				}
			}
			else
			{
				this.state++;
			}
		break;
		case 3: // start the first ticker
			if (this.toggle == false)
			{
				string = "<SPAN style='font-size:25px; color:#446479; font-family:HandelGotDBol;'>simpleText</SPAN><SPAN style='font-size:25px; color:#000000;'> is a complete out-of-the-box system for cost effective insertion of live text data into SD-SDI or HD-SDI broadcast. </SPAN>";
				string = string + "<SPAN style='font-size:25px; color:#446479; font-family:HandelGotDBol;'>simpleText</SPAN><SPAN style='font-size:25px; color:#000000;'> hardware provides a scrolling text ticker, static text fields and native time and date elements. </SPAN>";
				string = string + "<SPAN style='font-size:25px; color:#446479; font-family:HandelGotDBol;'>simpleText</SPAN><SPAN style='font-size:25px; color:#000000;'> hardware provides two graphics layers for text backgrounds or channel idents.</SPAN>";
			}
			else
			{
				string = "<SPAN style='font-size:25px; color:#000000; font-family:HandelGotDBol;'>@eyeheight: #TVtweetCaster</SPAN><SPAN style='font-size:25px; color:#ffffff;'> is a complete out-of-the-box system for cost effective insertion of tweets into SD-SDI or HD-SDI broadcast. </SPAN>";
				string = string + "<SPAN style='font-size:25px; color:#000000; font-family:HandelGotDBol;'>@eyeheight: #TVtweetCaster</SPAN><SPAN style='font-size:25px; color:#ffffff;'> includes software to download twitter content and provides full user filtering of tweets prior to broadcast. </SPAN>";
				string = string + "<SPAN style='font-size:25px; color:#000000; font-family:HandelGotDBol;'>@eyeheight: #TVtweetCaster</SPAN><SPAN style='font-size:25px; color:#ffffff;'> hardware provides a scrolling tweet ticker and native time and date elements. </SPAN>";
				string = string + "<SPAN style='font-size:25px; color:#000000; font-family:HandelGotDBol;'>@eyeheight: #TVtweetCaster</SPAN><SPAN style='font-size:25px; color:#ffffff;'> hardware also provides two graphics layers for text backgrounds or channel idents.</SPAN>";
			}
			this.ticker.updateText(string);
			this.ticker.init();
			this.state++;
		break;
		case 4: // run first ticker
			if (this.ticker.running)
			{
				this.ticker.updateTicker();
			}
			else
			{
				this.state++;
			}
		break;
		case 5: // fade the strap off - fade up top
			if (this.currentOpacity != 100)
			{
				this.currentOpacity+=interval;
				if (this.currentOpacity > 100)
				{	
					this.currentOpacity = 100;
				}
				this.setOpacity("promo1_top", this.currentOpacity);
				if (this.toggle == false)
				{
					this.setOpacity("promo1_date", 100 - this.currentOpacity);
					this.setOpacity("promo1_time", 100 - this.currentOpacity);				
				}
			}
			else
			{
				this.state++;
			}	
		break;
		case 6: // setup fade between slides
			//top is visible
			if (this.toggle == false)
			{
				document.getElementById("promo1_bottom").src = "images/frontpage/crawler_promo_big2_no_strap.jpg";
			}
			else
			{
				document.getElementById("promo1_bottom").src = "images/frontpage/crawler_promo_big_no_strap.jpg";
			}
			this.state++;
		break;
		case 7: // run xfade - fade down top
			if (this.currentOpacity != 0)
			{
				this.currentOpacity-=interval;
				if (this.currentOpacity < 0)
				{	
					this.currentOpacity = 0;
				}
				this.setOpacity("promo1_top", this.currentOpacity);				
			}
			else
			{
				this.state++;
			}
		break;
		case 8: // setup next strap
			// top is invisible
			if (this.toggle == false)
			{
				document.getElementById("promo1_top").src = "images/frontpage/crawler_promo_big2.jpg";
				document.getElementById("promo1_anchor").href = "TVtweetCaster.asp";
			}
			else
			{
				document.getElementById("promo1_top").src = "images/frontpage/crawler_promo_big.jpg";
				document.getElementById("promo1_anchor").href = "simpleText.asp";
			}
			this.state++;
		break;
		case 9: // run xfade
			if (this.currentOpacity != 100)
			{
				this.currentOpacity+=interval;
				if (this.currentOpacity > 100)
				{	
					this.currentOpacity = 100;
				}
				this.setOpacity("promo1_top", this.currentOpacity);
				if (this.toggle)
				{
					this.setOpacity("promo1_date", this.currentOpacity);
					this.setOpacity("promo1_time", this.currentOpacity);				
				}
			}
			else
			{
				this.state++;
			}
		break;
		case 10: // setup next ticker
		if (this.toggle == false)
		{
			string = "<SPAN style='font-size:25px; color:#000000; font-family:HandelGotDBol;'>@eyeheight: #TVtweetCaster</SPAN><SPAN style='font-size:25px; color:#ffffff;'> is a complete out-of-the-box system for cost effective insertion of tweets into SD-SDI or HD-SDI broadcast. </SPAN>";
			string = string + "<SPAN style='font-size:25px; color:#000000; font-family:HandelGotDBol;'>@eyeheight: #TVtweetCaster</SPAN><SPAN style='font-size:25px; color:#ffffff;'> includes software to download twitter content and provides full user filtering of tweets prior to broadcast. </SPAN>";
			string = string + "<SPAN style='font-size:25px; color:#000000; font-family:HandelGotDBol;'>@eyeheight: #TVtweetCaster</SPAN><SPAN style='font-size:25px; color:#ffffff;'> hardware provides a scrolling tweet ticker and native time and date elements. </SPAN>";
			string = string + "<SPAN style='font-size:25px; color:#000000; font-family:HandelGotDBol;'>@eyeheight: #TVtweetCaster</SPAN><SPAN style='font-size:25px; color:#ffffff;'> hardware also provides two graphics layers for text backgrounds or channel idents.</SPAN>";
		}
		else
		{
				string = "<SPAN style='font-size:25px; color:#446479; font-family:HandelGotDBol;'>simpleText</SPAN><SPAN style='font-size:25px; color:#000000;'> is a complete out-of-the-box system for cost effective insertion of live text data into SD-SDI or HD-SDI broadcast. </SPAN>";
				string = string + "<SPAN style='font-size:25px; color:#446479; font-family:HandelGotDBol;'>simpleText</SPAN><SPAN style='font-size:25px; color:#000000;'> hardware provides a scrolling text ticker, static text fields and native time and date elements. </SPAN>";
				string = string + "<SPAN style='font-size:25px; color:#446479; font-family:HandelGotDBol;'>simpleText</SPAN><SPAN style='font-size:25px; color:#000000;'> hardware provides two graphics layers for text backgrounds or channel idents.</SPAN>";			
		}
			this.ticker.updateText(string);
			this.ticker.init();
			this.state++;
		break;
		case 11: // run second ticker
			if (this.ticker.running)
			{
				this.ticker.updateTicker();
			}
			else
			{
				this.state++;
			}
			break;
		case 12: // fade off strap
			if (this.currentOpacity != 0)
			{
				this.currentOpacity-=interval;
				if (this.currentOpacity < 0)
				{	
					this.currentOpacity = 0;
				}
				this.setOpacity("promo1_top", this.currentOpacity);
				if (this.toggle)
				{
					this.setOpacity("promo1_date", this.currentOpacity);
					this.setOpacity("promo1_time", this.currentOpacity);				
				}
			}
			else
			{
				this.state++;
			}
		break;
		case 13: // setup fade back to start
			// top is invisible
			if (this.toggle == false)
			{
				document.getElementById("promo1_top").src = "images/frontpage/crawler_promo_big_no_strap.jpg";
			}
			else
			{
				document.getElementById("promo1_top").src = "images/frontpage/crawler_promo_big2_no_strap.jpg";
			}
			this.state++;
		break;
		case 14: // run the xfade
			if (this.currentOpacity != 100)
			{
				this.currentOpacity+=interval;
				if (this.currentOpacity > 100)
				{	
					this.currentOpacity = 100;
				}
				this.setOpacity("promo1_top", this.currentOpacity);				
			}
			else
			{
				if (this.toggle == false)
				{
					document.getElementById("promo1_bottom").src = "images/frontpage/crawler_promo_big.jpg";
					document.getElementById("promo1_anchor").href = "simpleText.asp";
				}
				else
				{
					document.getElementById("promo1_bottom").src = "images/frontpage/crawler_promo_big2.jpg";
					document.getElementById("promo1_anchor").href = "TVtweetCaster.asp";
				}
				this.state++;
			}
		break;			
		default:
			this.state = 2;
		break;
	}

	if (new Date().getMinutes() != this.minutes)
	{
		this.updateDateAndTime(this.dateTimeColour);
		this.minutes = new Date().getMinutes;
	}
	this.myTimeStamp = new Date();	
	//document.getElementById('debug').innerHTML = this.state;
	setTimeout(this.myid+".updateBPAnim()",this.updateTime); 
}

promoCW2.prototype.start = function()
{
		//init the date and time
		//**********************
		this.setOpacity('promo1_date', 0);
		this.setOpacity('promo1_time', 0);
		this.initDateAndTime(this.dateTimeColour);	
		
		this.state = 1;
		this.myTimeStamp = new Date();
		setTimeout(this.myid+".updateBPAnim()",this.updateTime); 
}

promoCW2.prototype.state = function()
{
	return this.state;
}







