addLoadEvent(dropdownNav);
addLoadEvent(prepareFilmStrip);

function writeText(s,d) {

	var o = document.getElementById(d);
	if (o != null) {
		o.innerHTML = s;
		//alert(s);	
	}
}

//Return object with query variables
function getArgs() {
	var args = new Object();
	var query= location.search.substring(1);
	var pairs = query.split(",");
	for (var i = 0;i < pairs.length; i++ ) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		args[argname] = unescape(value);
	}
	return args;
}
function dropdownNav(){
		var navRoot = document.getElementById('nav');
		var li_list = navRoot.getElementsByTagName('li');
		for (var i=0; i<li_list.length; i++){
			li_list[i].onmouseover = function(){
					for (var n=0; n<this.childNodes.length; n++){
							var ul_node = this.childNodes[n];
							if (ul_node.nodeName == 'UL'){
									this.childNodes[n].className += ' over';

							}
					}
			}
			li_list[i].onmouseout = function(){
					for (var n=0; n<this.childNodes.length; n++){
							var ul_node = this.childNodes[n];
							if (ul_node.nodeName == 'UL'){
									this.childNodes[n].className = '';

							}
					}
			}
		}

}
function prepareFilmStrip(){
	if (!document.getElementById('videoStripMoving')){
		return;
	}
	var videoStripMoving = document.getElementById('videoStripMoving');
	    videoStripMoving.style.left="0px";
	    videoStripMoving.style.top="0px";
	//in px
	var viewer = 402;
	var right_arrow = document.getElementById('moveRight');
	var left_arrow = document.getElementById('moveLeft');

	var right_final_x = -(videoStripMoving.clientWidth - viewer);
	var left_final_x = 0;
	var final_y = 0;
	var interval = 10;
	right_arrow.onmousedown = function(){
		moveElement(videoStripMoving.getAttribute('id'), right_final_x, final_y, interval);
	}
	right_arrow.onmouseup = function(){
		clearTimeout(movement);
	}
	left_arrow.onmousedown = function(){
		moveElement(videoStripMoving.getAttribute('id'), left_final_x, final_y, interval);
	}
	left_arrow.onmouseup = function(){
		clearTimeout(movement);
	}

}

var movement;
function moveElement(elementID, final_x, final_y, interval) {
  var elem = document.getElementById(elementID);

if (elem.movement){
	clearTimeout(elem.movement);
 }

  var xpos = parseInt( elem.style.left );
  var ypos = parseInt( elem.style.top );
  if ( xpos == final_x && ypos == final_y ) {
    return true; 
  }
  if (xpos < final_x) { xpos += 2; }
  if (xpos > final_x) { xpos -=2; }
  if (ypos < final_y) { ypos += 2; }
  if (ypos > final_y) { ypos -=2; }

  elem.style.left = xpos + "px";
  elem.style.top = ypos + "px";

  var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
  movement = setTimeout(repeat, interval);
}

//generic value churner by Hesido (wwww.hesido.com)
function easeInOut( opacStart, opacEnd, steps, thisStep, powr ){
     var NumDifference = opacEnd - opacStart;
     var increaseStepAmt = opacStart + (Math.pow((( 1 / steps ) * thisStep), powr ) * NumDifference );
     return Math.ceil(increaseStepAmt);
}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
	window.onload = func;
  } else {
	window.onload = function() {
	  if (oldonload) {
		oldonload();
	  }
	  func();
	}
  }
}
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/-/g, "\-");
	var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
