
var FCclip = function(){
	var clip = arguments[0];
	for(i in clip) this[i] = clip[i];
};

FCclip.prototype = {
	getMediafiles: function(){
		var clip = (typeof(arguments[0])=='object')?arguments[0]:this;
		if(typeof(clip.mediafiles.mediafile)=='object'){
			var _mf = clip.mediafiles.mediafile;
			if(_mf.length>=0) return _mf;
			else return [_mf];
		} else return false;
	},
	getSource: function(){
		var clip = (typeof(arguments[0])=='object')?arguments[0]:this;
		var _mfs = clip.getMediafiles();
		for(var i=0;i<_mfs.length;i++){
			if(_mfs[i].sourcefile) return _mfs[i];
		}
		return false;
	},
	getFramesize: function(){
		var clip = (typeof(arguments[0])=='object')?arguments[0]:this;
		var _s = clip.getSource();
		return {width:_s.width,w:_s.width,height:_s.height,h:_s.height};
	},
	resizeToFit: function(w, h){
		var clip = (typeof(arguments[0])=='object')?arguments[0]:this;
		var _csize = clip.getFramesize();
		var _w, _h, _x, _y;
		if(_csize.w>w){
			_h=_csize.h/(_csize.w/w);
			_w=w;
		}
		if(_h>h){
			_w=_w/(_h/h);
			_h=h;
		}
		_x= Math.floor((w-_w)/2);
		_y = Math.floor((h-_h)/2);
		delete(w); delete(h);
		return {width:_w,w:_w,height:_h,h:_h,x:_x,left:_x,y:_y,top:_y};
	},
	
	
	/** test **/
	getTitle: function(){
		var clip = (typeof(arguments[0])=='object')?arguments[0]:this;
		return clip.metadata.title;
	}
};
