/**
 * @author gallema1
 */
function mediaObject(obj,index){
	this.obj = obj;
	this.rootCanvas = this.obj.FindName('rootCanvas');
	this.index = index;
	this._width = obj.Width;
	this._height = obj.Height;
	this.scaleX = 1.5;
	this.scaleY = 1.5;
	this.storyboard;
	
	this.init();
}
mediaObject.prototype.init = function(){
	//Control Butons
	this.btn_play = this.obj.FindName('play' + this.index);
	this.mediaElement = this.obj.FindName('media' + this.index);
	this.player_mask = this.obj.FindName('player_mask' + this.index);
	//this.btn_stop = this.obj.FindName('stop'+ this.index);
	//this.btn_forward = this.obj.FindName('forward' + this.index);
	//this.btn_back = this.obj.FindName('back' + this.index);
	
	//MediaElement
//	this.mediaElement = this.obj.FindName('media' + this.index);
	this.addEvent(this.mediaElement,'CurrentStateChanged',Silverlight.createDelegate(this,this.onMediaStateChange));
	this.addEvent(this.mediaElement,'MediaEnded',Silverlight.createDelegate(this,this.onMediaEnded));
	
}
mediaObject.prototype.get = function(name){
	return this.obj.FindName(name);
}
mediaObject.prototype.addEvent = function (target,event,handler){
	target.addEventListener(event,handler);
}

mediaObject.prototype.play = function(sender,eventArgs){
	this.mediaElement.play();
	this.mediaElement.volume = 0.8;
	//alert(this.mediaElement.volume);
	var stb = this.obj.FindName('storyboard');
	stb.stop();
	//this.setEnlargeMovie();
}
mediaObject.prototype.stop = function(sender,eventArgs){
	this.mediaElement.stop();
	var stb = this.obj.FindName('storyboard');
	stb.begin();
}
mediaObject.prototype.forward = function(sender,eventArgs){
	alert(sender.name);
}
mediaObject.prototype.back = function(sender,eventArgs){
	alert(sender.name);
}
mediaObject.prototype.setSource = function(URL){
	this.mediaElement.source = URL;
}
/*
mediaObject.prototype.setEnlargeMovie = function(){
	this.storyboard = new Storyboard(this.obj,'mediaStoryboard');
	this.obj.Resources.Add(this.storyboard);
	this.addEvent(this.storyboard,'Completed',Silverlight.createDelegate(this,this.onMediaStoryComplete));
	this.storyboard.begin();
}
mediaObject.prototype.enlargeMovie = function(){
	this.obj['Canvas.Left'] = 10;
	this.obj['Canvas.Top'] = 10;
	//this.obj.RenderTransform.ScaleX += this.scaleX;
	//this.obj.RenderTransform.ScaleY += this.scaleY;
}
mediaObject.prototype.onMediaStoryComplete = function(sender,eventArgs){
	this.enlargeMovie();
	this.storyboard.begin();
}
*/
mediaObject.prototype.onMediaStateChange = function(sender,eventArgs){
}
mediaObject.prototype.onMediaEnded = function(sender, eventArgs){
	
	sender.stop();
	sender.play();
	sender.volume = 0;
	
	var stb = this.obj.FindName('storyboard');
	stb.begin();
}
function debug (data){
	var errorDiv = document.getElementById("errorLocation");
	errorDiv.innerHTML += data;
	errorDiv.innerHTML += '<br />';
}
