// JavaScript Document

document.observe("dom:loaded", function(){
	
	setupCaptions();
	imgCycle();
	
});


function setupCaptions(){
	var imgCap=$('img_list').select('li p');
	var imgLink=$('img_list').select('li a');
	
	
	for(var i=0; i <3; i++){
		imgCap[i].hide();
	}
	
	/*imgLink[0].observe("mouseover", function(){
		Effect.BlindDown(this.next('p'), {scaleX: true, scaleY: false, duration: 1.0});	
	});*/
	for (var x=0; x<3; x++){
		imgLink[x].observe("mouseenter", function(){
			if(this.next('p').getWidth() <= 200){
			Effect.BlindDown(this.next('p'), {scaleX: true, scaleY: false, duration: 1.0});
			}								  
												  
			//var cap = this.next('p');
			//if(!cap.visible()){
				//cap.show();
			//}
			
		});
		imgLink[x].observe("mouseleave", function(){
			//var cap = this.next('p');
			//cap.hide();
			if(this.next('p').getWidth() >= 200){
			Effect.BlindUp(this.next('p'), {scaleX: true, scaleY: false, duration: 1.0});
			}
		});
	}
} 

function imgCycle(){
	var canvas=$('canvas');
	var imgLink=$('img_list').select('li a');
	
	var newDiv= new Element ('div');
	newDiv.style.width= 696+"px";
	newDiv.style.height= 184+"px";
	newDiv.style.zIndex= 15;
	
	var currentImg=0;
	

	// var img1= imgLink[0].readAttribute('name');
	// var img2= imgLink[1].readAttribute('name');
	// var img3= imgLink[2].readAttribute('name');
	
	setInterval(function(){
			if(currentImg !=2){
					currentImg++	
			}else{
					currentImg=0;	
			}
			var src= 'url' + '('+ imgLink[currentImg].readAttribute('name') +')';
				var src= 'url' + '('+ imgLink[currentImg].readAttribute('name') +')';
				
			//alert(Math.floor(3*Math.random()));
			var oldDiv=$('canvas').firstDescendant();
			oldDiv.remove();
			canvas.insert({top:newDiv});
			newDiv.hide();
			newDiv.style.backgroundImage = src;
			newDiv.appear();
	}, 7000);
	
//	canvas.addClassName('pic1');
	
	imgLink.each(function(link){
		link.imgsrc = 'url' + '('+ link.readAttribute('name') +')';
		link.observe("mouseover",function(e){
			var oldDiv=$('canvas').firstDescendant();
			if(oldDiv.style.backgroundImage != this.imgsrc){
				// alert(this.imgsrc);
				oldDiv.remove();
				canvas.insert({top:newDiv});
				newDiv.hide();
				newDiv.style.backgroundImage = this.imgsrc;
				newDiv.appear();
				currentImg=imgLink.indexOf(this);
			}
		})
	})

	/*
	imgLink[0].observe("mouseover", function(){
		if(!this.active){
			var oldDiv=$('canvas').firstDescendant();
			oldDiv.remove();
			canvas.insert({top:newDiv});
			newDiv.hide();
			newDiv.style.backgroundImage = 'url' + '('+ img1 +')';
			newDiv.appear();
		}
	})
	imgLink[1].observe("mouseover", function(){
		var oldDiv=$('canvas').firstDescendant();
		oldDiv.remove();
		canvas.insert({top:newDiv});
		newDiv.hide();
		newDiv.style.backgroundImage = 'url' + '('+ img2 +')';
		newDiv.appear();
	})
	imgLink[2].observe("mouseover", function(){
		var oldDiv=$('canvas').firstDescendant();
		oldDiv.remove();
		canvas.insert({top:newDiv});
		newDiv.hide();
		newDiv.style.backgroundImage = 'url' + '('+ img3 +')';
		newDiv.appear();
	})
	*/
}