//Element.addMethods('div', menuMethods);
//Element.addMethods('a', buttonMethods);

var uhknaNavbar = {
	version : '0.0.1',
	requiredPrototype : '1.6.1',
	mainContextMenuId : 'main_menu',
    menuWidth: '170px',
    buttonHeight: '40px',
    currentPageId: null,
	url : 'index.php',
	menuImgNdx : 0,
	enabledOpacity : '1',
	overOpacity : '0.80',
	disabledOpacity : '0.60',
	menuImgs : [
    ,'./images/menu_image1.jpg'
    ,'./images/menu_image11.png'
    ,'./images/menu_image2.jpg'
    ,'./images/menu_image11.png'
    ,'./images/menu_image3.jpg'
    ,'./images/menu_image11.png'
    ,'./images/menu_image4.jpg'
    ,'./images/menu_image11.png'
    ,'./images/menu_image5.jpg'
    ,'./images/menu_image11.png'
    ,'./images/menu_image6.jpg'
    ,'./images/menu_image11.png'
    ,'./images/menu_image7.jpg'
    ,'./images/menu_image11.png'
    ,'./images/menu_image8.jpg'
    ,'./images/menu_image11.png'
    ,'./images/menu_image9.jpg'
    ,'./images/menu_image11.png'
    ,'./images/menu_image10.jpg'
    ],

	load : function(element) {
     this.init();

     if ($(this.mainContextMenuId)) {
     //  $(this.mainContextMenuId).observe();
     //  $(this.mainContextMenuId).firstDescendant().disable();
     };

     new PeriodicalExecuter( function( pe ) {
       if ( ++uhknaNavbar.menuImgNdx == uhknaNavbar.menuImgs.size() ) {
         uhknaNavbar.menuImgNdx = 0;
       }
       $("main_menu_image").src = uhknaNavbar.menuImgs[ uhknaNavbar.menuImgNdx ];
     }, 10);
	},

	init : function() {
		var agt = navigator.userAgent.toLowerCase();
		this.is_op = (agt.indexOf("opera") != -1);
		this.is_ie = (agt.indexOf("msie") != -1) && document.all && !this.is_op;
		this.is_ie6 = (agt.indexOf("msie 6") != -1) && document.all
				&& !this.is_op;
		this.is_ie7 = (agt.indexOf("msie 7") != -1) && document.all
				&& !this.is_op;
		this.checkRequiredPrototype(); // http://script.aculo.us/
    document.observe("uhkna:updateContent", function(event) {
        var msg="unkna:updateContent event fired.\n Memo is: " + event.memo.value;
        //alert("Target URL: " + msg );
        var url="index.php?page=" + event.memo.value;
        //alert("Target URL: " + url );
        parent.content.location = url;
    });

		//this.currentContext = new Context();
	},

	/* http://script.aculo.us/ */
	checkRequiredPrototype : function() {
		 if ((typeof Prototype == 'undefined')
         || (typeof Element == 'undefined')
         || (typeof Element.Methods == 'undefined')
         || (this.convertVersionString(Prototype.Version) < this.convertVersionString(this.requiredPrototype)))
       throw ("uhkna requires the Prototype JavaScript framework >= " + this.requiredPrototype);
	},

	/* http://script.aculo.us/ */
	convertVersionString : function(versionString) {
     var r = versionString.split('.');
     return parseInt(r[0]) * 100000 + parseInt(r[1]) * 1000 + parseInt(r[2]);
	},

	clicked : function(element) {
		element = $(element);
		var params = element.value.toQueryParams();
		this.currentPageId = params['pageId'];
		this.clearMenu( $('mainContextMenu') ) ;
		return element;
	},
	clearMenu : function(element) {;
    element = $(element);
		element.childElements().each(function(button) {
			var params = button.value.toQueryParams();
			// alert("Config: " + params['pageId'] + "/" + this.currentPageId);
				if (params['pageId'] == this.currentPageId) {
					this.disableButton(button);
				} else {
					this.enableButton(button);
				}
			}, this);
		return element;
	},
	myAlert : function() {
		alert("Current Context: " + this.currentContext.id + "\nCurrent Page: "
				+ this.currentContext.page);
	}
};

Event.observe(window, 'load', function(event) {
	uhknaNavbar.load(Event.element(event));
});

