nextSlide = function(shows){
	shows.each(function(show,i){
		(function(){show.next();}).delay(200*i);
	});
}

window.addEvent('domready', function() {

	myEffect = new Array(4);
	myTextEffect = new Array(4);
	
	$$('#buttons .button').each(function(el,i){
		
		el.addEvent('mouseenter', function(){
			showFullButton(el,i);
		});
		
		el.addEvent('mouseleave', function(){
			hideFullButton(el,i);
		});
		
		var panel = el.getChildren('.label');
		var text = panel[0].getChildren('.text');
		myTextEffect[i] = new Fx.Slide(text[0], {duration: 150, link:'cancel'}).hide();
		
	});	

	var myShows = new Array(4);
	var showcount = 0;

	$$('#buttons .button .bgimage').each(function(el,i){
		
		var request = new Request.JSON({
			url: 'ajax/homebtn.php?id='+(i+1),
			onComplete: function(jsonObj) {
				
				myShows[i] = createBtnShow(jsonObj,el);
								
			}
		}).send();
		
	});
	
	(function(){nextSlide(myShows);}).periodical(6000);

	new Request.JSON({
		url: 'ajax/home.php',
		onComplete: function(jsonObj) {
			
			var data = jsonObj;
			var myShow = new Slideshow('mainshow', data, { 
				delay: 7000,
				captions: false, 
				controller: false, 
				loader: false, 
				width: 933, 
				height: 353,
				slide: 0,
				paused: false,
				thumbnails: false,
				hu: 'images/home/',
				//transition: Fx.Transitions.easeIn
				overlap: true
			});


		}
	}).send();
	
	/*
	$f("player", "include/flowplayer/flowplayer.commercial-3.1.5.swf", { 
	    key: '#$972f4404d7c265b4ef7', 
		clip: { 
	        url: 'videos/DEMO_2010_RF_SHORT.f4v', 
	        autoPlay: true, 
	        autoBuffering: true,
			onFinish: function(){this.hide();},
			onStop: function() {this.hide();} 
	    }, 
	    canvas:  { 
		    // configure background properties 
		    background: 'url(/images/preloader_bg.jpg)',
		    // remove default canvas gradient 
		    backgroundGradient: 'none', 
		 	// setup a light-blue border 
		    border:'none' 
		},
		plugins: { 
		    controls: { 
		        url: 'flowplayer.controls-3.1.5.swf', 
		 		// display properties 
		        bottom:4, 
				right:0,
				width: 30,
		        backgroundColor: 'transparent', 
		        backgroundGradient: 'none', 
		 		buttonColor: '#999999',
		        // controlbar-specific configuration 
		        fontColor: '#000000', 
		        timeFontColor: '#333333', 
		        autoHide: 'never', 
		 		hideDelay: 100,
				
		        // which buttons are visible and which are not? 
		        all: false,
				mute:true
		     
		    },
			stopper: { 
		        url: 'flowplayer.controls-3.1.5.swf', 
		 
		        // display properties 
		        top:3, 
				right:4,
				width: 30,
		        backgroundColor: 'transparent', 
		        backgroundGradient: 'none', 
		 		buttonColor: '#999999',
		        // controlbar-specific configuration 
		        fontColor: '#000000', 
		        timeFontColor: '#333333', 
		        autoHide: 'never', 
		 		hideDelay: 100,
				
		        // which buttons are visible and which are not? 
		        all: false,
				stop: true
		     
		    }
		}
	});
	$f("player").play().setVolume(100);
	$("player").style.zIndex=40;
	$f("player").show();
	$('player').fade("in");
	*/
});

function createBtnShow(data,element){
	var myShow = new Slideshow(element, data, { 
		duration: 300,
		//classes: ['', '', '', '', '', '', '', 'alternate-images'],
		delay: 7000,
		captions: false, 
		controller: false, 
		loader: false, 
		width: 225, 
		height: 125,
		slide: 0,
		paused: true,
		thumbnails: false,
		//transition: Fx.Transitions.easeIn
		overlap: true
	});
	
	return myShow;
}

function showFullButton(el,i){
	
	myTextEffect[i].slideIn();

}

function hideFullButton(el,i){
	
	myTextEffect[i].slideOut();
	
}