


/** Function: onPageLoad
*
*	Pageload functions here
*/
function onPageLoad() {
	// preload load.gif
	loadImage = new Image();
	loadImage.src = '/images/ajaxload.gif';
}
function hoverplay(e) {
	// remove
	if($('playdiv')) $('playdiv').remove();
	
	// create
	playdiv = document.createElement('div');
	playdiv.setAttribute('id', 'playdiv');
	playdiv.setAttribute('class', 'playdiv');
	$(playdiv).innerHTML = 'Play';
	$(playdiv).hide();
	
	// fix style
	$(playdiv).style.position = 'absolute';
	$(playdiv).style.top = '2px';
	$(playdiv).style.left = '2px';
	$(playdiv).style.width = '127px';
	$(playdiv).style.height = '102px';
	$(playdiv).style.lineHeight = '100px';
	$(playdiv).style.textAlign = 'center';
	$(playdiv).style.background = 'black';
	$(playdiv).style.cursor = 'pointer';
	$(playdiv).style.zIndex = '10';
	
	// append and display
	$(e).appendChild(playdiv);
	Effect.Appear(playdiv, {duration: 0.4, from:0.0, to:0.8});
}
function unhoverplay(e) {
	if($('playdiv')) Effect.Fade('playdiv', {duration:0.4});
}
function play(thumb, id, params) {
	children = $('right').getElementsByClassName('imglink');
	for(i=0; i<children.length; i++) children[i].style.background = '#bbb';
	
	$(thumb).style.background = 'black';
	el = 'item';
	$(el).hide();
	
	var loading = document.createElement('div');
	loading.setAttribute('class', 'loading');
	loading.setAttribute('id', 'loading');
	$(loading).innerHTML = '<img src="/images/ajaxload.gif" alt="" />';
	$('left').appendChild(loading);
	
	new Ajax.Updater(el, '/video.php', {
		method: 'get',
		asynchronous:true,
		parameters: params,
		evalScripts: true,
		onComplete: function() {
			Effect.Appear(el, {duration:0.7});
			$(loading).remove();
		}
	});
}
var noclick=0;
var blockheight=470;
function scroll(dir) {
	if(noclick==1) return;
	totalpages = totalthumbs/perpage;
	
	if(dir == 'east') {
		if(currentpage != totalpages) {
			new Effect.Move('thumbswrapperdiv',{ x: 0, y: -blockheight, mode: 'relative', beforeStart:function(){noclick=1}, afterFinish:function(){noclick=0}});
			currentpage = currentpage+1;
		}
		else {
			new Effect.Move('thumbswrapperdiv',{ x: 0, y: (blockheight*totalpages)-blockheight, mode: 'relative', beforeStart:function(){noclick=1}, afterFinish:function(){noclick=0}});
			currentpage = 1;
		}
	}
	else if(dir == 'west') {
		if(currentpage != 1) {
			new Effect.Move('thumbswrapperdiv',{ x: 0, y: blockheight, mode: 'relative', beforeStart:function(){noclick=1}, afterFinish:function(){noclick=0}});
			currentpage = currentpage-1;
		}
	}
	else if(dir <= totalpages && dir > 0) {
		jumpto = (currentpage-dir)*blockheight;
		new Effect.Move('thumbswrapperdiv',{ x: 0, y: jumpto, mode: 'relative', beforeStart:function(){noclick=1}, afterFinish:function(){noclick=0}});
		currentpage = dir;
	}
	
	children = $('pagination').immediateDescendants();
	for(i=0; i<children.length; i++) {
		if(children[i].innerHTML == currentpage) {
			children[i].className = 'active';
		}
		else children[i].className = '';
	}
	if(currentpage == 1) {
		$('prev').className = 'disabled';
		$('prev').style.cursor = 'default';
	}
	else {
		$('prev').className = '';
		$('prev').style.cursor = 'pointer';
	}
//	if(currentpage == totalpages) {
//		$('next').className = 'disabled';
//		$('next').style.cursor = 'default';
//	}
//	else {
//		$('next').className = '';
//		$('next').style.cursor = 'pointer';
//	}
}

function containsDOM (container, containee) {
  var isParent = false;
  do {
    if ((isParent = container == containee))
      break;
    containee = containee.parentNode;
  }
  while (containee != null);
  return isParent;
}

function checkMouseEnter (element, evt) {
  if (element.contains && evt.fromElement) {
    return !element.contains(evt.fromElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}

function checkMouseLeave (element, evt) {
  if (element.contains && evt.toElement) {
    return !element.contains(evt.toElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}

/** Windows onload
*
*	Run onload functions
*/
window.onload = function() {
	if(window.onPageLoad) onPageLoad();
}