
//======================================================================================================================
var MENUTAB = function( tabObj ){
	
	var that = this;
	this.type = tabObj.type;
	this.id = tabObj.id;
	var that = this;
	var tabWidth  = tabObj.tabSize.width;
	var tabHeight = tabObj.tabSize.height;
	var menuWidth = tabObj.tabSize.totalWidth;
	var menuHeight = tabObj.tabSize.totalHeight;
	
	$("#"+tabObj.id).css(
			{	'width': menuWidth,
				'height': menuHeight
			}
		);

	$("#"+tabObj.id+" li").css(
			{	'display': 'block',
				'text-indent': '-9999px',
				'float': 'left',
				'width': tabWidth,
				'height': tabHeight
			}
		);
	
	$("#"+tabObj.id+" a").css(
		{	'display': 'block',
			'text-decolation': 'none',
			'background': 'url('+tabObj.imageMap+') no-repeat',
			'width': tabWidth,
			'height': tabHeight
		}
	);
	$("#"+tabObj.id+" li a").each(
		function(){
			var id = $(this).attr('id');

			if( that.type === 'column' ){
				var item = new TABITEM( id );
			}
			else if( that.type === 'row'){
				var item = new TABITEMROW( id );
			}
//			item.setReference( tabObj.referenceSet[id] );
			item.setStatus( tabObj.itemOffset[id], tabObj.stateOffset );
			item.setHandler();
		}
	);
	
	if( tabObj.defaultTab != ""){
		var id = tabObj.defaultTab;
		if( this.type === 'column' ){
			var item = new TABITEM( id );
		}
		else if( this.type === 'row'){
			var item = new TABITEMROW( id );
		}
		item.setStatus( tabObj.itemOffset[id], tabObj.stateOffset );
		item.fixMode();
	};
	
	this.setBackground = function(bkgObj){
		var node = $("#"+that.id);
		node.css(
			{
				'background': bkgObj.image,
				'width':bkgObj.width,
				'height': bkgObj.height,
				'padding-top': bkgObj.top,
				'padding-left': bkgObj.left,
				'padding-right': bkgObj.right,
				'padding-bottom': bkgObj.bottom,
				'background-position': bkgObj.position
			}
		);
	};
	
};

//======================================================================================================================
var TABITEM = function( ID ){
	
	this.id = ID;
	
	this.obj = $("#"+this.id);
	var that = this; 
	
	this.setStatus = function(OFFSET_UNIT, STATUS_OFFSET){
		that.position = OFFSET_UNIT;
		that.statusOffset = STATUS_OFFSET;
		that.offstate = that.position+" "+ that.statusOffset.off;
		that.onstate = that.position+" "+ that.statusOffset.on;
		that.selectstate = that.position+" "+ that.statusOffset.select;
		that.setStatusOut();
	};
	
	
	
	this.setReference = function(URL){
		that.reference = URL;
		this.obj.attr("href", URL);
	};
	
	this.fixMode = function(){
		
		that.obj.css("background-position", that.selectstate );
		that.obj.unbind( 'hover');
		that.obj.unbind( 'mousedown');
		that.obj.unbind( 'mouseover');
		that.obj.unbind( 'mouseout');
		that.obj.unbind( 'blur' );
		that.obj.unbind( 'click' );
	};
	
	this.setHandler = function(){
		that.obj.hover(
			function(){
				that.setStatusIn();
			},
			function(){
				that.setStatusOut();
			}
		);
		that.obj.mousedown(
			function(){
				that.setStatusSelect();
			}
		);
		that.obj.blur(
			function(){
				that.setStatusOut();
			}
		);
	};
	
	this.setStatusOut = function(){
		that.obj.css("background-position", that.offstate );
	};
	
	this.setStatusIn = function(){
		that.obj.css("background-position", that.onstate );
	};
	
	this.setStatusSelect = function(){
		that.obj.css("background-position", that.selectstate );
	};
	
};

//=======================================================================================
var TABITEMROW = function(OBJ){
	TABITEM.apply(this,[OBJ]);
	var that = this;
	
	this.setStatus = function(OFFSET_UNIT, STATUS_OFFSET){
		that.position = OFFSET_UNIT;
		that.statusOffset = STATUS_OFFSET;
		that.offstate = that.statusOffset.off +" "+ that.position;
		that.onstate = that.statusOffset.on +" "+ that.position;
		that.selectstate = that.statusOffset.select+" "+ that.position;
		that.setStatusOut();
	};

};

TABITEMROW.prototype = TABITEM;
	


