/*  
 *--------------------------------------------------------------------------
 *	Prototype JavaScript framework
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details, see the Prototype web site: http://prototype.conio.net/
/*--------------------------------------------------------------------------*/

//note: modified & stripped down version of prototype, to be used with moo.fx by mad4milk (http://moofx.mad4milk.net).

var Class = {
	create: function() {
		return function() {
			this.initialize.apply(this, arguments);
		}
	}
}

Object.extend = function(destination, source) {
	for (property in source) destination[property] = source[property];
	return destination;
}

Function.prototype.bind = function(object) {
	var __method = this;
	return function() {
		return __method.apply(object, arguments);
	}
}

Function.prototype.bindAsEventListener = function(object) {
var __method = this;
	return function(event) {
		__method.call(object, event || window.event);
	}
}

function $() {
	if (arguments.length == 1) return get$(arguments[0]);
	var elements = [];
	$c(arguments).each(function(el){
		elements.push(get$(el));
	});
	return elements;

	function get$(el){
		if (typeof el == 'string') el = document.getElementById(el);
		return el;
	}
}

if (!window.Element) var Element = new Object();

Object.extend(Element, {
	remove: function(element) {
		element = $(element);
		element.parentNode.removeChild(element);
	},

	hasClassName: function(element, className) {
		element = $(element);
		if (!element) return;
		var hasClass = false;
		element.className.split(' ').each(function(cn){
			if (cn == className) hasClass = true;
		});
		return hasClass;
	},

	addClassName: function(element, className) {
		element = $(element);
		Element.removeClassName(element, className);
		element.className += ' ' + className;
	},
  
	removeClassName: function(element, className) {
		element = $(element);
		if (!element) return;
		var newClassName = '';
		element.className.split(' ').each(function(cn, i){
			if (cn != className){
				if (i > 0) newClassName += ' ';
				newClassName += cn;
			}
		});
		element.className = newClassName;
	},

	cleanWhitespace: function(element) {
		element = $(element);
		$c(element.childNodes).each(function(node){
			if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) Element.remove(node);
		});
	},

	find: function(element, what) {
		element = $(element)[what];
		while (element.nodeType != 1) element = element[what];
		return element;
	}
});

var Position = {
	cumulativeOffset: function(element) {
		var valueT = 0, valueL = 0;
		do {
			valueT += element.offsetTop  || 0;
			valueL += element.offsetLeft || 0;
			element = element.offsetParent;
		} while (element);
		return [valueL, valueT];
	}
};

document.getElementsByClassName = function(className) {
	var children = document.getElementsByTagName('*') || document.all;
	var elements = [];
	$c(children).each(function(child){
		if (Element.hasClassName(child, className)) elements.push(child);
	});  
	return elements;
}

//useful array functions
Array.prototype.each = function(func){
	for(var i=0;ob=this[i];i++) func(ob, i);
}

function $c(array){
	var nArray = [];
	for (i=0;el=array[i];i++) nArray.push(el);
	return nArray;
}// some variables to save
var currentPosition;
var currentVolume;
var currentItem;

// these functions are caught by the JavascriptView object of the player.
function sendEvent(typ,prm) { thisMovie("mpl").sendEvent(typ,prm); };

/*
function getUpdate(typ,pr1,pr2,pid) {
	if(typ == "time") { currentPosition = pr1; }
	else if(typ == "volume") { currentVolume = pr1; }
	else if(typ == "item") { currentItem = pr1; setTimeout("getItemData(currentItem)",100); }
	var id = document.getElementById(typ);
	id.innerHTML = typ+ ": "+Math.round(pr1);
	pr2 == undefined ? null: id.innerHTML += ", "+Math.round(pr2);
	if(pid != "null") {
		document.getElementById("pid").innerHTML = "(received from the player with id <i>"+pid+"</i>)";
	}
};
*/

// These functions are caught by the feeder object of the player.
function loadFile(obj) { if(thisMovie("mpl")) thisMovie("mpl").loadFile(obj); };
function addItem(obj,idx) { if(thisMovie("mpl")) thisMovie("mpl").addItem(obj,idx); }
function removeItem(idx) { if(thisMovie("mpl")) thisMovie("mpl").removeItem(idx); }
function getItemData(idx) {
	var obj = thisMovie("mpl").itemData(idx);
	var nodes = "";
	for(var i in obj) { 
		nodes += "<li>"+i+": "+obj[i]+"</li>"; 
	}
	document.getElementById("data").innerHTML = nodes;
};

// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
    if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
};


var zgMovie = Class.create();

zgMovie.prototype = {
		initialize: function(id, filename) {
			this.id = id;
			this.filename = filename;

		}  		
};

var zgPlayer = Class.create();

zgPlayer.prototype = {
	initialize: function() {
		this.movies = Array();
	  	this.count = 0;
	  	this.current = -1;			
		this.start_at_movie = 0;
		this.start_at_specific = false;
		this.oneTimeInit = false;	  	
	}, 
	add: function(movie) {			
		this.movies[this.count] = movie;
		this.count++;
	},
	play: function() {
		//test_ start at specific point in playlist entry
		//first time only
		//when page is manually reloaded only...
		//oherwise call directly!
		if(this.start_at_specific && !this.oneTimeInit) {
			iCountMax = 0;
			iMax = this.movies.length;
			while(((aMovie = this.next()) || true) && iCountMax<iMax) {
				iCountMax++;
				//alert(aMovie.id);
				//alert(this.start_at_movie);
				if(aMovie.id==this.start_at_movie) {
					//alert("movie_id direct" + aMovie.id);
					this.oneTimeInit = true;
					this.start_at_specific = false;
					if(window.parent) {
						window.parent.movie_flash_play(aMovie.id, aMovie.filename);	
					} else {
						movie_flash_play(aMovie.id, aMovie.filename);
					}										
					break;
				}						
			}
			
			if(!this.oneTimeInit) {
				//alert("movie not found starting at the beginning of the playlist...");
				this.oneTimeInit = true;
				this.start_at_specific = false;
				this.current = -1;
				this.play();
			}
						
		} else {
			var aMovie = this.next();
			if(aMovie) {
				if(window.parent) {
					window.parent.movie_flash_play(aMovie.id, aMovie.filename);	
				} else {
					movie_flash_play(aMovie.id, aMovie.filename);
				}
			}			
		}

	},
	next: function() {
		if((this.current+1) < this.movies.length) {
			this.current++;				
		} else {
			this.current = 0;
		}
		if(this.current<this.movies.length) {
			return this.movies[this.current];	
		} else {
			return false;
		}			
	},
	current: function() {
		if(this.current<this.movies.length) {
			return this.movies[this.current];	
		} else {
			return false;
		}
	}		
};

function prepare_player() {
  s1.addParam('allowfullscreen','true');
  s1.addVariable("javascriptid","mpl"); 
  s1.addVariable('displayheight','288'); 
  s1.addVariable('frontcolor','0xFFFFFF');
  s1.addVariable('backcolor','0x86B003');
  s1.addVariable('lightcolor','0xFFFFFF');
  s1.addVariable('showicons','false');
  s1.addVariable('height','308'); 
  s1.addVariable('width','512'); 
  s1.addVariable('showdigits','false'); 
  s1.addVariable('autostart','false'); 
  s1.addVariable("enablejs","true");
  s1.write('player1');	
}

