﻿
var imageList = null;
var index = 0;
var interval = 4000;
function loadImage( url, callback )
{
	var img = new Image();
	img.src = url;
	if( img.complete )
	{// already loaded, just call callback and return;
		callback.call( img );
		return;
	}
	img.onload = function(){
		callback.call( img );
	}
}

// callback function
function	onImageLoaded(){
	if( index==0 )
	{
		divElem = document.getElementById("awards_holder");
		var first = imageList[0];
	
		divElem.innerHTML = '<a href="'+first[2]+'" id="partner_ref" target="_blank"><img id="partner" src="' + first[3]+'" /></a>';

	}

	if( imageList.length > 1 )
		setTimeout( loopShow, interval );
}

function addImage( _title, _name, _url, _image ){
	
	if( imageList==null )
		imageList = new Array();
	
	imageList[imageList.length] = new Array(_title, _name, _url, _image);	
}

function startAni(){
	
	if( imageList==null )
		return;
	if( imageList.length < 1 )
		return;

	
	loadImage( imageList[index][3], onImageLoaded );
}

function loopShow(){
	clearTimeout();
	
	if( index >= imageList.length )
		index = 0;
	showImage( imageList[index] );	
	loadImage( imageList[index++][3], onImageLoaded );
}

function showImage( imageInfo ){
	var elem = document.getElementById( "partner" );
	var elem_ref = document.getElementById("partner_ref");
	
	if( elem!=null && elem_ref!=null )
	{
		
		elem.src = imageInfo[3];
		elem.alt = imageInfo[0];
		elem_ref.href = imageInfo[2];
		elem_ref.target = "_blank";
	}
}
function ajaxFunction()
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	else
	  {
		alert("Your browser does not support XMLHTTP!");
	  }
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
			document.myForm.time.value=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","awards/awards.php",false);
	xmlhttp.send(null);
	document.write( xmlhttp.responseText );
}

