// JScript File
Element.extend({
    setStyle:function(property, value){
	    switch(property){
	    case 'opacity': return this.setOpacity(parseFloat(value));
	    case 'float': property = (window.ie) ? 'styleFloat' : 'cssFloat';
		    /*fix on ie Add by loa(locke_ad@yahoo.com.tw) 2007-11-05*/
	    case 'width':
	    case 'height':
		    if (window.ie) if (value.toInt()<1)value=1;break;
		    /*fix end*/
	    }
	    property = property.camelCase();
	    switch($type(value)){
		    case 'number': if (!['zIndex', 'zoom'].contains(property)) value += 'px'; break;
		    case 'array': value = 'rgb(' + value.join(',') + ')';
	    }
	    this.style[property] = value;
	    return this;
    }
});
window.addEvent('domready', function() { intd.init(); } );
var intd = {
	SubmenuEffects: Class.Empty,
	Submenus: Class.Empty,
	Menus: Class.Empty,
	AccordionMenuIndex: 0,
	init: function() {
	    // Set up left accordion menu and the mouseover style
	    new Accordion($$('div#stretch .stretcht'), $$('div#stretch .stretchd'),{show:this.AccordionMenuIndex});
	    $$('.stretcht').addEvent('mouseover', function () { this.setStyle('color','#fff'); } ).addEvent('mouseout', function () { this.setStyle('color',''); });
	    
	    // Find our top menus and submenus and set up the default effect
	    this.Submenus = $$('#mainlinks dd');
	    this.Menus = $$('#mainlinks dt');
	    var subtotalwidth = 0;
	    this.Menus.each(function (item,index) {
	        subtotalwidth += item.offsetWidth; } );
	    $('mainlinks').style.width = subtotalwidth + 'px';
	    this.SubmenuEffects = new Fx.Elements(this.Submenus,{'wait':false,'transition':Fx.Transitions.Back.easeOut});
	    
	    window.addEvent('resize',this.positionMenus.bind(this));
	    this.positionMenus();
	    
	    // Give a background color change to the menu items when we mouse over them
	    $$('#mainlinks li').addEvent(
			    'mouseover',
			    function() { this.setStyle('background-color','#007a5d'); }
		    ).addEvent(
			    'mouseout',
			    function() { this.setStyle('background-color',''); }
		    );
	},
	positionMenus: function() {
	    // Set up our submenus
	    var mp;
		for(i=this.Submenus.length;i>0;i--)
		{
		    // Find the parent menu location and line up the
		    // submenu and grab the original height of each submenu
		    // then hide the submenu so the animation has someplace to start
			mp = this.Menus[i-1].getCoordinates();
			this.Submenus[i-1].setStyle('width',120);
			this.Submenus[i-1].origheight=this.Submenus[i-1].scrollHeight;
			this.Submenus[i-1].setStyles({
				'top':(mp.top + mp.height),
				'left':(mp.left + (mp.width/2) - 60),
				'z-index':99999,
				'height':1,
				'opacity':0
				});
			
		}
	},
	showmenu: function(name) {
		var SubEffect = {};
		this.Submenus.each(
			function(elem,index){
				if(elem.id == name) { 
					SubEffect[index]={'opacity':1,'height':elem.origheight}; 
				} else {
					SubEffect[index]={'opacity':0,'height':1};
				}}
			);
		this.SubmenuEffects.start(SubEffect);
	}
};
