/* ------------------------------------------------------------------------
ImageBox
------------------------------------------------------------------------- */
var ImageBox = Class.create( {
	_images:[],
	id:'',
	_pos:0,
	_length:0,
	_imgwrap:null,
	_img:null,
	_img_attrs:{},
	_noimage:false,
	initialize : function(config) {
		if(config.images.length==0){
			config.images=config.noimage;
			this._noimage=true;
		}
		this._images=config.images;
		this._length=this._images.length;
		this.id=config.id;

		owner=this;
		var btn_back=$('#'+this.id+'_btn_back');
		var btn_forward=$('#'+this.id+'_btn_forward');
		var info=$('#'+this.id+'_info');
		var text=$('#'+this.id+'_text');
		if(this._length==0 | this._noimage){
			btn_back.remove();
			btn_forward.remove();
			info.remove();
			text.remove();
		}else{
			btn_back.bind("click", function(){
				owner.back();
			 }); 
			btn_forward.bind("click", function(){
				owner.forward();
			 }); 
		}
		this._imgwrap=$('#'+this.id+'_wrap');
		this._imgwrap.bind("click", function(){
			window.open (owner._img_attrs.src,"Image","menubar=0,scrollbars=1,status=0,location=0,resizable=1,width="+owner._img_attrs.width+",height="+owner._img_attrs.height);
		 }); 
		
		this.render();
		
	},
	render : function() {
		if(this._length==0)return;
		this._img=$('<img />').appendTo(this._imgwrap.html('')).attr('src',this._images[this._pos]['src']);
		$('#'+this.id+'_text').html(this._images[this._pos]['text']);
		$('#'+this.id+'_info').html(this._pos+1+"/"+this._length);
		owner._img_attrs.src=this._images[this._pos]['src'];
		owner._img_attrs.width=this.getSize(this._img.css('width'));
		owner._img_attrs.height=this.getSize(this._img.css('height'));
		if(owner._img_attrs.width<=600)owner._img_attrs.width=600;
		if(owner._img_attrs.height<=300)owner._img_attrs.height=300;
		this.setBtn();
	},
	getSize : function(pxsize) {
		if(pxsize=='' | pxsize==undefined)return 0;
		return parseInt(pxsize.substring(0,pxsize.length-2));
	},
	back : function() {
		this._pos--;
		if(this._pos<=-1){
			this._pos=0;
		}
		this.render();
	},
	forward :function(){
		this._pos++;
		if(this._pos>=this._length){
			this._pos=this._length-1;
		}
		this.render();
	},
	setBtn:function(){
		var btn_back=$('#'+this.id+'_btn_back');
		var btn_forward=$('#'+this.id+'_btn_forward');
		btn_back.attr('class','imagebox_btn_back');
		btn_forward.attr('class','imagebox_btn_forward');
		if(this._pos==0){
			btn_back.attr('class','imagebox_btn_back_disabled');
		}
		if(this._pos==this._length-1){
			btn_forward.attr('class','imagebox_btn_forward_disabled');
		}
	}
	
});
