// JavaScript Document
//the gallery on the main page and the text that a companies it 
var myheader = ['GREENE KING','LABOUR','CITROEN','WOLSELEY'];
var mycopy = ['Supporting a national brand with localised marketing that drives footfall','A CRM solution that delivers both national and local communications','Stronger relationships with local customers that deliver increased sales and loyalty','Branch based marketing that engages local customers and drives revenue'];
var mypics = ['url(../images/wrapper_images/image1.jpg)','url(../images/wrapper_images/image2.jpg)','url(../images/wrapper_images/image3.jpg)','url(../images/wrapper_images/image4.jpg)'];
if(typeof(count)=="undefined")var count = Math.floor(Math.random()*(myheader.length));

function timerSwitch(){
   if(count < myheader.length-1) count++;
   else count = 0;
   switchGallery();
}

function switchGallery(){
   $('gallery_copy').update(mycopy[count]);
   $('gallery_header').update(myheader[count]);
   $('wrapper').setStyle({backgroundImage:mypics[count]});
   $$('#gallery_items li').each(function(e){e.removeClassName("active")});
   $$('#gallery_items li')[count].addClassName("active");
}

document.observe("dom:loaded", function() {
	for(i=0;i<myheader.length;i++)$('gallery_items').insert("<li></li>",{position:"bottom"});
	$$('#gallery_items li').each(function(e){
		e.observe('click',function(evt){
			clearInterval(switcher);
			count = Event.element(evt).previousSiblings().length;
			switchGallery();
		})
	});
	if(typeof(killGallery) == "undefined")var switcher = setInterval("timerSwitch()",5000);
	switchGallery();
});
