/*
# ---------------------------------------------------------------
# P A R T   D E S C R I P T I O N
# ---------------------------------------------------------------
# project: Andrea Katheder
# ---------------------------------------------------------------
# name:    ak_home_gallery.js
# ---------------------------------------------------------------
# descr:   home page gallery scripts
# --------------------------------------------------------------
# author:  Felix Lucke
# ---------------------------------------------------------------
# charset: UTF-8
# ---------------------------------------------------------------
# edit:    Fri Jun 04 11:31:53 2010 - initial setup
# ---------------------------------------------------------------
*/

var intFadeTime = 1000;
var intPlayTime = 10000;

function StartImageGallery() {

	// continue if at least one image found
	if (home_images.length > 0) {
		
		if ($('#content_alternative').length > 0) {
			ShowFirstImage();
			setInterval('ShowNextImage()', intPlayTime);
		} else {
			setInterval('ShowNextImage()', intPlayTime);
		}
		
	}
	
}

function IncreasedIndex(current_index, max_images) {
	
	var new_index = current_index + 1;
	if (new_index == (max_images)) new_index = 0;
	return new_index;

}

function ShowFirstImage() {
	
	// hide seo content
	$('#content_alternative').hide();
	
	// load and display image
	var img = new Image();
	
	$(img)
		.load(function () {
			$(this).hide();
			// replace seo content
			$('#content_alternative').replaceWith(this);
			$(this).fadeIn(intFadeTime);
		})
		.error(function () {
			// step over image
			home_image_index = IncreasedIndex(home_image_index, home_images.length);
		})
		.attr('id', 'home_image_' + home_image_index)
		.attr('src', home_images[home_image_index]);
		
}

function ShowNextImage() {
	
	// load and display image
	var img = new Image();
	var current_image_index = home_image_index;
	
	home_image_index = IncreasedIndex(home_image_index, home_images.length);
	
	$(img)
		.load(function () {
			// fade out previous image and replace
			$(this).hide;
			$('#home_image_' + current_image_index).fadeOut(intFadeTime, function() {
				$('#home_image_' + current_image_index).replaceWith($(img).fadeIn(intFadeTime));
			});
		})
		.attr('src', home_images[home_image_index])
		.attr('id', 'home_image_' + home_image_index);	
}

$(document).ready(function() {
			
		// start image gallery when dom is ready
		StartImageGallery();
		
});
	

