function goto(url) 
{
	document.location.href = document.getElementsByTagName('base')[0].href + url;
}

currentPos = 0;

function sponsorNext()
{
	if (currentPos != parseInt($('sponsors-space').className)-2)
	{
		currentPos++;
		$('sponsors-space').style.marginLeft = -(128*currentPos) + "px";
	}
	
	clearTimeout(theTimeout);
}

function sponsorPrev()
{
	if (currentPos != 0)
	{
		currentPos--;
		$('sponsors-space').style.marginLeft = -(128*currentPos) + "px";
	}
	
	clearTimeout(theTimeout);
}

var theTimeout;

function sponsorAuto ()
{
	if (currentPos != parseInt($('sponsors-space').className)-2)
	{
		currentPos++;
		$('sponsors-space').style.marginLeft = -(128*currentPos) + "px";
		
		theTimeout = setTimeout(function () { sponsorAuto(); }, 5000);
	}	
}

// FONT REPLACEMENT

Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
Prototype.Browser.IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 7;
Prototype.Browser.IE8 = Prototype.Browser.IE && !Prototype.Browser.IE6 && !Prototype.Browser.IE7;

/*if(!Prototype.Browser.IE6)
{
	Cufon.replace([
		'div#main div#content div#content-text h1'
	]);
	
	Cufon.replace([
		'div.control-bar label',
		'div.control-bar button'
	]);
}*/

Event.observe(window, 'load', function() {
	Cufon.replace('h1', { fontFamily: 'Tektron' });
});

Cufon.replace('div#days', { fontFamily: 'Digital' });
Cufon.replace('div#hours', { fontFamily: 'Digital' });
Cufon.replace('div#minutes', { fontFamily: 'Digital' });
Cufon.replace('div#seconds', { fontFamily: 'Digital' });

// COUNTDOWN
function cdtime(container, targetdate){
if (!document.getElementById || !document.getElementById(container)) return
this.container=document.getElementById(container)
this.currentTime=new Date()
this.targetdate=new Date(targetdate)
this.timesup=false
this.updateTime()
}

cdtime.prototype.updateTime=function(){
var thisobj=this
this.currentTime.setSeconds(this.currentTime.getSeconds()+1)
setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
}

cdtime.prototype.displaycountdown=function(baseunit, functionref){
this.baseunit=baseunit
this.formatresults=functionref
this.showresults()
}

cdtime.prototype.showresults=function(){
var thisobj=this


var timediff=(this.targetdate-this.currentTime)/1000 //difference btw target date and current date, in seconds
if (timediff<0){ //if time is up
this.timesup=true
this.container.innerHTML=this.formatresults()
return
}
var oneMinute=60 //minute unit in seconds
var oneHour=60*60 //hour unit in seconds
var oneDay=60*60*24 //day unit in seconds
var dayfield=Math.floor(timediff/oneDay)
var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour)
var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute)
var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute))
if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
hourfield=dayfield*24+hourfield
dayfield="n/a"
}
else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
minutefield=dayfield*24*60+hourfield*60+minutefield
dayfield=hourfield="n/a"
}
else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
var secondfield=timediff
dayfield=hourfield=minutefield="n/a"
}
this.container.innerHTML=this.formatresults(dayfield, hourfield, minutefield, secondfield)
setTimeout(function(){thisobj.showresults()}, 1000) //update results every second
}

// COUNTDOWN OUTPUT
function showCountdown ()
{
	if (this.timesup==false)
	{
		if (arguments[0] < 10) arguments[0] = "0" + arguments[0];
		if (arguments[1] < 10) arguments[1] = "0" + arguments[1];
		if (arguments[2] < 10) arguments[2] = "0" + arguments[2];
		if (arguments[3] < 10) arguments[3] = "0" + arguments[3];
	
		$('days').innerHTML = arguments[0];
		$('hours').innerHTML = arguments[1];
		$('minutes').innerHTML = arguments[2];
		$('seconds').innerHTML = arguments[3];
	
		Cufon.replace('div#days', { fontFamily: 'Digital' });
		Cufon.replace('div#hours', { fontFamily: 'Digital' });
		Cufon.replace('div#minutes', { fontFamily: 'Digital' });
		Cufon.replace('div#seconds', { fontFamily: 'Digital' });
	}
	else
	{
		$('counter').style.display = "none";
	}	
}

// SCROLLER
var pWidth = 0;
var speed = 1; // change scroll speed with this value
/**
 * Get a collection of all of the objects of a particular type, can pass in an object that they should be collected from.
 */
function getElementsByTagNames(list,obj) {
  if (!obj) var obj = document;
  var tagNames = list.split(',');
  var resultArray = new Array();
  for (var i=0;i<tagNames.length;i++) {
    var tags = obj.getElementsByTagName(tagNames[i]);
    for (var j=0;j<tags.length;j++) {
      resultArray.push(tags[j]);
    };
  };
  var testNode = resultArray[0];
  if(!testNode){
    return [];
  };
  if(testNode.sourceIndex){
    resultArray.sort(function(a,b){
      return a.sourceIndex - b.sourceIndex;
    });
  }else if(testNode.compareDocumentPosition){
    resultArray.sort(function(a,b){
      return 3 - (a.compareDocumentPosition(b) & 6);
    });
  };
  return resultArray;
}
 
/**
 * Initialize the marquee, and start the marquee by calling the marquee function.
 */
function init(){
  var div = document.getElementById("image-bar");
  div.style.overflow = 'hidden';
  
  var ps = getElementsByTagNames('img',div);
  for(var j=0;j<ps.length;j++){
    pWidth += ps[j].offsetWidth;
  }
 
  var startdiv = document.getElementById("image-bar-ani");
  startdiv.style.width = pWidth+'px';
  div.scrollLeft = 0;
  setTimeout("scrollFromSide()",50);
}
 
var go = 0;
var timeout = '';
 
/**
 * This is where the scroll action happens.
 * Recursive method until stopped.
 */
function scrollFromSide(){
  clearTimeout(timeout);
  var el = document.getElementById("image-bar");

//$('test').innerHTML = el.scrollLeft + " / " + (pWidth-document.viewport.getWidth());

  if(el.scrollLeft >= pWidth-document.viewport.getWidth()){
    el.scrollLeft = 0;
  };
  el.scrollLeft = el.scrollLeft+speed;
  if(go == 0){
    timeout = setTimeout("scrollFromSide()",50);
  };
}
 
/**
 * Set the stop variable to be true (will stop the marquee at the next pass).
 */
function stop(){
  go = 1;
  timeout = '';
}
 
/**
 * Set the stop variable to be false and call the marquee function.
 */
function startit(){
  go = 0;
  scrollFromSide();
}

window.onload = function () {
	init();
	
}
