ArrayImageEditor = new Class({
	Extends: ImageEditor,
	
	Implements: Options,
	
	options:{
		'content_part_id':0,
		'image_default':false,
		'order':0,
		'description':'hello'
	},
	
	initialize: function(stack,options){
		
		//data members
		this.setOptions(options);
		this.parent(stack,options);
		this.order = this.options.order
		//generate HTML
		
		this.br = new Element('br',{'class':'clear'});
		
		//set properties
		if(this.options.image_default){
			this.image_default_input.checked = true;
			this.image_default_input.defaultChecked = true;
			this.published = true;
			this.image_default_value = true;
		} else {
			this.image_default_value = false;
		}
	}
});


ArrayImageBox = new Class({
	Extends: Box,
	
	Implements: Options,
	
	options:{
		'id':0,
		'image_id': 0,
		'image_name':'obray_placeHolder',
		'image_ext': '.jpg',
		'description':'Place Holder',
		'window_height': 461,
		'window_width': 392,
		'window_max_width': 392,
		'window_max_height': 461,
		'zoom_level': 300,
		'resizable': false,
		'offset_x': 0,
		'offset_y': 0,
		'onSave':this.onSave,
		'src':'obray/images/obray_placeHolder.jpg',
		'link':true,
		'link_follow':false,
		'order':0,
		'description_long':''
	},
	
	initialize: function(options){
		
		//data emembers
		this.setOptions(options);
		this.parent(options);
		this.content_part_id = this.options.id;
		this.order = this.options.order;
		if(this.options.link == ''){this.options.link = ' ';}
		alert(this.options.link);
		//generate HTML
		this.product_image_container = new Element('div',{'class':'product_image_container'});
		this.product_image_editor = new ArrayImageEditor(this.stack,{
			'content_part_id': this.options.id,
			'image_id': this.options.image_id,
			'image_name':this.options.image_name,
			'image_ext': this.options.image_ext,
			'description':this.options.description,
			'description_long':this.options.description_long,
			'window_height': this.options.window_height,
			'window_width': this.options.window_width,
			'window_max_width': this.options.window_max_width,
			'window_max_height': this.options.window_max_height,
			'zoom_level': this.options.zoom_level,
			'resizable': this.options.resizable,
			'offset_x': this.options.offset_x,
			'offset_y': this.options.offset_y,
			'onSave': this.onSave,
			'src':this.options.src,
			'link':this.options.link,
			'link_follow':this.options.link_follow,
			'order':this.order,
			'description_long':this.options.description_long
		});
		
		//construct HTML
		this.stack.chain(function(){
			this.product_image_editor.get().inject(this.product_image_container);
			this.product_image_container.inject(this.box_content);
		}.bind(this));
		this.stack.callChain();
	},
	
	onSave: function(response){
		eval(response);
		this.linkProductAndImage = new Request({'url':'index.cfm?action=pages.cp&component=large_button_array&do=linkContentPartImage&image_id='+image_id + '&content_part_id='+this.content_part_id + '&image_order='+this.order,'onComplete':function(){
			var location = window.location.href.replace(window.location.hash,'');
			var location = location.replace('#','');
			window.location = location;
		}.bind(this)}).send();
	}
	
});


ArrayVideoBox = new Class({
	Extends: VideoBox,
	Implements: Options,
	
	options:{
		'content_part_id':0,
		'media_id':0
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.parent(options);
		
		this.stack.chain(function(){
			this.video_category_container.destroy();
			this.video_tag_container.destroy();
			this.video_assigned_container.destroy();
			
			this.video_image_editor.editor_save_btn.removeEvent('click');
			this.video_image_editor.editor_save_btn.addEvent('click',function(e){
			if(this.video_image_editor.editor_description_textarea.getProperty('value') == '' || this.video_image_editor.editor_long_textarea.getProperty('value') == ''){
				var alertBox = new AlertBox({'message':'Please enter and description and long description before uploading a video.','width':300});
				alertBox.open('elastic');
			} else {
				if(this.video_image_editor.options.image_id == 0){
					var alertBox = new AlertBox({'message':'Please upload an image to represent your video first.','width':300});
					alertBox.open('elastic');
				} else {
					if(this.video_embed_input.getProperty('value') == '' && this.video_upload_input.getProperty('value') == ''){
						var alertBox = new AlertBox({'message':'Please enter the URL of the YouTube video you would like to embed or browse for you video file to upload','width':300});
						alertBox.open('elastic');
					} else {
						if(this.video_embed_input.getProperty('value') == ''){
							this.video_image_id.setProperty('value',this.video_image_editor.options.image_id);
							this.form_submit = true;
							this.video_upload_form.submit();
							var width = this.box_m.getCoordinates().width-5;
							var height = this.box_m.getCoordinates().height-5;
							this.box_m.setStyles({'height':height+5,'width':width+5});
							this.loader = new Loader(this.box_m,{'height':height,'width':width,'text':'Uploading Video, Please Wait','border':true});
							this.loader.get().setStyles({'position':'absolute','background-color':'white','left':'15px','top':'15px'});
							this.loader.get().inject(this.box_m);
						}else{
							this.video_image_id.setProperty('value',this.video_image_editor.options.image_id);
							this.video_image_editor.saveImage();	
						}
					}
				}
			}
			e.stopPropagation();
			}.bind(this));
		}.bind(this));
		this.stack.callChain();
	},
	
	onSave: function(response){
		eval(response);
		if(this.options.media_id == 0){
			var data = '&image_id=' + image_id
				  +'&user_id=' + this.options.user_id
				  +'&description=' + this.options.description
				  +'&description_long='+ this.options.description_long
				  +'&embed='+this.options.embed
				  +'&content_part_id='+this.options.content_part_id;
			var embedRequest = new Request({'data':data,'url':'index.cfm?action=videos.embedContentVideo','onComplete':function(response){
				var location = window.location.href.replace(window.location.hash,'');
			var location = location.replace('#','');
			window.location = location;
			}.bind(this)}).send();
		} else {
			var data = '&image_id=' + image_id
				  +'&media_id=' + this.options.media_id
				  +'&user_id=' + this.options.user_id
				  +'&description=' + this.options.description
				  +'&description_long='+ this.options.description_long
				  +'&embed='+this.options.embed
				  +'&content_part_id='+this.options.content_part_id;;
			var embedRequest = new Request({'data':data,'url':'index.cfm?action=videos.updateContentVideo','onComplete':function(response){
				var location = window.location.href.replace(window.location.hash,'');
				var location = location.replace('#','');
				window.location = location;
			}.bind(this)}).send();
		}
	}
});