// =-=-=-=-=-=-=-=-=- //
//  INITIALS 		  //
//	 DEFERRED UNTIL	  //
//	 AFTER HTML  	  //
// -=-=-=-=-=-=-=-=-= //
function initial(){
	//	first setup the intro animation
	YAHOO.example.container.intro = new YAHOO.widget.Panel("myPanel", {
		width: "500px", 
		fixedcenter: true, 
		modal:true, 
		close:false, 
		zindex:4,
		visible:true, 
		draggable:false
	} );

	YAHOO.example.container.intro.render(document.body);

	YAHOO.example.container.intro.show();

	YAHOO.util.Event.on('demo-run', 'click', function() {
		document.getElementById('demo-run').src = "images/logo-lit.gif";
		
		document.getElementById('instructions').style.display = "none";
		
		// Remove the original listener
		YAHOO.util.Event.removeListener("demo-run", "click");

		// Add a new listener
		YAHOO.util.Event.addListener("demo-run", "click", toggleLight);

		window.setTimeout('removeModalWithAnim()',250);
	});
	
	YAHOO.util.Event.on('logo-text', 'click', function() {
		document.getElementById('demo-run').src = "images/logo-lit.gif";
		
		// Remove the original listener
		YAHOO.util.Event.removeListener("logo-text", "click");
		
		window.setTimeout('removeModalWithAnim()',250);
	});
	
	//	run initial overlay creation
	YAHOO.util.Event.onDOMReady(init);

	//	event handlers for menu tabs
	YAHOO.util.Event.addListener("showOverlay1", "click", showOverlay1, YAHOO.example.container.overlay1, true);
	YAHOO.util.Event.addListener("showOverlay2", "click", showOverlay2, YAHOO.example.container.overlay2, true);
	YAHOO.util.Event.addListener("showOverlay3", "click", showOverlay3, YAHOO.example.container.overlay3, true);
	YAHOO.util.Event.addListener("showOverlay4", "click", showOverlay4, YAHOO.example.container.overlay4, true);
	YAHOO.util.Event.addListener(newsIds, "click", navNewsTabs);
	
	//	creating form validator
	var frmvalidator  = new Validator("contact");
	frmvalidator.EnableOnPageErrorDisplaySingleBox();
	frmvalidator.EnableMsgsTogether();
	frmvalidator.addValidation("name","req","Please enter your name");
	frmvalidator.addValidation("name","alpha_s","Name can contain only letters and spaces.");
//  	frmvalidator.addValidation("company","sentence","Company name may contain only letters, numbers and spaces");
	frmvalidator.addValidation("email","email", "Must enter a valid email");
	frmvalidator.addValidation("phone","numeric", "Phone number may only contain numbers");
	frmvalidator.addValidation("questions","sentence", "Questions/Comments may contain only letters, numbers, spaces and punctuation.");
}

// =-=-=-=-=-=-=-=-=- //
//  PAGE SETUP LOGIC  //
// -=-=-=-=-=-=-=-=-= //

YAHOO.namespace("example.container");

//	add onclick's id here to create new overlay
var newsIds = [	"newsDefault",
				"news1",
				"news1_ig",
				"news1_bg",
				"news1_ga",
				"news2",
				"news3",
				"news4"];

function init_news_tabs(){
	//	instantiate overlay foreach news div
	for ( var i in newsIds )
	{
	    // Build overlays based on markup
		eval('YAHOO.example.container.overlay_' + newsIds[i] + '= new YAHOO.widget.Overlay("overlay_' + newsIds[i] + '",{visible:false,context: ["news_bumper", "tl", "bl"],constraintoviewport: true,width:"700px",height:"350px",zIndex:1000,effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.50}});YAHOO.example.container.overlay_' + newsIds[i] + '.render("example");');
	} 
}

function navNewsTabs(e) { 
	//	when name sent, go to that tab, when yui obj, go there, less the list
	if ( typeof(e) == 'string' ){
		showOverlay4();	//	exterior click - show news page
		tabId	=	e;
	}else{
		tabId	=	this.id ? this.id : "newsDefault";
	}
	//	loop through all tabs
	for ( var i in newsIds ){
		//	 hide non selected
		if ( newsIds[i] != tabId ){
			eval('YAHOO.example.container.overlay_' + newsIds[i] + '.hide();document.getElementById("overlay_' + newsIds[i] + '").style.display = "none";');
		}
	}
	
	// now show the selected one
	eval('document.getElementById("overlay_' + tabId + '").style.display = "block";YAHOO.example.container.overlay_' + tabId + '.align("tl", "bl");YAHOO.example.container.overlay_' + tabId + '.show();');
} 

function init() {
	// Build overlay1 based on markup
	YAHOO.example.container.overlayDefault = new YAHOO.widget.Overlay("overlayDefault", {
		visible:false,
		context: ["bumper", "tl", "bl"], 
		width:"700px",
		height:"375px",
		zIndex:1000,
		effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.50} } );
	YAHOO.example.container.overlayDefault.render("example");
	
	// Build overlay1 based on markup
	YAHOO.example.container.overlay1 = new YAHOO.widget.Overlay("overlay1", {
		visible:false,
		context: ["bumper", "tl", "bl"], 
		width:"700px",
		height:"375px",
		zIndex:1000,
		effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.50} } );
	YAHOO.example.container.overlay1.render("example");
	
	// Build overlay2 based on markup
	YAHOO.example.container.overlay2 = new YAHOO.widget.Overlay("overlay2", {
		visible:false,
		context: ["bumper", "tl", "bl"], 
		width:"700px",
		height:"375px",
		zIndex:1000,
		effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.50} } );
	YAHOO.example.container.overlay2.render("example");
	
	// Build overlay3 based on markup
	YAHOO.example.container.overlay3 = new YAHOO.widget.Overlay("overlay3", {
		visible:false,
		context: ["bumper", "tl", "bl"], 
		width:"700px",
		height:"375px",
		zIndex:1000,
		effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.50} } );
	YAHOO.example.container.overlay3.render("example");
	
	// Build overlay4 based on markup
	YAHOO.example.container.overlay4 = new YAHOO.widget.Overlay("overlay4", {
		visible:false,
		context: ["bumper", "tl", "bl"], 
		constraintoviewport: true,
		width:"700px",
		height:"375px",
		zIndex:1000,
		effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.50} } );
	YAHOO.example.container.overlay4.render("example");
	
	// Build overlayNav based on markup - just old house video button
	YAHOO.example.container.overlayNav = new YAHOO.widget.Overlay("nav", {
		context: ["myPanelBody", "tr", "tr"], 
		visible:false,
		width:"200px",
		zIndex:900,
		effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.50} } );
	YAHOO.example.container.overlayNav.render("example");
	
	// Build overlayNav based on markup
	YAHOO.example.container.overlayNavigate = new YAHOO.widget.Overlay("navigation", {
		context: ["nav_bumper", "tl", "bl"], 
		visible:false,
		width:"700px",
		zIndex:1000,
		effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.50} } );
	YAHOO.example.container.overlayNavigate.render("example");
	
	init_news_tabs();
}

function toggleLight() {
	if (document.getElementById('demo-run').src == "http://www.commonwealthlandscapelighting.com/newVersion/images/logo-unlit.gif") {
		document.getElementById('demo-run').src = "images/logo-lit.gif";
		
		window.setTimeout('removeModal()',250);
	} else {
		document.getElementById('demo-run').src = "images/logo-unlit.gif";
		
		window.setTimeout('addModal()',250);
	}
}

function removeModalWithAnim() {
	YAHOO.example.container.intro.cfg.setProperty("modal",false); 
	YAHOO.example.container.intro.render(document.body);
	
	window.setTimeout('completeAnim()',1000);
}

function removeModal() {
	YAHOO.example.container.intro.cfg.setProperty("modal",false); 
	YAHOO.example.container.intro.render(document.body);
}

function addModal() {
	YAHOO.example.container.intro.cfg.setProperty("modal",true); 
	YAHOO.example.container.intro.render(document.body);
}

function completeAnim() {
	anim.onComplete.subscribe(showNav);
	
    anim.animate();
}

function showNav() {
	YAHOO.example.container.overlayNav.align("tr", "tr");
	YAHOO.example.container.overlayNav.show();
	
	YAHOO.example.container.overlayNavigate.align("tl", "bl");
	YAHOO.example.container.overlayNavigate.show();
	
	// Activate the text portion of the logo
//	YAHOO.util.Event.addListener("logo-text", "click", showOverlayDefault);
//	document.getElementById('logo-text').style.cursor = "pointer";
	
	window.setTimeout('showOverlayDefault()',1000);
}

function hideOverlayDefault() {
	YAHOO.example.container.overlayDefault.hide();
	
	document.getElementById('overlayDefault').style.display = "none";
}

function hideOverlay1() {
	YAHOO.example.container.overlay1.hide();
	
	YAHOO.util.Dom.removeClass('nav1','selected');
	
	document.getElementById('overlay1').style.display = "none";
}

function hideOverlay2() {
	YAHOO.example.container.overlay2.hide();
	
	YAHOO.util.Dom.removeClass('nav2','selected');
	
	document.getElementById('overlay2').style.display = "none";
}

function hideOverlay3() {
	YAHOO.example.container.overlay3.hide();
	
	YAHOO.util.Dom.removeClass('nav3','selected');
		
	document.getElementById('overlay3').style.display = "none";
}



function hideOverlay4() {
	YAHOO.example.container.overlay4.hide();
	
	YAHOO.util.Dom.removeClass('nav4','selected');
	
	document.getElementById('overlay4').style.display = "none";
}


function showOverlayDefault() {
	hideOverlay1();
	hideOverlay2();
	hideOverlay3();
	hideOverlay4();
	
	document.getElementById('overlayDefault').style.display = "block";
	
	YAHOO.example.container.overlayDefault.align("tl", "bl");
	
	YAHOO.example.container.overlayDefault.show();
}

function showOverlay1() {
	hideOverlayDefault();
	hideOverlay2();
	hideOverlay3();
	hideOverlay4();
	
	document.getElementById('overlay1').style.display = "block";
	
	YAHOO.util.Dom.addClass('nav1','selected');
	
	YAHOO.example.container.overlay1.align("tl", "bl");
	
	YAHOO.example.container.overlay1.show();
}

function showOverlay2() {
	hideOverlayDefault();
	hideOverlay1();
	hideOverlay3();
	hideOverlay4();
	
	// put a delay here
	
	document.getElementById('overlay2').style.display = "block";
	
	YAHOO.util.Dom.addClass('nav2','selected');
	
	YAHOO.example.container.overlay2.align("tl", "bl");
	YAHOO.example.container.overlay2.show();
}

function showOverlay3() {
	hideOverlayDefault();
	hideOverlay1();
	hideOverlay2();
	hideOverlay4();
	
	// put a delay here
	
	document.getElementById('overlay3').style.display = "block";
	
	YAHOO.util.Dom.addClass('nav3','selected');
	
	YAHOO.example.container.overlay3.align("tl", "bl");
	YAHOO.example.container.overlay3.show();
}

function showOverlay4() {
	hideOverlayDefault();
	hideOverlay1();
	hideOverlay2();
	hideOverlay3();
	
	// put a delay here
	document.getElementById('overlay4').style.display = "block";
	
	YAHOO.util.Dom.addClass('nav4','selected');
	
	YAHOO.example.container.overlay4.align("tl", "bl");
	YAHOO.example.container.overlay4.show();

	//	then show news list overlay
	navNewsTabs();
}

// =-=-=-=-=-=-=-=-=- //
// CONTACT FORM LOGIC //
// -=-=-=-=-=-=-=-=-= //
var handleSuccess = function(o){
	var div_c	=	document.getElementById('contact_form');
	if(o.responseText == 'SUCCEED'){
		new_div	= "<div id=\"success\">";
		new_div	+= "<p class=\"\"><h1>Thank You</h1></p>";
		new_div	+= "<p class=\"\">Your information has been sent, and you will be hearing back from us shortly. </p>";
		new_div	+= "</div>";
		new_div += "<p>";
		new_div += "<br /><br />Mark Piantedosi<br />";
		new_div += "978-857-0164<br />"
		new_div += "<a href=\"mailto:mark@cwlandscapelighting.com\">mark@cwlandscapelighting.com</a>";
		new_div += "</p>";
		div_c.innerHTML	=	new_div;
	}
	else if(o.responseText == 'FAIL'){
		new_div	= "<div id=\"failure\">";
		new_div	+= "<p class=\"\">We\'re Sorry</p>";
		new_div	+= "<p class=\"\">Your information was not sent, please try back later. </p>";
		new_div	+= "</div>";
		div_c.innerHTML	=	new_div + div_c.innerHTML;
	}else{
		new_div	= "<div id=\"failure\">";
		new_div	+= "<p class=\"\">We\'re Sorry</p>";
		new_div	+= "<p class=\"\">" + o.responseText + "</p>";
		new_div	+= "</div>";
		div_c.innerHTML	=	new_div + div_c.innerHTML;
	}
};

var handleFailure = function(o){
	var div_c	=	document.getElementById('contact_form');
	if(o.responseText !== undefined){
		new_div	= "<div id=\"failure\">";
		new_div	+= "<p class=\"\">We're Sorry</p>";
		new_div	+= "<p class=\"\">Your information was not sent, please try back later. </p>";
		new_div	+= "</div>";
		div_c.innerHTML	= new_div + div_c.innerHTML;
	}
};

var callback =
{
  success:handleSuccess,
  failure:handleFailure,
  argument:['foo','bar']
};


function submitForm(){
	var sUrl = "functions/contact.php";
	var postData = "";
	var formElements = document.contact.elements;
	var div_err	=	document.getElementById('contact_errorloc');
	var div_c	=	document.getElementById('contact_form');
	
	if(document.contact.phone.value == "" && document.contact.email.value == ""){
		div_err.innerHTML = "<ul><li>You must enter either phone number or email address</li></ul>" + div_err.innerHTML;
	}
	else{
	//	show loading
	div_c.innerHTML	=	"<div style=\"width:100%;height:100%;text-align:center;padding-top:60px;\"><img src=\"images/load-lg.gif\"></div>";
	
	for (i=0; i<formElements.length; i++) {
		if ((formElements[i].name != "send") && (formElements[i].value != "")){
			if ( postData == ""){
				postData +=	formElements[i].name + "=" + "\"" + encodeURIComponent(formElements[i].value) + "\"";
			}else{
				postData +=	"&" + formElements[i].name + "=" + "\"" + encodeURIComponent(formElements[i].value) + "\"";
			}
		}
	}
	
	var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
	}
}


// =-=-=-=-=-= //
// PHOTO LOGIC //
// -=-=-=-=-=- //

init_photo = function(){
	//creating a data source object
 	var dataSource = {
		image1:{url:"photos/landscape_lighting/photo01.jpg"},
		image2:{url:"photos/landscape_lighting/photo02.jpg"},
		image3:{url:"photos/landscape_lighting/photo03.jpg"},
		image4:{url:"photos/landscape_lighting/photo05.jpg"},
		image5:{url:"photos/landscape_lighting/photo07.jpg"},
		image6:{url:"photos/landscape_lighting/photo08.jpg"},
		image7:{url:"photos/landscape_lighting/photo09.jpg"},
		image8:{url:"photos/landscape_lighting/photo12.jpg"},
		image9:{url:"photos/landscape_lighting/photo13.jpg"},
		image10:{url:"photos/landscape_lighting/photo14.jpg"},
		image11:{url:"photos/landscape_lighting/photo15.jpg"},
		image12:{url:"photos/landscape_lighting/photo17.jpg"},
		image13:{url:"photos/landscape_lighting/photo18.jpg"},
		image14:{url:"photos/landscape_lighting/photo20.jpg"},
		image15:{url:"photos/landscape_lighting/photo21.jpg"},
		image16:{url:"photos/landscape_lighting/photo22.jpg"},
		image17:{url:"photos/landscape_lighting/photo23.jpg"},
		image18:{url:"photos/landscape_lighting/photo24.jpg"},
		image19:{url:"photos/landscape_lighting/photo25.jpg"},
		image20:{url:"photos/landscape_lighting/photo39.jpg"},
		image21:{url:"photos/landscape_lighting/photo40.jpg"},
		image22:{url:"photos/landscape_lighting/photo41.jpg"}
	};

	//Instantiate a Lightbox object
	var lightbox = new YAHOO.com.thecodecentral.Lightbox(dataSource,{
		id: 'examples',
		maskOpacity: .75,
		maskBgColor: '#000000',
		modal: true,
		hasThumbnails: true,
		ctrlVisible: true,
		ctrlOpacity: .5,
		effect: true,
		effectDuration: 1
	});
}
	
//	news image lightbox
init_news = function(){
	// now the news lightbox
	var newsDataSource = {
		news_image1:{url:"images/savoy-cw-01-big.jpg"},
		news_image2:{url:"images/savoy-cw-02-big.gif"},
		news_image3:{url:"photos/crane_estate/overview1.jpg"},
		news_image4:{url:"photos/crane_estate/overview2.jpg"},
		news_image5:{url:"photos/crane_estate/overview3.jpg"},
		news_image6:{url:"images/savoy-cw-03-big.jpg"},
		news_image7:{url:"photos/old_manse/overview.jpg"}
	};

	//Instantiate a Lightbox object
	var lightbox_news = new YAHOO.com.thecodecentral.Lightbox(newsDataSource,{
		id: 'news',
		maskOpacity: .75,
		maskBgColor: '#000000',
		modal: true,
		hasThumbnails: true,
		ctrlVisible: true,
		ctrlOpacity: .5,
		effect: true,
		effectDuration: 1
	});
}

//	italianate gardens lightbox
init_news1_ig = function(){
	// now the news lightbox
	var DataSource_news1_ig = {
		image1_news1_ig:{url:"photos/crane_estate/italianateGarden1.jpg"},
		image2_news1_ig:{url:"photos/crane_estate/italianateGarden2.jpg"},
		image3_news1_ig:{url:"photos/crane_estate/italianateGarden3.jpg"},
		image4_news1_ig:{url:"photos/crane_estate/italianateGarden4.jpg"},
		image5_news1_ig:{url:"photos/crane_estate/italianateGarden5.jpg"},
		image6_news1_ig:{url:"photos/crane_estate/italianateGarden6.jpg"}
	};

	//Instantiate a Lightbox object
	var lightbox_news1_ig = new YAHOO.com.thecodecentral.Lightbox(DataSource_news1_ig,{
		id: 'news_ig',
		maskOpacity: .75,
		maskBgColor: '#000000',
		modal: true,
		hasThumbnails: true,
		ctrlVisible: true,
		ctrlOpacity: .5,
		effect: true,
		effectDuration: 1
	});
}

//	bowling green lightbox
init_news1_bg = function(){
	// now the news lightbox
	var DataSource_news1_bg = {
		image1_news1_bg:{url:"photos/crane_estate/bowlingGreen1.jpg"},
		image2_news1_bg:{url:"photos/crane_estate/bowlingGreen2.jpg"},
		image3_news1_bg:{url:"photos/crane_estate/bowlingGreen3.jpg"}
	};

	//Instantiate a Lightbox object
	var lightbox_news1_bg = new YAHOO.com.thecodecentral.Lightbox(DataSource_news1_bg,{
		id: 'news_bg',
		maskOpacity: .75,
		maskBgColor: '#000000',
		modal: true,
		hasThumbnails: true,
		ctrlVisible: true,
		ctrlOpacity: .5,
		effect: true,
		effectDuration: 1
	});
}

//	grand allee lightbox
init_news1_ga = function(){
	// now the news lightbox
	var DataSource_news1_ga = {
		image1_news1_ga:{url:"photos/crane_estate/grandAllee1.jpg"},
		image2_news1_ga:{url:"photos/crane_estate/grandAllee2.jpg"},
		image3_news1_ga:{url:"photos/crane_estate/grandAllee3.jpg"},
		image4_news1_ga:{url:"photos/crane_estate/grandAllee4.jpg"},
		image5_news1_ga:{url:"photos/crane_estate/grandAllee5.jpg"},
		image6_news1_ga:{url:"photos/crane_estate/grandAllee6.jpg"},
		image7_news1_ga:{url:"photos/crane_estate/grandAllee7.jpg"},
		image8_news1_ga:{url:"photos/crane_estate/grandAllee8.jpg"}
	};

	//Instantiate a Lightbox object
	var lightbox_news1_ga = new YAHOO.com.thecodecentral.Lightbox(DataSource_news1_ga,{
		id: 'news_ga',
		maskOpacity: .75,
		maskBgColor: '#000000',
		modal: true,
		hasThumbnails: true,
		ctrlVisible: true,
		ctrlOpacity: .5,
		effect: true,
		effectDuration: 1
	});
}

// carousel stuff
var carousel, curpos, items = [];

function getImageTag(img) {
	return "<img src=\"" + img.link + "\" id=\"" + img.id + "\">";
}

function getImages() {
	var carousel = this;

	YAHOO.util.Connect.asyncRequest("GET", "functions/getimages.php?pos="+curpos,{
		success: function (o) {
			var i = curpos,
				j = 0,
				r = eval('(' + o.responseText + ')');

			curpos += r.length;

			while (i < curpos) {
				if (r[j]) {
					carousel.addItem(getImageTag(r[j]));
				} else {
					break;
				}
				i++;
				j++;
			}

			carousel.set("selectedItem", carousel.get("firstVisible"));

			//	SZELLEY: reload lightbox to be active on added divs
			init_photo();
		},

		failure: function (o) {
			alert("Ajax request failed!");
		}
	});
}


// carousel for italianate gardens stuff
var carousel_news1_ig, curpos_news1_ig, items_news1_ig = [];

function getImages_news1_ig() {
	var carousel_news1_ig = this;

	YAHOO.util.Connect.asyncRequest("GET", "functions/getimages.php?italianate_garden=true&pos="+curpos_news1_ig,{
		success: function (o) {
			var i = curpos_news1_ig,
				j = 0,
				r = eval('(' + o.responseText + ')');

			curpos_news1_ig += r.length;

			while (i < curpos_news1_ig) {
				if (r[j]) {
					carousel_news1_ig.addItem(getImageTag(r[j]));
				} else {
					break;
				}
				i++;
				j++;
			}

			carousel_news1_ig.set("selectedItem", carousel_news1_ig.get("firstVisible"));

			//	SZELLEY: reload lightbox to be active on added divs
			init_news1_ig();
		},

		failure: function (o) {
			alert("Ajax request failed!");
		}
	});
}

// carousel for bowling green stuff
var carousel_news1_bg, curpos_news1_bg, items_news1_bg = [];

function getImages_news1_bg() {
	var carousel_news1_bg = this;

	YAHOO.util.Connect.asyncRequest("GET", "functions/getimages.php?bowling_green=true&pos="+curpos_news1_bg,{
		success: function (o) {
			var i = curpos_news1_bg,
				j = 0,
				r = eval('(' + o.responseText + ')');

			curpos_news1_bg += r.length;

			while (i < curpos_news1_bg) {
				if (r[j]) {
					carousel_news1_bg.addItem(getImageTag(r[j]));
				} else {
					break;
				}
				i++;
				j++;
			}

			carousel_news1_bg.set("selectedItem", carousel_news1_bg.get("firstVisible"));

			//	SZELLEY: reload lightbox to be active on added divs
			init_news1_bg();
		},

		failure: function (o) {
			alert("Ajax request failed!");
		}
	});
}

// carousel for italianate gardens stuff
var carousel_news1_ga, curpos_news1_ga, items_news1_ga = [];

function getImages_news1_ga() {
	var carousel_news1_ga = this;

	YAHOO.util.Connect.asyncRequest("GET", "functions/getimages.php?grand_allee=true&pos="+curpos_news1_ga,{
		success: function (o) {
			var i = curpos_news1_ga,
				j = 0,
				r = eval('(' + o.responseText + ')');

			curpos_news1_ga += r.length;

			while (i < curpos_news1_ga) {
				if (r[j]) {
					carousel_news1_ga.addItem(getImageTag(r[j]));
				} else {
					break;
				}
				i++;
				j++;
			}

			carousel_news1_ga.set("selectedItem", carousel_news1_ga.get("firstVisible"));

			//	SZELLEY: reload lightbox to be active on added divs
			init_news1_ga();
		},

		failure: function (o) {
			alert("Ajax request failed!");
		}
	});
}

YAHOO.util.Event.onDOMReady(function (ev) {
	var i, spotlight;
	
	//	before carousel, load other lightbox
	init_news();

	carousel = new YAHOO.widget.Carousel("container", {
		numItems: 22,
		numVisible: 2
	});
    
    YAHOO.util.Connect.asyncRequest("GET", "functions/getimages.php", {
		success: function (o) {
			var i, r = eval('(' + o.responseText + ')');
			curpos = r.length;

			for (i = 0; i < curpos; i++) {
				items.push(r[i]);
			}

			// check if the Carousel widget is available
			if (typeof carousel != "undefined") {
				for (i = 0; i < curpos; i++) {
					// if so, shove the elements into it
					carousel.addItem(getImageTag(items[i]));
				}
			
				carousel.set("selectedItem", 0);
				items = [];
			}

			//	SZELLEY: load lightbox attached to carousel
			init_photo();
		},

		failure: function (o) {
			alert("Ajax request failed!");
		}
	});

	carousel.render();
	carousel.show();

	carousel.on("loadItems", function (o) {
		// more items available?
		getImages.call(this);
	});
	
	//	grand allee carousel
	carousel_news1_ga = new YAHOO.widget.Carousel("container_news1_ga", {
		numItems: 2,
		numVisible: 2
	});
    
    YAHOO.util.Connect.asyncRequest("GET", "functions/getimages.php?grand_allee=true", {
		success: function (o) {
			var i, r = eval('(' + o.responseText + ')');
			curpos_news1_ga = r.length;

			for (i = 0; i < curpos_news1_ga; i++) {
				items_news1_ga.push(r[i]);
			}

			// check if the Carousel widget is available
			if (typeof carousel_news1_ga != "undefined") {
				for (i = 0; i < curpos_news1_ga; i++) {
					// if so, shove the elements into it
					carousel_news1_ga.addItem(getImageTag(items_news1_ga[i]));
				}
			
				carousel_news1_ga.set("selectedItem", 0);
				items_news1_ga = [];
			}

			//	SZELLEY: load lightbox attached to carousel
			init_news1_ga();
		},

		failure: function (o) {
			alert("Ajax request failed!");
		}
	});

	carousel_news1_ga.render();
	carousel_news1_ga.show();

	carousel_news1_ga.on("loadItems", function (o) {
		// more items available?
		getImages_news1_ga.call(this);
	});
	
	//	italianate gardens carousel
	carousel_news1_ig = new YAHOO.widget.Carousel("container_news1_ig", {
		numItems: 6,
		numVisible: 2
	});
    
    YAHOO.util.Connect.asyncRequest("GET", "functions/getimages.php?italianate_garden=true", {
		success: function (o) {
			var i, r = eval('(' + o.responseText + ')');
			curpos_news1_ig = r.length;

			for (i = 0; i < curpos_news1_ig; i++) {
				items_news1_ig.push(r[i]);
			}

			// check if the Carousel widget is available
			if (typeof carousel_news1_ig != "undefined") {
				for (i = 0; i < curpos_news1_ig; i++) {
					// if so, shove the elements into it
					carousel_news1_ig.addItem(getImageTag(items_news1_ig[i]));
				}
			
				carousel_news1_ig.set("selectedItem", 0);
				items_news1_ig = [];
			}

			//	SZELLEY: load lightbox attached to carousel
			init_news1_ig();
		},

		failure: function (o) {
			alert("Ajax request failed!");
		}
	});
		
	carousel_news1_ig.render();
	carousel_news1_ig.show();

	carousel_news1_ig.on("loadItems", function (o) {
		// more items available?
		getImages_news1_ig.call(this);
	});
	
	//	bowling green carousel
	carousel_news1_bg = new YAHOO.widget.Carousel("container_news1_bg", {
		numItems: 3,
		numVisible: 2
	});
    
    YAHOO.util.Connect.asyncRequest("GET", "functions/getimages.php?bowling_green=true", {
		success: function (o) {
			var i, r = eval('(' + o.responseText + ')');
			curpos_news1_bg = r.length;

			for (i = 0; i < curpos_news1_bg; i++) {
				items_news1_bg.push(r[i]);
			}

			// check if the Carousel widget is available
			if (typeof carousel_news1_bg != "undefined") {
				for (i = 0; i < curpos_news1_bg; i++) {
					// if so, shove the elements into it
					carousel_news1_bg.addItem(getImageTag(items_news1_bg[i]));
				}
			
				carousel_news1_bg.set("selectedItem", 0);
				items_news1_bg = [];
			}

			//	SZELLEY: load lightbox attached to carousel
			init_news1_bg();
		},

		failure: function (o) {
			alert("Ajax request failed!");
		}
	});

	carousel_news1_bg.render();
	carousel_news1_bg.show();

	carousel_news1_bg.on("loadItems", function (o) {
		// more items available?
		getImages_news1_bg.call(this);
	});
});