// JavaScript Document
/*
Written by streetpuppy@gmail.com for temporadio.co.uk
*/
function getAjaxVideo(event) {
		var myClass = $(this).attr('class');
		var id = myClass.substr(9,myClass.length);
		event.preventDefault();
		location.href="#videobox";
		location.hash=id;
		$("#videobox").load("/system/modules/video_ext/templates/ajax_video_helper.tpl.php?selected="+ id,{ videoid: id})
}
function nextAjaxVideo(event) {

	currVid++;
	if (vidArray.length == currVid) currVid = 0;
	
   $("#videobox").load("/system/modules/video_ext/templates/ajax_video_helper.tpl.php",{videoid: vidArray[currVid]});
	event.preventDefault();	
}
function previousAjaxVideo(event) {
	if (currVid == 0 ) { currVid = vidArray.length -1 	} else { currVid-- }
	
   $("#videobox").load("/system/modules/video_ext/templates/ajax_video_helper.tpl.php",{videoid: vidArray[currVid]});
	event.preventDefault();

}
$(document).ready(function(){
	$("a[class*=videoshow]").click(getAjaxVideo);
	$("#nextVideo").click(nextAjaxVideo);
	$("#previousVideo").click(previousAjaxVideo);
});

window.onVideoEnd = function() {
	if (document.videoController.autoplay[0].checked) {
		nextAjaxVideo();
	}
}