var resetSlides = false;
var addextra = false;
var no_of_slides = 7; // This is the number of images in the slideshowArray array

function homepageSlideshow(counter) {
	var picArray = slideshowArray()/*new Array()*/;
	var imagePath = ''/*'images/front-centre/'*/;
	var win= null; 
	counter = counter-0;
	if (counter == 0) {
		$('image1').src = imagePath + picArray[counter];
		counter++;
		$('image2').src = imagePath + picArray[counter];
		counter++;
	} else {
		$('image1').src = imagePath + picArray[counter];
		if(resetSlides){
			if(counter == no_of_slides){
				counter = 0;
				addextra = true;
			}
			$('image1').src = imagePath + picArray[counter];
			if(addextra){
				counter++;
			}
			resetSlides = false;
		} else {	
			counter++;
		}
		$('image1').style.display = "none";
		new Effect.Fade('image2', {
			duration: 4.0,
			afterFinish: function() {
				if(counter == no_of_slides){
					counter = 0;
				}
				$('image2').src = imagePath + picArray[counter];
				counter++;
			}
		});
	}
	
	new Effect.Appear('image1', {
		
		duration: 4.0,
		afterFinish: function() {
			new Effect.Fade('image1');
			new Effect.Appear('image2', {
				duration: 4.0,
				afterFinish: function() {
					if (counter > (no_of_slides-1)) {
						resetSlides = true;
						homepageSlideshow(counter);
					} else {
						homepageSlideshow(counter);
						
					}
				}
			});
		}
	});
}

function newwindow(mypage,myname,w,h,scroll){ 
	var winl = 0;
	var wint = 0;
	winl = (screen.width-w)/2;
	if (navigator.userAgent.indexOf("Opera")==-1){  //Opera needs to be zero as it keeps popups within the browser content area
		wint = (screen.height-h)/2;
	}
	settings='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',toolbar=no,location=no,status=no,menubar=no,resizable=yes,dependent=no' 
	win=window.open(mypage,myname,settings) 
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();} 
} 

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}
