var imgs=new Array();
var alts=new Array();
var lins=new Array();
var busImageArray = new Array();
var busAltArray = new Array();
var busURLArray = new Array();
var perImageArray = new Array();
var perAltArray = new Array();
var perURLArray = new Array();
var stdImageArray = new Array();
var stdAltArray = new Array();
var stdURLArray = new Array();

busImageArray[0]="http://www.bankofireland.ie/html/gws/includes/hp/images/sectione/startup.gif";
busImageArray[1]="http://www.bankofireland.ie/html/gws/includes/hp/images/sectione/credit_interest.gif";
busImageArray[2]="http://www.bankofireland.ie/html/gws/includes/hp/images/sectione/obla_hp.gif";

busAltArray[0]="Business Start-up online training course";
busAltArray[1]="Our best ever current account now pays interest";
busAltArray[2]="Business Loan & Overdraft/Apply Online";

busURLArray[0]="http://www.bankofirelandstartupcourse.com";
busURLArray[1]="http://www.bankofireland.ie/html/gws/personal/day_to_day/credit_interest/index.html";
busURLArray[2]="http://www.bankofireland.ie/html/gws/business/finance_your_business/online_loan/index.html";


perImageArray[0]="http://www.bankofireland.ie/html/gws/includes/hp/images/sectione/free_day.gif";
perImageArray[1]="http://www.bankofireland.ie/html/gws/includes/hp/images/sectione/tup.gif";
perImageArray[2]="http://www.bankofireland.ie/html/gws/includes/hp/images/sectione/credit_interest.gif";

perAltArray[0]="Free day to day banking";
perAltArray[1]="Trading Up Mortgage Package";
perAltArray[2]="Our best ever current account now pays interest";

perURLArray[0]="http://www.bankofireland.ie/html/gws/personal/day_to_day/free_banking/index.html";
perURLArray[1]="http://www.bankofireland.ie/html/gws/personal/buy_house/trading_up/index.html";
perURLArray[2]="http://www.bankofireland.ie/html/gws/personal/day_to_day/credit_interest/index.html";


stdImageArray[0]="http://www.bankofireland.ie/html/gws/includes/hp/images/sectione/startup.gif";
stdImageArray[1]="http://www.bankofireland.ie/html/gws/includes/hp/images/sectione/credit_interest.gif";
stdImageArray[2]="http://www.bankofireland.ie/html/gws/includes/hp/images/sectione/obla_hp.gif";

stdAltArray[0]="Business Start-up online training course";
stdAltArray[1]="Our best ever current account now pays interest"; 
stdAltArray[2]="Business Loan & Overdraft/Apply Online";

stdURLArray[0]="http://www.bankofirelandstartupcourse.com";
stdURLArray[1]="http://www.bankofireland.ie/html/gws/personal/day_to_day/credit_interest/index.html";
stdURLArray[2]="http://www.bankofireland.ie/html/gws/business/finance_your_business/online_loan/index.html";
updateCookie();

function updateCookie(){

	var theUrl=document.location.href;
	if(theUrl.indexOf('personal')>=0)
		createCookie('theSwitch','1',30);
	else if(theUrl.indexOf('business')>=0)
		createCookie('theSwitch','2',30);
	
}


var count=0;
var ran = "267";
ranh = "_old";

function createCookie(name,value,days) {
	
	if (days) {
		
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
		
	}
	else var expires = "";
	//alert(expires);
	document.cookie = name+"="+value+expires+"; path=/";
	//alert(document.cookie);
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}



function imageWriting(){
	
	//writeImage(busImageArray,busAltArray,busURLArray)
	//writeImage(perImageArray,perAltArray,perURLArray)
	
	
	var been=readCookie('theSwitch');
	
	if(been==null)
		writeImage(stdImageArray,stdAltArray,stdURLArray);
	else if(been==1)
		writeImage(perImageArray,perAltArray,perURLArray);
	else if(been==2)
		writeImage(busImageArray,busAltArray,busURLArray);
	else
		writeImage(stdImageArray,stdAltArray,stdURLArray);
	return;
}

function writeImage(imageArray,altArray,urlArray) {
	//alert("gets here");

	for(var i=0;i<imageArray.length;i++){
		document.write('<a href="'+urlArray[i]+'"><img border="0" src="'+imageArray[i]+'" alt="'+altArray[i]+'"></a>');
	}

}



function AddImage(v1,v2,v3) {
imgs[count]=v1;
alts[count]=v2;
lins[count]=v3;
count++;
}
function AddPopImage(v1,v2,v3,v4,v5) {
imgs[count]=v1;
alts[count]=v2;
lins[count]="javascript:SectionEPopupWindow('"+v3+"','sectione','width="+v4+",height="+v5+",scrollbars=1')";
count++;
}

function SectionEPopupWindow(winurl,winname,winfeatures) {
	newwin = window.open(winurl,winname,winfeatures);
	}

function doImage() {
if (count!=0) {
if (ran!=267) {ranh = ran;}
ran = Math.floor(Math.random()*count);

if (ran==ranh) {

	doImage();
	return;
	}
else {
	document.write('<a href="'+lins[ran]+'"><img src="'+imgs[ran]+'"></a><br />');
	document.write('<a href="'+lins[ran]+'" >'+alts[ran]+'</a>');
	}	
}
}











