//reference: http://davidwalsh.name/mootools-slideshow
window.addEvent('domready',function() {
	
	/* settings */
	var showDuration = 7000;
	var container = $('slideshow');
	var navlinks = $$('#slide-nav li a'); //be specific or you will break nex/prev
	var images = container.getElements('div');
	var currentIndex = 0; //slide showing
	var next = 1; //slide to show
	var interval;
	
	/* start and stop functions */
	var start = function() { interval = show.periodical(showDuration);};
	var stop = function() { $clear(interval); };

	/* opacity and fade */
	images.each(function(img,i){ 
		if(i > 0) {
			img.set('opacity',0);
		}
	});
	
	/* worker */
	var show = function() {
		next = parseFloat(next); //make sure int
		if(next > images.length -1 || next < 0 || !$defined(next) ) {
			next = 0;
		}
		//console.log("next is: " + next + "\n currentIndex is: " + currentIndex); //debug
		
		images[currentIndex].fade('out');
		images[next].fade('in');
		
		currentIndex = next; //current image
		next = currentIndex + 1; //next image
	};
	
	/* new: control: start/stop on mouseover/mouseout */
	container.addEvents({
		mouseenter: function() { stop(); },
		mouseleave: function() { start(); }
	});
	
	navlinks.addEvent('click', function(event){
		//stop page from reloading (only needed for get pages, shouldn't need for sh404sef)
		event.stop();
		
		var part = this.getProperty('href'); //get href value
		next = part.substring(6); //just get the number
		stop();show(); //stop show, next slide
	});
	
	$('next').addEvent('click', function(event){
		event.stop();//stop page from reloading 
		next = currentIndex + 1; //just get the number
		stop();show(); //stop show, next slide
	});
	
	$('previous').addEvent('click', function(event){
		event.stop();//stop page from reloading 
		next = (currentIndex - 1 < 0) ? images.length -1 : currentIndex - 1;
		stop();show(); //stop show, next slide
	});

	/* start once the page is finished loading */
	window.addEvent('load',function(){
		//load images
		start();
	});

});

function livepop() {

	url = 'http://www.nickyeoman.com/live-chat/?tmpl=component';
	window.open (url, "mywindow","location=1,status=1,scrollbars=1, width=400,height=400");
}
