// all logos must measure 100 pixels wide and 100 pixels tall
var sponsor_logo_array=[['/sponsor_logos/esr_logo_square.png','http://www.easystreetrecumbents.com'],['/sponsor_logos/medici_logo.gif','http://www.caffemedici.com'],['/sponsor_logos/sam_placette_100.png','http://samplacette.com'],['/sponsor_logos/thunderbird.jpg','http://www.thunderbirdcoffee.com/'],['/sponsor_logos/cgood_studios_100.jpg','http://www.cynthiagoodstudios.com/'],['/sponsor_logos/be_kind_100.jpg','http://www.bekindtocyclists.com'],['/sponsor_logos/cyclistlaw_100.jpg','http://www.cyclistlaw.com'],['/sponsor_logos/the_peddler_100x100.png','http://www.peddlerbike.com'],['/sponsor_logos/Tart_100x100.png','http://www.tart-yogurt.com'],['/sponsor_logos/mj_logo.jpg','http://www.mellowjohnnys.com/']];

var xoffset=425;

function start_scroll() {
   new mq('sponsor_scroller',sponsor_logo_array,100);
   mqScroll(mqr); // must come last
}
function start_rotate() {
   var sponsor_logo_length = sponsor_logo_array.length;
   var random_index = Math.floor(Math.random()*sponsor_logo_length);
   for (var j = 0; j < random_index; j++) {
	sponsor_logo_array.push(sponsor_logo_array[0]);
	sponsor_logo_array.shift();
   }

   new image_rotator('sponsor_rotator',sponsor_logo_array,100);
   rotate(rotate_array); // must come last
}
window.onload = function() {start_rotate();}

var mqr = []; 
var rotate_array = [];

function mq(id,ary,wid){
	this.mqo=document.getElementById(id); 
	var heit = this.mqo.style.height; 

	this.mqo.onmouseout=function() {
		mqScroll(mqr);
	}; 
	this.mqo.onmouseover=function() {
		clearTimeout(mqr[0].TO);
	}; 
	this.mqo.ary=[]; 
	var maxw = ary.length; 
	
	for (var i=0;i<maxw;i++) {
                this.mqo.ary[i]=document.createElement('div');
		this.mqo.ary[i].innerHTML='<a href="' +  ary[i][1] + '"><img src="' + ary[i][0] + '"/></a>';
//		this.mqo.ary[i]=document.createElement('img'); 
//		this.mqo.ary[i].src=ary[i][0]; 
		this.mqo.ary[i].style.position = 'absolute'; 
		this.mqo.ary[i].style.left = (xoffset + (wid+10)*i)+'px'; 
		this.mqo.ary[i].style.width = wid+'px'; 
		this.mqo.ary[i].style.height = heit; 

		this.mqo.appendChild(this.mqo.ary[i]);
	} 
	mqr.push(this.mqo);
} 

function mqScroll(mqr){
	if (!mqr) return; 
	for (var j=mqr.length - 1; j > -1; j--) {
		maxa = mqr[j].ary.length; 
		for (var i=0;i<maxa;i++){
			var x = mqr[j].ary[i].style;  
			x.left=(parseInt(x.left,10)-1)+'px';
		} 
		var y = mqr[j].ary[0].style; 
		if (parseInt(y.left,10)+parseInt(y.width,10)<xoffset) {
			var z = mqr[j].ary.shift(); 
			z.style.left = (parseInt(z.style.left) + parseInt(z.style.width)*maxa) + (mqr.length+2)*10 + 'px'; 
			mqr[j].ary.push(z);
		}

	} 

	mqr[0].TO=setTimeout('mqScroll(mqr)',100);
}



function image_rotator(id, sponsor_array, width) {
	this.dom_object=document.getElementById(id); 
	var dom_object_height = this.dom_object.style.height; 

/*	this.dom_object.onmouseout=function() {
		rotate(rotate_array);
	}; 
	this.dom_object.onmouseover=function() {
		clearTimeout(rotate_array[0].TO);
	}; */

	this.dom_object.array=[]; 

	for (var i=0;i<sponsor_array.length;i++) {
                this.dom_object.array[i]=document.createElement('div');
		this.dom_object.array[i].innerHTML='<a href="' +  sponsor_array[i][1] + '"><img src="' + sponsor_array[i][0] + '"/></a>';
		this.dom_object.array[i].style.width = width+'px'; 
		this.dom_object.array[i].style.height = dom_object_height;
		this.dom_object.array[i].style.display = 'none';

		this.dom_object.appendChild(this.dom_object.array[i]);
	} 
	rotate_array.push(this.dom_object);
}

function rotate(rotate_array){
	if (!rotate_array) return; 
	for (var j=rotate_array.length - 1; j > -1; j--) {
		rotate_array[j].array[1].style.display='block';

		rotate_array[j].array[0].style.display='none';

		rotate_array[j].array.push(rotate_array[j].array.shift());
	}
	rotate_array[0].TO=setTimeout('rotate(rotate_array)',5000);
}

