/***
START - Data to be pulled dynamically
**************************/
var mycarousel_itemList = [
    {url: '/application/images/eDirectory-what-guest-say.gif', title: 'What Guests Say', target: '/whatguestsay/index.html', popUp: false},
	{url: '/application/images/eDirectory-view-our-serviced-residence.gif', title: 'View our Serviced Residence Directory', target:'http://editions.magsbyme.com/ebook/10012567/AscottDiren.html', popUp: true},
	{url: '/application/images/eDirectory-build-people.gif', title: 'When We Build Buildings We Build People', target: '/specials/cluster.html?did=14484', popUp: false}
];
/***
END - Data to be pulled dynamically
**************************/

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {
	// The index() method calculates the index from a
	// given index who is out of the actual item range.
	var idx = carousel.index(i, mycarousel_itemList.length);
	carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
	carousel.remove(i);
};

/*function initResized() {
	$("#mycarousel").css("left","0px");	
	alert("initResized");
}*/

/**
* Item html creation helper.
*/
function mycarousel_getItemHTML(item) {
	if(item.popUp)
		return "<a href=\"javascript:;\" onclick=\"openWin('"+item.target+"',780,600);\" ><img src=\""+item.url+"\" width=\"200\" height=\"148\" alt=\""+item.title+"\" /></a>";
	else 
		return '<a href="' + item.target + '"><img src="' + item.url + '" width="200" height="148" alt="' + item.title + '" /></a>';
};

function triggerNext() {
	$(".jcarousel-next").trigger("click");
};


$(function() {
	$("#mycarousel").jcarousel({
		wrap: 'circular',
		scroll: 1,
		itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
		itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
	});

	try {
		setInterval ("triggerNext()",7000);
	}
	catch(e) { }
	
	/*$("body").attr("onresize","initResized();");*/ 
});
