/* VIDEO CONTAINER model
================================================== */
function VideoContainerModel(){
    
    this.vidWidth;
    this.vidHeight;
    this.videoID;
    this.iFrameID=0;
    
    var self = this;
    
    //set video ID    
    this.setVideoID = function(id){
        this.videoID = id;
        this.onChange('videoID');
    } 
    //get video ID    
    this.getVideoID = function(){
        return this.videoID;        
    } 
    
    //get iframeID   
    this.getIFrameID = function(){
        return this.iFrameID;        
    }          
    
    //set video size
    this.setSize = function(val){
        this.vidWidth = val.vidWidth;
        this.vidHeight = val.vidHeight;
        this.onChange();
    }
    
    //set video width
    this.setVideoWidth = function(val){
        this.vidWidth = val;
        this.onChange();
    }
    
    //set video height
    this.setVideoHeight = function(val){
        this.vidHeight = val;
        this.onChange();
    }
    
    //get video width
    this.getVideoWidth = function(){
        return this.vidWidth;
    } 
    
    //get video height
    this.getVideoHeight = function(){
        return this.vidHeight;
    }            
        
                    
    //on video id change
    this.onVideoIDChange=function(event){
        self.vidWidth = event.data.w;
        self.vidHeight = event.data.h;
        self.iFrameID = event.data.iFrameID;     
        self.setVideoID(event.data.videoID);
    }
    EventBus.addEventListener(Event.NEW_VIDEO_ID, this.onVideoIDChange);
    
    //on video width change
    this.onVideoWidthChange=function(event){
        self.setVideoWidth(event.data);
    }
    //on video height change
    this.onVideoHeightChange=function(event){
        self.setVideoHeight(event.data);
    } 
    //on video size change
    this.onVideoSizeChange=function(event){
        self.setVideoWidth(event.data.w);
        self.setVideoHeight(event.data.h);
    }       
    EventBus.addEventListener(Event.NEW_VIDEO_WIDTH, this.onVideoWidthChange);
    EventBus.addEventListener(Event.NEW_VIDEO_HEIGHT, this.onVideoHeightChange);
    EventBus.addEventListener(Event.NEW_VIDEO_SIZE, this.onVideoSizeChange); 
    
    
    
    
                
}
VideoContainerModel.prototype = new GenericModel();







/* VIDEO ASSETS model
================================================== */
function VideoAssetsModel(){
    var _this = this;
    
    this.init = function(){
        this.data = new Array();
    }    
    this.data;
    
    //set data one time on load
    this.setData = function(val){
        for(var i=0;i<val.length;i++){
            var obj = val[i];
            obj.isSelected = false;
            switch(obj.type)
            {
                case GenericAssetModel.IMAGE:
                  //image
                  obj = jQuery.extend(new ImageAssetModel(), obj);                                    
                  _this.add(obj);
                  break;
                case GenericAssetModel.TEXT:
                  //text
                  obj = jQuery.extend(new TextAssetModel(), obj);                  
                  _this.add(obj);                  
                  break;
                case GenericAssetModel.BUTTON:
                  //button
                  obj = jQuery.extend(new ButtonAssetModel(), obj);                  
                  _this.add(obj);                  
                  break;
                case GenericAssetModel.RECTANGLE:
                  //rectangle
                  obj = jQuery.extend(new RectangleAssetModel(), obj);                  
                  _this.add(obj);                  
                  break;   
				case GenericAssetModel.FORM:
                  //form
                  obj = jQuery.extend(new FormAssetModel(), obj);                  
                  _this.add(obj);                  
                  break;   
                case GenericAssetModel.CODE:
                  //code
                  obj = jQuery.extend(new CodeAssetModel(), obj);                  
                  _this.add(obj);                  
                  break;
              }             
        }
        //this.data = val;
    }
    this.getData = function(){
        return this.data;
    }    
    
    //add object
    this.add = function(genericAsset){        
        _this.data.push(genericAsset);        
        main_json_data.setAssets(_this.data);
        EventBus.dispatchEvent(new Event(Event.ASSETS_COLLECTION_CHANGE, this.data));
        _this.broadcastAddedAsset(genericAsset);      
    }
    //remove object
    this.removeObject = function(event){
        for(var i=0;i<_this.data.length;i++){
            if(_.isEqual(_this.data[i], event.data)){
                _this.data.splice(i,1);
                var e = new Object();
                e.indx = i;                
                EventBus.dispatchEvent(new Event(Event.REMOVE_VIEW, e));                
                break;
            }
        }        
    }
    EventBus.addEventListener(Event.REMOVE, this.removeObject);
    
    //asset has changed
    this.onAssetChange = function(event){
        EventBus.dispatchEvent(new Event(Event.ASSETS_COLLECTION_CHANGE, _this.data));
    }
    EventBus.addEventListener(Event.ASSET_CHANGE, this.onAssetChange);
    
    //select asset
    this.onAssetSelect = function(event){       
        for(var i=0;i<_this.data.length;i++){
            _this.data[i].setSelected(false);
            if(_.isEqual(_this.data[i], event.data)){
                _this.data[i].setSelected(true);
            }
        }
    }
    EventBus.addEventListener(Event.SELECT_ASSET, this.onAssetSelect);
    
    
    //broadcast asset added
    this.broadcastAddedAsset = function(genericAsset){                
        EventBus.dispatchEvent(new Event(Event.ASSET_ADDED, genericAsset));
    }
        
}
VideoAssetsModel.prototype = new GenericModel();

