// JavaScript Document

	var imgArray=null;
	var myReqObj =null;
	var timerInterval;
	var index=0;
	var pageContent=null;
	var timer = 10000; //timer is in milliseconds
	
	
	window.onload=function(){
		new Ajax.Request('getImages.php',
										{
										method 	   : 'post',
										parameters : 'null=null',
										onComplete : function(ajaxObj){
											eval('myReqObj = '+ajaxObj.responseText);
											for(i in myReqObj){
												switch(i){
													case 'filePath':
														imgArray = myReqObj[i];
														break;
												}
											}
											startTimer();
											//setTimeout('startTimer()', timer);											
											
										}
										});
	
	}
	function displayContent(){
		var te = document.getElementById('home_photo');
		te.src=(imgArray[index]+'.jpg');
		var textContent = document.getElementById('home_photo_caption');
		textContent.innerHTML='';
		textContent.innerHTML= pageContent;
		
	}
	
	function fateEffect(effect){
		var type=0;
		if(effect=='in'){
			type=100;
		}
		new Rico.Effect.FadeTo('container',
								type,//opacity
								800, //milisecond
								10,  //steps
								{
								complete:function(){
									if(type==0){
										displayContent();
									}
								}});
	}
	
	function getContent(index){
		new Ajax.Request( (imgArray[index]+'.html') ,
										{
										method 	   : 'post',
										parameters : 'null=null',
										onComplete : function(ajaxObj){
											pageContent = ajaxObj.responseText;										
											displayContent();
											
										}
										});
	}
	
	function getRandom(){
	
		index = Math.floor(Math.random() * imgArray.length);
		getContent(index);
		
	}
	
	function startTimer(){
	timerInterval = setInterval("getRandom()", timer);
	
	
	}