/**************************************************************
	List Class
**************************************************************/
function List(header,el,width,requestURL){
	
	this.header = header;
	this.el = el;
	this.addRows = [];
	this.editRows = [];
	this.inputs = [];
	this.width = width;
	this.addURL = requestURL;
	this.editURL = '';
	this.deleteURL = '';
	this.detailsURL = '';
	//create HTML
	
	this.list = new Element('div',{'class':'list','id':header});
	this.list_header = new Element('div',{'class':'list_header'});
	this.list_add = new AddRow('dark',this.width-200,requestURL);
	this.list_headerH1 = new Element('h1');
	this.list_headerH1.set('html',this.header);
	this.list_rows = new Element('div',{'class':'list'});
	this.list_break = new Element('br',{'class':'clear'});
	//Construct HTML
	this.list_header.adopt(this.list_headerH1);
	this.list.adopt(this.list_header);
	this.list.adopt(this.list_rows);
	this.el.adopt(this.list);
	//Set Styles
	this.list_add.getRow().setStyle('float','right');
	
}

List.prototype.getList = function(){
		return this.list;
}

List.prototype.setAddURL = function(url){
	this.addURL = url;
	this.list_add.addURL(this.addURL,function(inputs){
		if($chk(inputs[0])){
			if(inputs[0].name == 'question_id'){
				
				if(inputs[3].question_type == "True_or_False"){
					this.addRow('Q'+inputs[0].value,'dark','index.cfm?action=surveys.showTrueOrFalse');	
				} else {
					this.addRow('Q'+inputs[0].value,'dark',inputs,this.detailsURL);	
				}
			} else {
				this.addRow(inputs[0].value,'dark',inputs,this.detailsURL);
			}
		}
	}.bind(this));
}
List.prototype.setEditURL = function(url){this.editURL = url;}
List.prototype.setDeleteURL = function(url){this.deleteURL = url;}
List.prototype.setDetailsURL = function(url){this.detailsURL = url;}

List.prototype.initilize = function(){
	for(var i=0;i<this.inputs.length;++i){
		this.list_add.addInput(this.inputs[i]);
	}
	this.list_add.insertInside(this.list_header);
	this.list_add.initilize();
	this.list_header.adopt(this.list_break.clone());
}
	
List.prototype.addInput = function(input){
	this.inputs[this.inputs.length] = input;
}

List.prototype.disableHeader = function(){
	this.list_header.destroy();
}

List.prototype.disableAdd = function(){
	var newRow = this.list_add.getRow();
	newRow.destroy();
}

List.prototype.addRow = function(id,color,inputs,detailsURL){
	var rowN = this.editRows.length;
	//alert(this.header);
	this.editRows[rowN] = new EditRow(id,color,this.width);
	if(this.header != "Categories" && this.header != "Sub-Categories")
		this.editRows[rowN].disableRearrangeBtn();
	this.editRows[rowN].setDeleteURL(this.deleteURL,function(){
		this.editRows[rowN].deleteRow();
	}.bind(this));
	
	this.editRows[rowN].setDetailsURL(detailsURL,function(){
		var height = this.editRows[rowN].row_details.getScrollSize().y;
		var openDetails = new Fx.Tween(this.editRows[rowN].row_details,{duration: 500, transition: Fx.Transitions.Quart.easeOut, wait: false})
		if(this.editRows[rowN].row_details.getSize().y == 0){
			openDetails.start('height',height);
			this.editRows[rowN].row_openBtn.removeClass('row_openBtn');
			this.editRows[rowN].row_openBtn.addClass('row_openBtn_over');
			openDetails.addEvent('onComplete',function(){
				this.editRows[rowN].row_details.setStyle('height','auto');
			}.bind(this));
		} else {
			openDetails.start('height','0px');
			this.editRows[rowN].row_openBtn.removeClass('row_openBtn_over');
			this.editRows[rowN].row_openBtn.addClass('row_openBtn');
			this.editRows[rowN].row_details.set('html','');
		}
		
	}.bind(this));
	this.editRows[rowN].setEditURL(this.editURL,function(inputs){
		this.editRows[rowN].toggleEdit();
		var valueCount = 0;
		for(var i=0;i<inputs.length;++i){
			if($chk(inputs[i])){
				if(inputs[i].value == "Disabled" || inputs[i].value == "Enabled"){					//hacked fix for enable/disable update
					if($chk(this.editRows[rowN].inputValues[valueCount+1])){
						this.editRows[rowN].inputValues[valueCount+1].set('html',inputs[i].value);
					}
				}
				else{
					this.editRows[rowN].inputValues[valueCount].set('html',inputs[i].value);
					++valueCount;
				}
			}
		}
	}.bind(this));
	for(var i=0;i<inputs.length;++i){
		this.editRows[rowN].addInput(inputs[i]);	
	}
	this.editRows[rowN].insertInside(this.list_rows);
	//this.list_rows.adopt(this.list_break.clone());
	return this.editRows[rowN];
	
}


/**************************************************************
	Movie Detail Class
**************************************************************/
function MovieDetail(id,el,movie_file,movie_xml,movie_thumb,movie_description,movie_published){
	this.id = id;
	//Video
	this.movieFile = new EditRow(id,'dark',860,'index.cfm?action=movies.uploadMovie');
	this.movieFile.setEditURL('index.cfm?action=movies.uploadMovie',function(){
		this.movieFile.uploadBox.close();
		this.movieFile.toggleEdit();
	}.bind(this));
	var movieId_input = new Input('hidden','movie_id',this.id);
	var movieFile_input = new Input('file','movie_file','<strong>Movie File:</strong> ' + movie_file,500);
	this.movieFile.addInput(movieId_input);
	this.movieFile.addInput(movieFile_input);
	this.movieFile.disableDeleteBtn();
	this.movieFile.disableOpenBtn();
	this.movieFile.insertInside(el);
	//XML
	this.movieXML = new EditRow(id,'dark',860,'index.cfm?action=movies.uploadXML');
	this.movieXML.setEditURL('index.cfm?action=movies.uploadXML',function(){
		this.movieXML.uploadBox.close();
		this.movieXML.toggleEdit();
	}.bind(this));
	var movieId_input = new Input('hidden','movie_id',this.id);
	var movieXML_input = new Input('file','movie_XML','<strong>Movie Assets XML:</strong> ' + movie_xml,500);
	this.movieXML.addInput(movieId_input);
	this.movieXML.addInput(movieXML_input);
	this.movieXML.disableDeleteBtn();
	this.movieXML.disableOpenBtn();
	this.movieXML.insertInside(el);
	//Thumbnail
	this.movieThumb = new EditRow(id,'dark',860,'index.cfm?action=movies.uploadThumb');
	this.movieThumb.setEditURL('index.cfm?action=movies.uploadThumb',function(){
		this.movieThumb.uploadBox.close();
		this.movieThumb.toggleEdit();
	}.bind(this));
	var movieId_input = new Input('hidden','movie_id',this.id);
	var movieThumb_input = new Input('file','movie_thumb','<strong>Movie Thumbnail:</strong> ' + movie_thumb,500);
	this.movieThumb.addInput(movieId_input);
	this.movieThumb.addInput(movieThumb_input);
	this.movieThumb.disableDeleteBtn();
	this.movieThumb.disableOpenBtn();
	this.movieThumb.insertInside(el);
	//Description
	this.movieDescription = new EditRow(id,'dark',860,'index.cfm?action=movies.updateDescription');
	this.movieDescription.setEditURL('index.cfm?action=movies.updateDescription',function(){
		this.movieDescription.toggleEdit();
	}.bind(this));
	var movieId_input = new Input('hidden','movie_id',this.id);
	var movieDescription_input = new Input('text','movie_description','<strong>Movie Description:</strong> ' + movie_description,500);
	this.movieDescription.addInput(movieId_input);
	this.movieDescription.addInput(movieDescription_input);
	this.movieDescription.disableDeleteBtn();
	this.movieDescription.disableOpenBtn();
	this.movieDescription.insertInside(el);
	//pulished
	this.moviePublished = new EditRow(id,'dark',860,'index.cfm?action=movies.updatePublished');
	this.moviePublished.setEditURL('index.cfm?action=movies.updatePublished',function(){
		this.moviePublished.toggleEdit();
	}.bind(this));
	var movieId_input = new Input('hidden','movie_id',this.id);
	if(movie_published == "Published"){
		var option = "checked";	
	}
	var moviePublished_input = new Input('checkbox','movie_published',movie_published,100,option);
	this.moviePublished.addInput(movieId_input);
	this.moviePublished.addInput(moviePublished_input);
	this.moviePublished.disableDeleteBtn();
	this.moviePublished.disableOpenBtn();
	this.moviePublished.insertInside(el);
	
	//Images List
	this.imagesList = new List('Asset Images',el,860,'index.cfm?action=movies.addAssetImage');
	this.imagesList.setAddURL('index.cfm?action=movies.addAssetImage');
	this.imagesList.setEditURL('index.cfm?action=movies.editAssetImage');
	this.imagesList.setDetailsURL('index.cfm?action=movies.assetImageDetail');
	this.imagesList.setDeleteURL('index.cfm?action=movies.deleteAssetImage');
	//create add inputs
	var imagesList_movieId = new Input('hidden','movie_id',this.id);
	var imageList_imageFile_input = new Input('file','assetImage_file','',400);
	
	this.imagesList.addInput(imagesList_movieId);
	this.imagesList.addInput(imageList_imageFile_input);
	
	this.imagesList.initilize();
	//Preview button
	this.moviePreview = new Row(this.id,'dark',860);
	this.moviePreviewBtn = new Element('input',{'type':'button','value':'Preview'});
	this.moviePreview.row_middle.adopt(this.moviePreviewBtn);
	this.moviePreview.getRow().setStyle('width',this.moviePreview.width);
	this.moviePreview.insertInside(el);
	
	this.moviePreviewBtn.addEvent('click',function(){
		this.box = new Box({'width':950},700,950);
		this.date = new Date();
		this.timestamp = this.date.getTime();
		this.box.open('index.cfm?action=movies.moviePreview&movie_id='+this.id,'fade');
	}.bind(this));
	
	//Quiz List
	this.quizList = new List('Quiz Questions',el,820,'index.cfm?action=surveys.addQuestion');
	this.quizList.setAddURL('index.cfm?action=surveys.addQuestion');
	this.quizList.setEditURL('index.cfm?action=surveys.editQuestion');
	this.quizList.setDetailsURL('index.cfm?action=surveys.showTrueOrFalse');
	this.quizList.setDeleteURL('index.cfm?action=surveys.deleteQuestion');
	//create add inputs
	var quizList_survey_id = new Input('hidden','movie_id',this.id);
	var quizList_question = new Input('text','question_text','',450);
	var options = [];
	options[0] = 'True_or_False';
	options[1] = 'Multiple_Choice';
	this.quizList_question_type = new Input('select','question_type','',100,options);
	this.quizList_question_type.getInput().addEvent('change',function(){
		var value = this.quizList_question_type.getInput().getProperty('value');
		if( value == 'True_or_False'){
			this.quizList.setDetailsURL('index.cfm?action=surveys.showTrueOrFalse');													 
		} else {
			this.quizList.setDetailsURL('index.cfm?action=surveys.showQuestions');													 
		}
	}.bind(this));
	
	this.quizList.addInput(quizList_survey_id);
	this.quizList.addInput(quizList_question);
	this.quizList.addInput(this.quizList_question_type);
	
	this.quizList.initilize();
}

MovieDetail.prototype.addAsset = function(inputs){
	var newRow = this.imagesList.addRow(inputs[0].value,'dark',inputs,'');
	newRow.disableEditBtn();
	newRow.disableOpenBtn();
}

MovieDetail.prototype.addQuestion = function(inputs,trueOrFalse){
	if(trueOrFalse == 'True_or_False'){
		var newRow = this.quizList.addRow('Q'+inputs[0].value,'dark',inputs,'index.cfm?action=surveys.showTrueOrFalse');
	} else {
		var newRow = this.quizList.addRow('Q'+inputs[0].value,'dark',inputs,'index.cfm?action=surveys.showQuestions');
	}
	return newRow;
}

MovieDetail.prototype.disableVideo = function(){
	this.movieFile.getRow().destroy();
}

MovieDetail.prototype.disableXML = function(){
	this.movieXML.getRow().destroy();
}

MovieDetail.prototype.disableAssets = function(){
	this.imagesList.getList().destroy();
}

MovieDetail.prototype.disablePreview = function(){
	this.moviePreview.getRow().destroy();
}

MovieDetail.prototype.disableAddQuestion = function(){
	this.quizList.disableAdd();
}

MovieDetail.prototype.disableThumbnail = function(){
	this.movieThumb.getRow().destroy();
}

MovieDetail.prototype.disableDescription = function(){
	this.movieDescription.getRow().destroy();
}

MovieDetail.prototype.disablePublished = function(){
	this.moviePublished.getRow().destroy();
}





























