/*
 	Lukasz Podkalicki
	menu
*/

var menu = {
	
	// menu vars
	ID					: 'menu_2dh_sub',
	CONTAINER_PREFIX 	: 'container_submenu_', //id_str
	PREFIX				: 'menu_', 				//id_str
	PID 				: -1,
	LAST_PID			: -1,
	PARSED_PID			: -1,
	
	// pokazuje menu wraz z podmenu
	show : function(pid) {
		try {
			if(
				(mobj = document.getElementById(this.PREFIX + pid)) 			&&
				(cobj = document.getElementById(this.CONTAINER_PREFIX + pid)) 	&&
				true
				) {
				mobj.className="selected";	
				cobj.style.display = 'block';
			}
		}
		catch(e) {
			
		}
	},
	
	// ukrywa menu wraz z podmenu
	hide : function(pid) {
		try {
			if(
				(mobj = document.getElementById(this.PREFIX + pid)) 			&&
				(cobj = document.getElementById(this.CONTAINER_PREFIX + pid))   &&
				true
				) {
				mobj.className="deselected";
				cobj.style.display = 'none';
			}
		}
		catch(e) {
			
		}
	},
	
	// parser pid'a
	parse_pid : function(pid) {
		var m = sm = -1;
        
		if((pid.length>0))  {
			ppid = pid.split('_');
            if(ppid.length >= 2) {
                m = ppid[0] + '_' + ppid[1];
                if(ppid.length == 3) {
                    sm = m + '_' + ppid[2];
                }
            }
        }
		tmpTab = new Array(m, sm);
		return tmpTab;
	},
	
	// glowna funkcja wyzwalajaca :) 
	set : function(pid) {
		if(this.PID == pid) {
			return false;
		}
		else {
			this.LAST_PID = this.PID
			this.PID = pid;
            m = menu.parse_pid(this.LAST_PID);
			menu.hide(m[0]);
            m2 = menu.parse_pid(this.PID);
			menu.show(m2[0]);
            menu.submenu.show(this.submenu.PID);
			return true;
		}
	},
	
	// funkcja inicjujaca menu
	init : function(){
        m = this.parse_pid(menu.PID);
		this.show(m[0]);
        this.submenu.PID = m[1];

        this.submenu.show(this.submenu.PID);
	},
	
	// submenu 
	submenu : {
		ID					: 'menu_2dh_sub',	
		PREFIX      		: 'a_submenuitem_', 		//id_str
		PID					: -1,
		LAST_PID			: -1,
		
		// pokazuje podmenu
		show : function(pid) {
            try {
                if(
                    (mobj = document.getElementById(this.PREFIX + pid))             &&
                    true
                    ) {
                    mobj.style.color="#c0e3ff";
                }
            }
            catch(e) {
                
            }
		},
		
		hide : function(pid) {
		    try {
                if(
                    (mobj = document.getElementById(this.PREFIX + pid))             &&
                    true
                    ) {
                    mobj.style.backgroundColor="";
                }
            }
            catch(e) {

            }
		},
		
		set : function(pid) {
			
		}
	}
}

