/*
* Author:      Marco Kuiper (http://www.marcofolio.net/)
*/

// Speed of the automatic slideshow
var slideshowSpeed = 10000;
//"title" : "<p>We invite you to join our diverse community of scholars.<a href=\"#\">Read More</a><p>",

// Variable to store the images we need to set as background
// which also includes some text and url's.
var photos = [  {
		<!--"title" : "<p>We invite you to join our diverse community of scholars.<p>",-->
		"image" : "wp10.jpg",
		"url" : "http://www.sxc.hu/photo/1221065",
		"text" : "Administration with Integrity",
		"mainright" : "Shaping careers and transforming lives"
	}, {
		<!--"title" : "<p>We invite you to join our diverse community of scholars.<p>",-->
		"image" : "wp11.jpg",
		"url" : "http://www.sxc.hu/photo/1271915",
		"text" : "Promote the inquisitive nature4",
		"mainright" : "Rekindling a quest for knowledge"
	}
];



jQuery(document).ready(function() {
		
	// Backwards navigation
	jQuery("#back").click(function() {
		stopAnimation();
		navigate("back",'');
		interval = setInterval(function() {
			navigate("back",'');	
		}, slideshowSpeed);
		
	});
	
	// Forward navigation
	jQuery("#next").click(function() {
		stopAnimation();
		navigate("next",'');
		
			
		
		interval = setInterval(function() {
			navigate("next",'');	
		}, slideshowSpeed);
	});
	
	
	jQuery(".gotoimage").click(function() {
		stopAnimation();
		var arraNew= new Array();
		var id = jQuery(this).attr("href"); 
		id=id.substring(1);
		
		
		//alert(id.substring(1));
		//showImage(photos[id - 1], id, id);
		var accutalId =  parseInt(id);
		//var accutalId =  parseInt(arraNew[1])+1;
		navigate("next",accutalId);
		//navigate("next",arraNew[1]);
		interval = setInterval(function() {
		//alert(arraNew[1]);								
										
		
		if(accutalId>=5)
		{
		accutalId=1;	
		}else
		{
		accutalId++;
		}
		//alert(accutalId);								
			navigate("next",accutalId);
		}, slideshowSpeed);
		
	});
	
	
	var interval;
	
	
	
	
	
	
	var activeContainer = 1;	
	var currentImg = 0;
	var animating = false;
	var navigate = function(direction, goimage) {
		// Check if no animation is running. If it is, prevent the action
		if(animating) {
			return;
		}
		
		// Check which current image we need to show
		if(direction == "next") {
			currentImg++;
			if(currentImg == photos.length + 1) {
				currentImg = 1;
			}
		} else {
			currentImg--;
			if(currentImg == 0) {
				currentImg = photos.length;
			}
		}
		
		//alert(currentImg);
		// Check which container we need to use
		var currentContainer = activeContainer;
		
		if(goimage!='')
		{
			currentImg= goimage;
		}
		
		
		showImage(photos[currentImg - 1], currentContainer, currentImg);
		
	};
	
	var currentZindex = -1;
	var showImage = function(photoObject, currentContainer, activeContainer) {
		animating = true;
		
		// Make sure the new container is always on the background
		currentZindex--;
		//jQuery(".headerimg").css("display" , "none");
		
		//jQuery("#headerimg1").css('display',"none");
		//alert(activeContainer);
		// Set the background image of the new active container photoObject.image
		
		//jQuery("#headerimg1").css({
			//"background-image" : "url(http://shopping.ckcsons.com/images/" + wp10.jpg + ")"
			
		//});
		
		
		// Hide the header text
		//jQuery("#headertxt").css({"display" : "none"});
		
		
		//jQuery("#headerimg" + activeContainer).css("display" , "block");
		
		
		
		// Set the new header text
		jQuery("#text").html(photoObject.text);
		jQuery("#mainright")
			.attr("href", photoObject.url)
			.html(photoObject.mainright);
		jQuery("#transptextright").html(photoObject.title);
		//jQuery("#transptextright").html("dfgdf");
		
		// Fade out the current container
		// and display the header text when animation is complete
		/*jQuery("#headerimg" + activeContainer).fadeIn(function() {
			setTimeout(function() {
				jQuery("#headertxt").css({"display" : "block"});
				animating = false;
			}, 1500);
		});*/
		//jQuery("#headerimg" + activeContainer).fadeOut('slow'function() {;
		
				jQuery(".gotoimage").removeClass("current");
		jQuery("#round"+ activeContainer).addClass("current");

		
		jQuery("#headerimg1").fadeIn('slow', function() {
   		setTimeout(function() {
				//jQuery("#headertxt").css({"display" : "block"});
				animating = false;
			}, 1500);
  		});
		
		
	};
	
	var stopAnimation = function() {
		// Change the background image to "play"
		jQuery("#control").css({ "background-image" : "url(../images/btn_play.png)" });
		
		// Clear the interval
		clearInterval(interval);
	};
	
	// We should statically set the first image
	navigate("next",'');
	
	// Start playing the animation
	interval = setInterval(function() {
		navigate("next",'');
	}, slideshowSpeed);
	
});
