/****************************
 ***** ROTATING STORIES *****
 ****************************/
var imageCSSClass = "homepage_story_image";
var PAUSE_TIME = 10000; //1000 ms = 1 sec

var INTERVAL_RESTORE_TIME = 500;
var CLICK_RESTORE_TIME = 600;


//define list of images to rotate
//["{PATH}", "{URL (optional)}", "{value for "target" attribute of link (optional)}", "{alt text for image tag (optional)}"]
var fadeImages = new Array(
	["/images/homepage_news/boca.jpg", "/woolbrightNews.aspx", "", ""],
	["/images/homepage_news/jupiter.jpg", "/woolbrightNews.aspx", "", ""],
	["/images/homepage_news/lantana.jpg", "/woolbrightNews.aspx", "", ""] 
//	["/images/homepage_news/costco.jpg","","",""], 
//	["/images/homepage_news/great_strides.jpg","","",""], 
//	["/images/homepage_news/glades.jpg","","",""],
//	["/images/homepage_news/glades_plaza.jpg","","",""],
//	["/images/homepage_news/avda.jpg","http://www.southfloridanewswire.com/index.aspx?page=readstories&id=1167","_blank",""],
//	["/images/homepage_news/ElevationStaplesMiramar.jpg","/woolbrightNews.aspx#180","",""]
);

//define text array
var textArray = new Array(
	{
		"title" : "Woolbright Development Signs Leases In Boca Raton",
		"desc": "Goods Sounds, a custom home theater dealer, has leased 2,017 square feet and Harold's Jeweler, a fine jewelry retailer has renewed its leases, at Glades Plaza in Boca Raton, Florida."
	},
	{
	    "title": "Woolbright Development Signs Leases In Jupiter",
	    "desc": "Quinn Communications, a web designer for large and small businesses and organizations worldwide, has leased 1,821 square feet, at Abacoa Town Center in Jupiter, Florida. "
	},
	{
	    "title": "Woolbright Development Signs Leases In Lantana/Boynton Beach/Lake Worth",
	    "desc": "Edward Jones & Company, an investment brokerage and financial services company, has leased 1,010 square feet and Dr. Fara Bender, DMD,  renewed her lease at Lantana Square in Lantana, Florida. "
	}
//	{
//		"title" : "Woolbright Development Celebrates Costco Grand Opening",
//		"desc" : "Costco recently opened a 150,000 sq. ft. store at Woolbright's London Square in Kendall, Florida. At the celebration were: (L to R) Emran Ally, Woolbright leasing associate; Terry Donohue, Costco's general manager; and Sylvia Pereda, Woolbright leasing associate."
//	},
//	{
//		"title" : "Woolbright Supports the Cystic Fibrosis Foundation",
//		"desc" : "Woolbright joins a number of local celebrities in helping raise more than $100,000 for the Cystic Fibrosis Foundation during the annual Great Strides Walk in Boca Raton. Photo by <b><i>ELITE</i></b> Photography. www.events2photograph.com"
//	},
//	{
//		"title" : "Woolbright Named &quot;Top 10 Redeveloper&quot;",
//		"desc" : "For the second year in a row, Woolbright was selected by Chain Store Age as one of the country's &quot;Top 10 Redevelopers.&quot; The company was recognized for redevelopment work completed during 2007, which made dramatic improvements in 9 of its existing centers."
//	},
//	{
//		"title" : "Boca Raton Beautification Committee Recognizes Glades Plaza",
//		"desc" : "The Boca Raton Beautification committee recognized Glades Plaza for its contribution to the beautification of the City of Boca Raton. The Boca Raton Beautification Committee awarded and recognized Glades Plaza for Landscape Excellence in the category of Large Commercial Property. Picture (L- R) Susan Haynie, Council Member (Black Dress), Cary Fronstin, Barbara Benefield, Landscape Excellence Awards Chairperson (Yellow Dress) Boca Raton Beautification Committee."
//	},
//	{
//		"title" : "Woolbright Development Sponsors AVDA's Kick-Off Fundraiser for Annual 5K Run/Walk",
//		"desc" : "As part of the Boca Festival Days, Woolbright Development recently sponsored the fundraising kick-off event at Houston's for the ninth annual 5K Run/Walk benefitting Aid to Victims of Domestic Abuse (AVDA).<br /><br /><a href='http://www.southfloridanewswire.com/index.aspx?page=readstories&id=1167' target='_blank'>SouthFloridaNewsWire.com : 09/02/08 - Woolbright Development Sponsors AVDA's Fundraiser</a>"
//	},
//	{
//	    "title" : "Kohl's opens to great fanfare at Miramar Square",
//	    "desc" : "Click <a href='http://cbs4.com/video/?id=63201@wfor.dayport.com' target='_blank'>here</a> for a story on CBS highlighting the value of having the right tenant mix in our centers. Even in this tough economic climate our shopping centers can continue to thrive with customers like Gail!<br /><br />Click <a href='/woolbrightNews.aspx#180'>here</a> for the press release."
//	}
);

//randomize arrays
try { shuffle(fadeImages, textArray); }
catch(err) {
	alert(err.message);
} //end catch

function next() {
	//remove onclick handler from link to prevent fast clicking from creating timing issues
	nextLink.onclick = "";
	prevLink.onclick = "";
	
	//clear the interval and re-initiate it so that we don't get conflicting event timings
	clearInterval(intvl);
	
	//fade in next image
	nextImage();
	
	//increment current index
	idx = idx == fadeImages.length - 1 ? 0 : idx + 1;
	
	//set all necessary data
	setData();
	
	//restore interval
	setTimeout('intvl = setInterval("next()", PAUSE_TIME)', INTERVAL_RESTORE_TIME); //we must use setTimeout to allow the fading to finish before restarting another interval
	
	//reset the onclick handler on links
	setTimeout("nextLink.onclick = next", CLICK_RESTORE_TIME); //we must use setTimeout to allow the fading to finish before allowing the user to click the links again
	setTimeout("prevLink.onclick = prev", CLICK_RESTORE_TIME); //we must use setTimeout to allow the fading to finish before allowing the user to click the links again

	return false;
} //end function next

function prev() {
	//remove onclick handler from link to prevent fast clicking from creating timing issues
	nextLink.onclick = "";
	prevLink.onclick = "";
	
	//clear the interval and re-initiate it so that we don't get conflicting event timings
	clearInterval(intvl);
	
	//fade in previous image
	previousImage();
	
	//decrement current index
	idx = idx == 0 ? fadeImages.length - 1 : idx - 1;
	
	//set all necessary data
	setData();
	
	//restore interval
	setTimeout('intvl = setInterval("next()", PAUSE_TIME)', INTERVAL_RESTORE_TIME); //we must use setTimeout to allow the fading to finish before restarting another interval
	
	//reset the onclick handler on links
	setTimeout("nextLink.onclick = next", CLICK_RESTORE_TIME); //we must use setTimeout to allow the fading to finish before allowing the user to click the links again
	setTimeout("prevLink.onclick = prev", CLICK_RESTORE_TIME); //we must use setTimeout to allow the fading to finish before allowing the user to click the links again

	return false;
} //end function prev

function setData() {
	//set corresponding text
	picText.innerHTML = textArray[idx].desc;
	titleText.innerHTML = textArray[idx].title;
	
	//change corresponding color block
	for(var i = 0; i < colorBlockArray.length; i++)
		colorBlockArray[i].style.backgroundColor = "#fccea4";
	colorBlockArray[idx].style.backgroundColor = "#f9a25e";
} //end function setData

function init() {
	if(colorBlockArray.length != fadeImages.length) //check to make sure there are the same number of color blocks and image sections
		alert("The number of images and text sections must be equal.");
	else {            
		//load first image
		start();
		
		//load first set of text
		picText.innerHTML = textArray[idx].desc;
		titleText.innerHTML = textArray[idx].title;
		
		if(fadeImages.length > 1) { //if more than one image exists, show links and begin fade sequence
			//show links
			nextLink.style.visibility = "visible";
			prevLink.style.visibility = "visible";
			
			//set forward fading
			intvl = setInterval("next()", PAUSE_TIME);
		} //end if
	} //end else
} //end function init