// multi media player "DeLuxe Edition"
// items visible when carousel is not moving
var itemsshown=5;
// width of each item within the scroller (including margin between items)
var myitem=87;
// amount of items to be scrolled when moved
var scrollby=1;
// next button image
var nextImage= { FileName:'images/media_next.gif', Width:14, Height:63 };
// previous button image
var prevImage= { FileName:'images/media_prev.gif', Width:14, Height:63 };
// choose to switch carousel on (true) of off (false)
var carousel=false;
// choose pause time of carousel
var carspeed=5000;
// choose step speed of carousel
var step=2;
// set sizefit to true if you want images to be resized to fit the display area
var sizefit=true;
// choose how high the title layer should scroll up from the bottom of the the display area
var myendpoint=40;

// video player code to play .flv files (flow player), change settings for the look of the controls here
// for more info: http://flowplayer.org/documentation/configuration/
function loadVideo(vidloc) {	
	$f("div.player", "swf/flowplayer-3.1.2.swf",  {
		wmode: 'opaque',
		clip: {	url: vidloc,autoPlay: true,	autoBuffering: true	},				
		plugins:  {				
			// default controls with the same background color as the page background
			controls:  {
				autoHide: 'always',
				hideDelay: '2000',				
				play:true,         
				volume:true,         
				time:true,         
				stop:true,
				buttonColor: '#666666',
				buttonOverColor: '#999999',
				playlist:false,         
				fullscreen:true,
				backgroundColor: '#3e3e3e',
				backgroundGradient: 'yes',			
				all:false,
				scrubber:true,
				mute:true,
				height:30,
				progressColor: '#999999',
				bufferColor: '#666666',
				timeColor: '#ffffff'
			}
		},			
		canvas: { backgroundColor:'#f2f2f2',backgroundGradient: [0.1, 0] }			
	});	
}

// do not change these variables
var oid=0;var music=false;
var myThumbs=new Array();var ainnerDiv;var anxt;var aprv;
var scrollnr;var mybox;var myleft;var theleft;var timer;var trgt;var busy=false;var waiting;var strt=true;
var pid;var pageWidth;var pageHeight;
var curTop;var titletimer;var titletimer2;var firstup;var endpoint;var titleLayer;
// Determine file type and show content accordingly
function showContent(id) {
	var mediaDiv=document.getElementById('plyr');
	var vidObj=myVideos[id];	
	var vidcont;	
	if (vidObj.FileName.indexOf('.flv')>=1){	
		var vidloc=vidObj.FileName;
		mediaDiv.innerHTML='';
		loadVideo(vidloc);
	} else if (vidObj.FileName.indexOf('</object>')>=1){ 		
		var vidloc=vidObj.FileName;
		if (vidloc.match("width")) { vidloc=vidloc.replace(/width="[0-9]+"/g,"width=\"469\""); }
		if (vidloc.match("height")) { vidloc=vidloc.replace(/height="[0-9]+"/g,"height=\"334\""); }
		if (vidloc.match("<embed")) { vidloc=vidloc.replace(/<embed/,"<param wmode=\"transparent\"></param><embed wmode=\"transparent\""); }
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 			var ieversion=new Number(RegExp.$1);
 			if (ieversion>=6) { if (vidloc.match("<ob")) { vidloc=vidloc.replace(/<ob/,"<bob"); } }
		}
		mediaDiv.innerHTML=vidloc;
	}
	else { 
		var vidloc=new Image();	
		vidloc.src=vidObj.FileName;
		var plyrw=document.getElementById('plyr').offsetWidth;
		var plyrh=document.getElementById('plyr').offsetHeight;		
		if (sizefit==true) { vidcont='<div id="imgHolder"><img src="'+vidObj.FileName+'" width="'+plyrw+'" height="'+plyrh+'" border="0" /><div id="imgTitle">'+vidObj.Title+'</div></div>'; }
		else { vidcont='<div id="imgHolder"><table width="100%" height="100%"><tr><td align="center" valign="middle"><img src="'+vidObj.FileName+'" border="0" /></td></tr></table><div id="imgTitle">'+vidObj.Title+'</div></div>'; }			
		mediaDiv.innerHTML=vidcont;
		setimgTitle();
	}
}
// generate thumbnails, add onclick functionality and add extra thumbnails to make the carousel work visually
function boMediaPlayer() {
    if (myVideos.length > 0 && document.getElementById('ainner')) {
		ainnerDiv = document.getElementById('ainner');
		// set the next and previous buttons
		if (document.getElementById('anxt')) {
			anxt=document.getElementById('anxt');
			var nxtImg = document.createElement("IMG");
			nxtImg.src = '/images/spacer.gif'; nxtImg.width = nextImage.Width; nxtImg.height = nextImage.Height;
			nxtImg.onclick = function() { moveOn(); }
			anxt.appendChild(nxtImg);
		}
		if (document.getElementById('aprv')) {
			aprv=document.getElementById('aprv');
			var prvImg = document.createElement("IMG");
			prvImg.src = '/images/spacer.gif'; prvImg.width = prevImage.Width; prvImg.height = prevImage.Height;
			prvImg.onclick = function() { moveBack(); }
			aprv.appendChild(prvImg);
		}
		// generate thumbnails
		for(var i=0; i < myVideos.length; i++) {
			var newDiv = document.createElement("DIV");
			newDiv.className += "thumb";			
			var newImg = document.createElement("IMG");
			newDiv.style.backgroundImage = 'url('+myVideos[i].ThumbNail+')';
			if (myVideos[i].Title=='') { newImg.src = 'images/icon_vid.png'; }
			else { newImg.src = '/images/spacer.gif'; }
			newDiv.appendChild(newImg);	
			ainnerDiv.appendChild(newDiv); 
			newDiv.nr = i;
			newDiv.onclick=function() { showContent(this.nr); }			
			myThumbs.push(newDiv);
		}		
		if (myVideos.length > itemsshown) {
		    var n=0;
			for(var i=0; i<itemsshown; i++) { 
				var clonedNode = myThumbs[i].cloneNode(true);
				ainnerDiv.appendChild(clonedNode); clonedNode.nr = n; myThumbs.push(clonedNode);				
				clonedNode.onclick = function() { showContent(this.nr); }
				n=n+1;
			}
		}		
		if (myThumbs.length>0) { showContent(0); }
		moveinplace();
	}
}
// reset the carousel to starting point
function moveinplace() {
	scrollnr=(scrollby*myitem);	ainnerDiv.style.left='0px';
	var i=myThumbs;
	mybox=-(((i.length-1)*myitem)-(itemsshown*myitem));myleft=ainnerDiv.style.left;theleft=parseInt(myleft);showButtons(theleft);		
	// deals with automatic scrolling
	if (carousel==true && strt==false) { waiting=setTimeout("moveOn()",1); }
	if (carousel==true && strt==true) { strt=false;waiting=setTimeout("moveOn()",carspeed); }
	if (carousel==true) { 
		ainnerDiv.onmouseover=function() { carousel=false;clearTimeout(waiting); }
		ainnerDiv.onmouseout=function() { carousel=true;waiting=setTimeout("moveOn()",carspeed); } 
		if (anxt) anxt.onmouseover=function() { carousel=false;clearTimeout(waiting); }
		if (anxt) anxt.onmouseout=function() { carousel=true;waiting=setTimeout("moveOn()",carspeed); }
		if (aprv) aprv.onmouseover=function() { carousel=false;clearTimeout(waiting); }
		if (aprv) aprv.onmouseout=function() { carousel=true;waiting=setTimeout("moveOn()",carspeed); }
	}		
}
// next button/movement
function moveOn() {	
	trgt=theleft-scrollnr;
	if (trgt>=mybox && busy==false) { timer=setInterval("moveLeft("+trgt+");",4);busy=true; }
	else if (busy==false) { 
		var lastitems=(mybox+(-theleft))/myitem;
		if (lastitems<=0) { scrollnr=-((lastitems*myitem)-myitem);trgt=theleft-scrollnr;timer=setInterval("moveLeft("+trgt+");",4);busy=true; } 
		else { moveinplace();	if (carousel==false) { moveOn(); }	}		 
	}
}
function moveLeft(trgt) {
	if (theleft>trgt) {	theleft=theleft-step; ainnerDiv.style.left=(theleft+'px');	} 
	else { 
		clearInterval(timer); 
		if (theleft<trgt){ ainnerDiv.style.left=(trgt+'px');theleft=trgt; }
		busy=false;
		if (carousel==true) { waiting=setTimeout("moveOn()",carspeed); }
	}	
}
// previous button/movement
function moveBack() {		
	var startpoint=mybox;	
	if (theleft==0) { theleft=(startpoint-myitem);ainnerDiv.style.left=(startpoint-myitem+'px'); }
	trgt=theleft+scrollnr;
	if (trgt<0 && busy==false) { timer=setInterval("moveRight("+trgt+");",4);busy=true; }
	else if (busy==false) { 
		var lastitems=theleft/myitem;
		if (lastitems<0) { scrollnr=-(lastitems*myitem);trgt=theleft+scrollnr;timer=setInterval("moveRight("+trgt+");",4);	busy=true; } 
		else { moveinplace();moveBack(); }		 
	}
}
function moveRight(trgt) {
	if (theleft<trgt) {	theleft=theleft+step;ainnerDiv.style.left=(theleft+'px');	} 
	else { 
		clearInterval(timer); 
		if (theleft>trgt){ ainnerDiv.style.left=(trgt+'px');theleft=trgt; }
		scrollnr=(scrollby*myitem);	busy=false; 
	}	
}
// show buttons if there are more thumbnails than shown in the carousel
function showButtons(theleft) {
	if (mybox<0) { 
		if (anxt) { anxt.style.backgroundImage='url('+nextImage.FileName+')';anxt.style.cursor='pointer'; }
		if (aprv) { aprv.style.backgroundImage='url('+prevImage.FileName+')';aprv.style.cursor='pointer'; }
	}
}

// semi transparent title layer for fotos
function setimgTitle() {	
	clearTimeout(firstup);
	if (document.getElementById('imgTitle')) { titleLayer=document.getElementById('imgTitle'); }
	myImg=document.getElementById('imgHolder').getElementsByTagName("img");
	if (music==false) {
		endpoint=myendpoint;
		myImg[0].onmouseover=function() { showImgTitle(); }
		myImg[0].onmouseout=function() { hideImgTitle(); }
		showImgTitle();	firstup=setTimeout("hideImgTitle()",3000);
	} else { music=false;endpoint=myendpoint+20;showImgTitle(); }
}
function showImgTitle() { clearTimeout(firstup);clearInterval(titletimer);clearInterval(titletimer2);titletimer=setInterval("comeUp();",5); }
function comeUp() {		
	if (titleLayer) {
		curTop=titleLayer.style.marginTop;curTop=curTop.replace("px","");
		if (curTop>-endpoint) { curTop=curTop-1;titleLayer.style.marginTop=curTop+"px";} 
		else { clearInterval(titletimer);titleLayer.style.marginTop=-endpoint+"px";curTop=-endpoint; }
	}
}
function hideImgTitle() { clearTimeout(firstup);clearInterval(titletimer);clearInterval(titletimer2);titletimer2=setInterval("comeDown();",5); }
function comeDown() {		
	if (titleLayer) {
		if (curTop<0) { curTop=curTop+1;titleLayer.style.marginTop=curTop+"px";} 
		else { clearInterval(titletimer2);titleLayer.style.marginTop=0+"px"; }
	}
}
