/**
 *
 * Template initialization
 *
 * @package		ge_v1 template
 * @since			1.5
 * @version   1.0
 */

/**
 * Update the LI element top menu
 * set the className to 'active' if the A child is active
*/
function fixTopmenu(){
	var ul = $$("ul[class=menu-nav]").each(function(el){
		var i, o;
		for (i=0; i<el.childNodes.length; i++){
			var li = el.childNodes[i];
			if(li.id == "current")
				return;
			if (li.nodeName=="LI"){
				o = li.className.indexOf('item')
				if(o != -1){
					name = "div[class=moduletable_"+li.className.substring(o+4)+"]";
					if($$(name).length) {
						li.id="current";
						return;
					}
				}
			}
		}
	});
}

function hideRightColumnIfEmpty() {
	var e = $("rightcolumn");
	if(e && e.innerHTML.length < 2)
		e.style.display = 'none';
}

function moveModifyDate() {
	el = $$('*[class=modifydate]');
	if(el && el[0]) {
		mdt = document.createElement("div");
		mdt.id = "modifydatetime_1";
		mdt.name = mdt.id;
		mdt.className="modifydate";
		mdt.style.position = "absolute";
		mdt.style.overflow = "hidden";
		mdt.style.textAlign = "right";
		mdt.style.margin = "0 auto";
		mdt.style.cssFloat = "right";
		mdt.style.styleFloat = "right";
		mdt.style.left = "720px";
		mdt.style.top = "24px";
		mdt.style.width = "200px";
		mdt.style.height = "16px";
		mdt.innerHTML = el[0].innerHTML;
		
		$('top').appendChild(mdt); 
	}
}

function makeScrollable() {
	$$('*[class*=scrollable]').each(function(el){
		new ScrollControl(el, {'createControls': true});
	});
}

window.addEvent('load', function() {
	fixTopmenu();
	hideRightColumnIfEmpty();
	moveModifyDate();
	makeScrollable();
});
