var resetSlides = false;
var addextra = false;
var no_of_slides = 0; // 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; 

	/*picArray[0] = 'images/front-centre/cyprus-architectural-ruins.jpg';
	picArray[1] = 'images/front-centre/cyprus-beach.jpg';
	picArray[2] = 'images/front-centre/cyprus-city-streets.jpg';
	picArray[3] = 'images/front-centre/cyprus-coastal-rocks.jpg';
	picArray[4] = 'images/front-centre/cyprus-fishing-village.jpg';
	picArray[5] = 'images/front-centre/cyprus-historical-ruins.jpg';
	picArray[6] = 'images/front-centre/cyprus-holiday-pool-resort.jpg';
	picArray[7] = 'images/front-centre/cyprus-holiday-resort.jpg'
	picArray[8] = 'images/front-centre/cyprus-shopping-mall.jpg';   
	picArray[9] = 'images/front-centre/cyprus-market-town.jpg';
	picArray[10] = 'images/front-centre/cyprus-mountain-accommodation.jpg';
	picArray[11] = 'images/front-centre/cyprus-mountain-resort.jpg';
	picArray[12] = 'images/front-centre/cyprus-paphos-ruins.jpg';
	picArray[13] = 'images/front-centre/cyprus-paphos-ruins2.jpg';
	picArray[14] = 'images/front-centre/cyprus-holiday-resort2.jpg';
	picArray[15] = 'images/front-centre/greece-nighttime-historical.jpg';
	picArray[16] = 'images/front-centre/greece-historical-ruins.jpg';*/
	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 setupAdvSearch() {
	$('accomType').style.display = "none";
	$('starRating').style.display = "none";
	$('accomOptions').style.display = "none";
	
	sectionHeaders = document.getElementsByClassName('sectionHeader');
	
	sectionHeaders.each(function(item, index) {
			link = item.getElementsByTagName('a')[0];
			link.onclick = function() {
			
				switch(item.id) {
					case 'typeHeader':
						image = $(item.id).getElementsByTagName('img')[0];
						if (image.className == "down") {
							image.className = "up"
							image.src = "images/up-arrow.jpg";
							$('accomType').style.display = "block";
						} else {
							image.className = "down"
							image.src = "images/down-arrow.jpg";
							$('accomType').style.display = "none";
						}
					break;
					case 'starHeader':
						image = $(item.id).getElementsByTagName('img')[0];	
						if (image.className == "down") {
							image.className = "up"
							image.src = "images/up-arrow.jpg";
							$('starRating').style.display = "block";
						} else {
							image.className = "down"
							image.src = "images/down-arrow.jpg";
							$('starRating').style.display = "none";
						}
					break;
					case 'optionsHeader':
						image = $(item.id).getElementsByTagName('img')[0];
						if (image.className == "down") {
							image.className = "up"
							image.src = "images/up-arrow.jpg";
							$('accomOptions').style.display = "block";
						} else {
							image.className = "down"
							image.src = "images/down-arrow.jpg";
							$('accomOptions').style.display = "none";
						}
					break;
				}
			}
		}
	);
}

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();
		}
	}
}
