window.featureList = new Object;
featureList.currentIndex = 0;
featureList.features = [];
featureList.fadeOutStrength = 0.5;
//for when the content is implemented -- root node for the information about the featured items
featureList.baseHref = '/Sights_To_See/';

function spawnFeature(name,description,image,url,titleImage) {
	var feature = new Object;
	feature.name = name;
	feature.description = description;
	feature.image = image;
	feature.url = url;
	feature.titleImage = titleImage;
	featureList.features.push(feature);
}

//==== TESTING ====================
//==== TODO: PRELOAD IMAGES =======
spawnFeature("Uluru","No matter how many pictures you've seen, nothing will prepare you for your first view of Uluru. Even from a distance, across the rich red plains of the Centre, the energy of its ancient spirit will astonish you. Once you stand at its base, touch it and explore the mysteries of this perimeter, you will understand why it is not only a treasured icon to local Anangu people of the region, but also one of the great wonders of the world.","/site_cms/assets/images/homeUluru.jpg","Uluru-Kata_Tjuta_National_Park_","/site_cms/assets/images/home-uluru-title.png");
spawnFeature("MacDonnell Ranges","No matter how many sunrises and sets you have experienced, it is not until you have seen the untouched natural beauty of the fiery reds, oranges and more; rising and falling over a picturesque back drop of Alice Springs the MacDonnell ranges, will you draw in energy like no other and the vision be instilled in your memory forever. These ranges rise dramatically from the Central Australian Desert floor stretching east and west for over 400 kilometres.","/site_cms/assets/images/homeMacDonnell.jpg","West_MacDonnell_Ranges","/site_cms/assets/images/home-macdonnell-title.png");
spawnFeature("Kings Canyon","No matter how many images you have seen, visiting Kings Canyon itself will take your breath away, a sheer sandstone cliff face soaring high above the incredible cycad gardens just one of the many spectacular views of the mighty chasm that cleaves the earth to a depth of 270 metres. This national park is a conservation of rock holes and gorges that provide refuge for over 600 species of plants and many native animals.","/site_cms/assets/images/homeKingsCanyon.jpg","Kings_Canyon","/site_cms/assets/images/home-kings-title.png");
spawnFeature("Devil's Marbles","No matter how many different ways you wonder how these giant marbles came to be; the Devils Marbles (Karlu Karlu) will still boggle your mind with their incredible formations of giant granite like boulders, not only are they spectacular formations they play an import role in the breeding of the Fairy Martins and Zebra Finches, and an array of local lizards and native flora. ","/site_cms/assets/images/homeDevilsMarbles.jpg","Devils_Marbles_and_Tennant_Creek","/site_cms/assets/images/home-devils-title.png");
spawnFeature("Rainbow Valley","No matter where you are in central Australia you will be owe inspired to engage in the energy, colours and natural beauty of a very unique place in the world. Visiting Rainbow Valley will give you the history and heritage of another era, the better time to visit is late afternoon to view the rainbow bands embedded within the Valley ridge. The bands glow vibrantly when struck by the golden rays of the sun.","/site_cms/assets/images/homeRainbow.jpg","Rainbow_Valley","/site_cms/assets/images/home-rainbow-title.png");
spawnFeature("Chambers Pillar","No matter how you look at the images of Chambers Pillar you can only try to imagine how our first explorers navigated our vast lands with the use of large land marks. Although it is not until you are at the base looking up at Chambers Pillar, will you appreciated the 50 meter high red and yellow sandstone column, you will gain a sense of direction as it rises out of the vast red plains. A time of understanding and inspiration, just 164 kilometres south of Alice Springs.","/site_cms/assets/images/homeChambers.jpg","Chambers_Pillar","/site_cms/assets/images/home-chambers-title.png");
j(document).ready(function() {
	j('.featureLeftListItem img').hover(featureListHoverIn,featureListHoverOut);
	j('.featureLeftListItem img').fadeTo('slow',featureList.fadeOutStrength);	
	
	var randomnumber= Math.floor(Math.random()*6);
	currentImage = randomnumber;
  	timeout = null;
	featureList.currentIndex = currentImage;
	/*j('.featureLeftListInfoPopup').css('left',j(j('.featureLeftListItem')[featureList.currentIndex]).position().left);
	j('.featureLeftListInfoPopup').html(featureList.features[featureList.currentIndex].name);*/
	loadContent(randomnumber);
	j(j('.featureLeftListItem img')[currentImage]).stop(true);
	j(j('.featureLeftListItem img')[currentImage]).fadeIn(0);
	j('.featureLeftListItem img').each(function(i,el) {
		j(el).click(function() {
			clearTimeout(timeout);		 
			j('.featureLeftListItem img').fadeTo('slow',featureList.fadeOutStrength);
			j(this).stop(true);
			j(this).fadeTo(0,1.0);
			featureList.currentIndex = getCurrentFeatureIndex(this);
			loadContent(featureList.currentIndex);
		});
	});
	
	setTimeout('cycleImage();', 30000);
});

function getCurrentFeatureIndex(element) {
	var index = -1;
	j('.featureLeftListItem img').each(function(i,el) {
		if (el === element) {
			index = i;
		}
	});
	return index;
}

function loadContent(index) {
	var speed = 400;
	j('.featureRightHighlight').fadeOut(speed);
	j('.featureLeftActions').fadeOut(speed);
	j('.featureLeftCopy').fadeOut(speed,function() {
		j('.featureLeftCopy').html(featureList.features[index].description);	
		j('.featureRightHighlight img').attr('src',featureList.features[index].image);	
		j('.featureLeftActionsInfo a').attr('href',featureList.baseHref + featureList.features[index].url);
		j('.featureLeftActionsActivity a').attr('href',featureList.baseHref + featureList.features[index].name.replace(" ","_").replace("'","") + '/');
		j('.featureLeftActionsGallery a').attr('href',featureList.baseHref + featureList.features[index].name.replace(" ","_").replace("'","") + '/');
		j('.featureRightHighlight').fadeIn(speed);
		j('.featureLeftCopy').fadeIn(speed);
		j('.featureLeftActions').fadeIn(speed);
	});	
	j('.featureLeftTitle').fadeOut(400,function() {
		j('.featureLeftTitle img').attr('src',featureList.features[index].titleImage);
		j('.featureLeftTitle').fadeIn(400);
	});
}

function featureListHoverIn(el) {
	//j('.featureLeftListInfoPopup').stop(true);
	j(el.target).stop(true,true);
	j(el.target).fadeTo('slow',1.0);
	/*j('.featureLeftListInfoPopup').animate({ left: j(el.target).position().left },
													{ complete: function() {
														j(this).html(featureList.features[getCurrentFeatureIndex(el.target)].name);
													}});*/
}

function featureListHoverOut(el) {
	if (!(el.target === j('.featureLeftListItem img')[featureList.currentIndex]))
	{
		j(el.target).fadeTo('fast',featureList.fadeOutStrength);
	}

	/*j('.featureLeftListInfoPopup').animate({ left: j(j('.featureLeftListItem img')[featureList.currentIndex]).position().left },
													{ complete: function() {
														j(this).html(featureList.features[featureList.currentIndex].name);
													}});*/
}

function cycleImage() {   
	nextImage = currentImage + 1;
	if(nextImage > 5) nextImage = 0;
	j(j('.featureLeftListItem img')[currentImage]).fadeTo('fast',featureList.fadeOutStrength);
	j(j('.featureLeftListItem img')[nextImage]).fadeTo('slow',1.0);
	rotate(nextImage);
	currentImage=nextImage;
	timeout = setTimeout('cycleImage();',30000);
}

function rotate(nextImg) {
	/*j('.featureRightHighlight').fadeOut(400,function() {	
		j('.featureRightHighlight img').attr('src',featureList.features[nextImg].image);	
		j('.featureRightHighlight').fadeIn(400);
		j('.featureLeftCopy').html(featureList.features[nextImg].description);
		j('.featureLeftCopy').fadeIn(400);
	});
	j('.featureLeftTitle').fadeOut(400,function() {
		j('.featureLeftTitle img').attr('src',featureList.features[nextImg].titleImage);
		j('.featureLeftTitle').fadeIn(400);
	});*/
	loadContent(nextImg);
}
