
// preload

var navList = new Array('home','about_us','news','product_range','store_finder','	_us');
var visibleLogos=1;

for(var i=0;i<navList.length;i++)
{
	var tmp = new Image();
	tmp.src = "images/common/nav/" + navList[i] + "_over.gif";
}

////////////////////////////// ROLLOVERS ////////////////////////////// 
mouts = new Object();
//rollover the image named n, with the source image s (it guessed the source image if not provided)
function mover (n, s) {if (!document.images[n]) return; if (!s) {s = document.images[n].src; s = s.substr(0, s.lastIndexOf(".")) + "_over" + s.substr(s.lastIndexOf("."));} mouts._last = n; mouts[n] = document.images[n].src; document.images[n].src = s;}
//rollout of the image named n, or else the last image
function mout (n) {n = n ? n : mouts._last; if (!document.images[n]) return; document.images[n].src = mouts[n];}
////////////////////////////// ROLLOVERS ////////////////////////////// 


function clear_search(f)
{
	if(f.value == 'Search our site') f.value = '';
}

function do_search()
{
	if($('main_search_field').value != 'Search our site') document.location = "/search/" + $('main_search_field').value;
	return false;
}
function toggleoffer(id,price,pricevat)
{ 
	new Effect.Highlight('specialoffer'+id);
	
	if(document.getElementById('specialoffer'+id).innerHTML==price)
	{
		document.getElementById('specialoffer'+id).innerHTML=pricevat
		document.getElementById('specialoffer'+id+'vat').innerHTML='inc. VAT';
	
	}
	else
	{
		document.getElementById('specialoffer'+id).innerHTML=price;
		document.getElementById('specialoffer'+id+'vat').innerHTML='ex. VAT';
	}
	
}

function newwindow(url)
{
	window.open(url);

}

lastone=-1;
function changeRandom()
{
	var rand;
	do{
	rand=Math.floor(Math.random()*logoSets)+1
	}while(rand==lastone)
	lastone=rand;
	
	new Effect.toggle('logo'+rand,'appear',{'duration':3});
}
blockSkipping=false;
currentTab=0;


function skipToTab(which,max)
{
	
	if(blockSkipping==false)
	{
		currentTab=which;
		blockSkipping=true;
	

		for(i=0;i<max;i++)
		{
			if(i!=which)
			{
			
				document.getElementById('toptab'+i).className='offertab';
				new Effect.Fade('offertab'+i,{'duration':1})
			}
			else
			{
				document.getElementById('toptab'+i).className='offertabselected';
				new Effect.Appear('offertab'+i,{'duration':1})
			}
		}
		setTimeout("unblockSkipping()",1000)
	}
	

}

function skipToNext(max)
{
	if(currentTab==max-1)
	{
	currentTab=-1;
	
	}
	
	
	skipToTab(currentTab+1,max);

	
}


function unblockSkipping()
{
	
	blockSkipping=false;

}

//MS: vars needed for logo anim
logoLayerVisible = 0;
numLogos = 9;

function logoCascade()
	{
	for(i=0;i<numLogos;i++)
		{
		new Effect.Fade('logo_'+logoLayerVisible+'_'+i,{'queue':'end','duration':0.3}); /*changed on 16-09-08 jules*/
		if(logoLayerVisible==2)
			{
			new Effect.Appear('logo_0_'+i,{'queue':'end','duration':0.3}); /*changed on 16-09-08 jules*/
			}
		else
			{
			new Effect.Appear('logo_'+(logoLayerVisible + 1)+'_'+i,{'queue':'end','duration':0.3}); /*changed on 16-09-08 jules*/
			}
		}
	
	if(logoLayerVisible==2)
		{
		logoLayerVisible=0;
		}
	else
		{
		logoLayerVisible++;
		}
	populateLogos(logoLayerVisible);
	
	setTimeout('logoCascade()',7000); /*changed from 10000 7000 on 15-09-08 jules*/
	}


//MS: var needed for logo population
logocount = 0;

function populateLogos(cycle)
	{
	//MS: populate each slot
	for(i=1;i<numLogos;i++)
		{
		if (logocount == logoArray.length)
			{
			logocount = 0;//MS: reset logocount if end of logoArray reached
			}
		if (logoArray[logocount][0] == '')//MS: if link doesn't exist
			{
			this.document.getElementById("logo_"+cycle+"_"+i).innerHTML = '<img src="'+logoArray[logocount][1]+'" alt="'+logoArray[logocount][3]+'" />';//MS: create img html
		logocount++;//MS: increment logo count
			}
		else
			{
			this.document.getElementById("logo_"+cycle+"_"+i).innerHTML = '<a href="/'+logoArray[logocount][0]+'"><img src="'+logoArray[logocount][1]+'" alt="'+logoArray[logocount][3]+'" /></a>';//MS: create img and link html
		logocount++;//MS: increment logo count
			}
		}
	}

/*
Robins original version
function logoCascade()
	{
	for(i=0;i<9;i++)
		{
		new Effect.Fade('logo_'+logoLayerVisible+'_'+i,{'duration':0.15});
		}
	
	if(logoLayerVisible==2)
		{
		logoLayerVisible=0
		}
	else
		{
		logoLayerVisible++;
		}
		
	for(i=0;i<9;i++)
		{
		new Effect.Appear('logo_'+logoLayerVisible+'_'+i,{'queue':'end','duration':0.12});
		}
	
	setTimeout('logoCascade()',10000);
	}*/



var failedElements=''
			
function sendContactForm()
	{
	failedElements='';
	var qs=new String();
	qs=appendQuerystring('contact_us_name',true,'name');
	qs+=appendQuerystring('contact_us_email',true,'email address','email');
	qs+=appendQuerystring('contact_us_question','enquiry',true);
	//New fields passed in by Paul 27/8/2008
	qs+=appendQuerystring('contact_us_town','town','town');
	qs+=appendQuerystring('contact_us_telephone','telephone');
	if (document.getElementById('contact_us_subscribe').checked) qs+=appendQuerystring('contact_us_subscribe','subscribe');

	if (failedElements!='')
		{
		alert(failedElements);
		}
	else
		{
		new Ajax.Updater('contact_us_form','/send-email/?='+qs)
		}
	}

function appendQuerystring(id,mustexist,friendlyName,type)
	{
	if (mustexist==true && document.getElementById(id).value=='')
		{
		if(document.getElementById(id).type=='text')
			{
			failedElements+="Please fill in your " + friendlyName + "\n";
			}
		else
			{
			failedElements+="Please select your " + friendlyName + "\n";
			}
		}
	
	if (type=='email' && (mustexist || document.getElementById(id).value!='') )
		{
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = document.getElementById(id).value;
		if(reg.test(address) == false)
			{
			failedElements+="Your " + friendlyName + " must be valid. \n";
			}
		}
	
	if (type=='phone' && (mustexist || document.getElementById(id).value!='') )
		{
		number=document.getElementById(id).value;
		number=number.replace(/ /, "");
		var reg=/^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/;
		if (reg.test(number	)==false)
			{
			failedElements+="Your " + friendlyName + " must be a valid number. \n";
			}
		}
		
	return '&request['+id+']='+document.getElementById(id).value;
	}

/*function appendQuerystring(id,mustexist,friendlyName,type)
	{
	if (mustexist==true && document.getElementById(id).value=='')
		{
		if(document.getElementById(id).type=='text')
			{
			failedElements+=friendlyName+" must be filled in. \n";
			}
		else
			{
			failedElements+=friendlyName+" must be selected. \n";
			}
		}
	
	if (type=='email' && (mustexist || document.getElementById(id).value!='') )
		{
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = document.getElementById(id).value;
		if(reg.test(address) == false)
			{
			failedElements+=friendlyName+" must be a valid email address. \n";
			}
		}
	
	if (type=='phone' && (mustexist || document.getElementById(id).value!='') )
		{
		number=document.getElementById(id).value;
		number=number.replace(/ /, "");
		var reg=/^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/;
		if (reg.test(number	)==false)
			{
			failedElements+=friendlyName+" must be a valid phone/fax number. \n";
			}
		}
	return '&request['+id+']='+document.getElementById(id).value;
	}*/
