var Project = function(){}

Project.prototype = {
	datas : null,
	dataCount : null,
	current_content : 0,
	container : null,
	previousBtn : null,
	nextBtn : null,
	
	addDatas : function(datas){
		this.datas = datas;
		this.dataCount = this.datas.datas.length-1;
	},

	next : function(){
		this.previousBtn.show();
		if(this.current_content < this.dataCount ){
			this.current_content ++;
			this.addContent();
		}
		else if(this.current_content == this.dataCount){
			this.nextBtn.hide();
			this.current_content ++;
			this.addDescription();
		}
		this.pagination();
	},
	
	previous : function(){
		this.nextBtn.show();
		if(this.current_content > 0){
			this.current_content --;
			this.addContent();
			if(this.current_content == 0){
				this.previousBtn.hide();
			}
		}
		this.pagination();
	},

	addWorkBox : function(){
		var me = this;
		this.container = $('#worklightbox_content');
		this.addContent();
		this.nextBtn = $('#next')
		this.nextBtn.click(function(e){
			e.preventDefault();
			me.next();
		});
		this.previousBtn = $('#previous')
		this.previousBtn.click(function(e){
			e.preventDefault();
			me.previous();
		});
		this.previousBtn.hide();
		this.pagination();
	},
	
	pagination : function(){
		$('#pagecurrent').html(this.current_content+1);
		$('#pagetotal').html(this.dataCount+2);
	},

	addContent : function(){
		this.container.empty();
		var data = this.datas.datas[this.current_content],
			type = data.type,
			value = data.value;

		if(type == 'video'){
			alert(value.length);
	
			this.addVideo(value);
		}
		else if(type == 'image'){
			this.addImage(value);
		}
	},

	addDescription : function(){
		this.container.empty();
		
		this.container.append(this.datas.post_content);
	},
	
	addVideo : function(video){
		this.container.fadeOut('slow', function(){
			this.container.append(video);
		}
		);
		
	},

	addImage : function(image){
		var me = this;
			link = $('<a href="#"></a>'),
			img = $('<img src="'+image+'">');
		link.click(function(e){
			e.preventDefault();
			me.next();
		});
		 
		this.container.empty();
		this.container.append(link);
		link.append(img);
		this.container.hide();
		this.container.fadeIn('slow');
		img.load(function(){
			this.container.fadeIn('slow');
		});
		
		
	}
}
