var switchImageTime = 5000;
var fadeTime = 1500;
var intervalId = false;

/* DO NOT CHANGE BELOW */
var imageCount = 0;
	
$(document).ready(function(){
	
	setListIds();
	if (imageCount > 1) {
		setTimer();
	}
	
	// initialize fancybox for video links
	$("a.playVideo").fancybox({
		'width'			:	640,
		'height'		:	480,
		'titleShow'		:	false,
		'onStart'		:   clearTimer,
		'onClosed'		:	setTimer
	});
	
$("a.playVideoAlt").click(function() {
	   $.fancybox({
	    'autoScale'     : false,
	    'transitionIn'  : 'none',
	    'transitionOut' : 'none',
	    'title'         : this.title,
	    'width'         : 640,
	    'height'        : 385,
	    'href'          : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
	    'type'          : 'swf',
	    'swf'           : {
	    'wmode'             : 'transparent',
	    'allowfullscreen'   : 'true'
	     }
	  });
	  return false;
	});	
});

function setTimer() {
	intervalId = setInterval( switchImage, switchImageTime);
}

function clearTimer() {
	clearInterval( intervalId );
}

function setListIds() {
	
	$('#'+imagesDiv+' li').each(function(index, element){	
		$(element).attr("id", index+1);
		imageCount++;
	});
}

function switchImage() {
	
	var active = $('#'+imagesDiv+' li.active');
		
	var next = active.next();
	
	if (next.length == 0) next = $('#'+imagesDiv+' li:first');
	
	active.fadeOut(2000, function() {
		active.removeClass('active');
	});
	
	next.fadeIn(2000, function() {
		next.addClass('active');
	});
	
/*	active.hide("slide", { direction: "left" }, 1000, function() {
		active.removeClass('active');
	});
	
	next.show("slide", {direction: "right" }, 1000, function() {
		next.addClass('active');
	});
*/	
}
