
/////////////////////////// NewsTicker ////////////////////////////////
function NewsTicker()
{
	///State of the ticker:
	this.iCurrentItem = 0
	this.iCurrentLetter = 0
	
	///Ticker tweakers:
	this.iLetterWaitMs = 100
	this.iHeadlineWaitMs = 3*1000
	
	///Global reference for callbacks (only allows one per page!)
	document.newsTicker = this
	
	this.start = function()
	{
		if(this.tickerItems.length == 0)
		{
			document.all.TickerWrapper.style.display = "none"
		}
		else
		{
			//Fire it up:
			setInnerText(document.all.NewsTicker, "")
			this.iCurrentItem = 0
			this.iCurrentLetter = 0

			this.tick()
		}
	}
	
	this.tick = function()
	{
		if(this != document.newsTicker)
			return document.newsTicker.tick()

		var item = this.tickerItems[this.iCurrentItem]

		if(this.iCurrentLetter == 0)
		{
			///First tick -
			setInnerText(document.all.NewsTicker, "")
			document.all.NewsTicker.href 
				= document.all.MoreNewsLink.href
				= item.strUrl
			document.all.NewsTicker.target 
				= document.all.MoreNewsLink.target
				= item.strTarget
		}
		
		//the easy ie code: document.all.NewsTicker.innerText += item.strTitle.substring(this.iCurrentLetter, this.iCurrentLetter+1)
		//Standards Compatible Version to Please Everyone:
		document.all.NewsTicker.innerHTML += htmlEncode(item.strTitle.substring(this.iCurrentLetter, this.iCurrentLetter+1))
		
		this.iCurrentLetter++
		//window.status = "["+item.strTitle.length+","+this.iCurrentLetter+"] " + window.status
		if(this.iCurrentLetter < item.strTitle.length)
			window.setTimeout(this.tick, this.iLetterWaitMs)
		else
		{
			if(this.tickerItems.length > 1)
			{
				this.iCurrentLetter = 0
				window.setTimeout(this.cycle, this.iHeadlineWaitMs)
			}
		}
	}
	
	this.cycle = function()
	{
		if(this != document.newsTicker)
			return document.newsTicker.cycle()

		this.iCurrentItem++
		
		if(this.iCurrentItem >= this.tickerItems.length)
		{
			this.iCurrentItem = 0
		}

		window.setTimeout(this.tick, this.iLetterWaitMs)
	}

	this.tickerItems = new Array()

	this.addItem = function(tickerItem)
	{
		this.tickerItems.push(tickerItem)
		return tickerItem
	}
}

function TickerItem(strTitle, strUrl, strTarget)
{
	this.strTitle = strTitle
	this.strUrl = strUrl
	if(typeof(strTarget) =="undefined")
		strTarget = ""
		
	this.strTarget = strTarget
}

function CaseStudiesScroller()
{
	this.caseStudies = new Array()

	this.addItem = function(caseStudy)
	{
		this.caseStudies.push(caseStudy)
		return caseStudy
	}
	
	this.start = function()
	{
		///Shuffle the items (http://www.mickweb.com/javascript/arrays/userDefinedSortingArrays5.html):
		var times = 10
		var i,j,t,l = this.caseStudies.length;
		while(times--)
		{
			with(Math)
			{
				i = floor(random()*l)
				j = floor(random()*l)
			}
			t = this.caseStudies[i]
			this.caseStudies[i] = this.caseStudies[j]
			this.caseStudies[j] = t
		}
		
		this.transition()
	}
	
	///Global reference for callbacks (only allows one per page!)
	document.caseStudiesScroller = this

	this.iCurrentItem = 0
	
	this.iScrollTimeoutMs = 1000*8
	
	this.transition = function()
	{
		if(this != document.caseStudiesScroller)
			return document.caseStudiesScroller.transition()
		
		var item = this.caseStudies[this.iCurrentItem]

		setInnerText(document.all.caseStudyHeadline, item.strTitle)

		if(isIe6())
		{
			//add the filter to the style tag:
			document.all.caseStudyBody.style.filter = "progid:DXImageTransform.Microsoft.Fade(duration=1)";
			document.all.caseStudyBody.filters[0].apply();
		}

		document.all.caseStudyBody.innerHTML = item.strBody + "<div><a href='" + item.strUrl + "' target='" + item.strTarget + "' id='caseStudyLink'>Details...</a></div>"
		
		document.all.caseStudyBody.style.backgroundImage = "url(" + item.strImage + ")"
		
		if(isIe6())
			//play the filter
			document.all.caseStudyBody.filters[0].play();
		
		this.iCurrentItem = (this.iCurrentItem + 1 ) % this.caseStudies.length
		
		if(this.caseStudies.length > 1)
			window.setTimeout(this.transition, this.iScrollTimeoutMs)
	}
}

function CaseStudy(strTitle, strBody, strImage, strUrl, strTarget)
{
	this.strTitle = strTitle
	this.strBody = strBody
	this.strImage = strImage
	this.strUrl = strUrl
	
	if(typeof(strTarget) =="undefined")
		strTarget = ""
		
	this.strTarget = strTarget
}
