// JavaScript Document
var scroll_dur = 450;
var Ajax;
var c1 = 'maincolumn';
var c2 = 'maincolumn_full';
var container;
var ajaxAppend = 'tmpl=raw';
var currentPage = 'home';
var lastPage;

function popupWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}


window.addEvent('domready', function() 
{
	
	container = ($(c2)) ? c2 : ( ($(c1)) ? c1 : null );
	init();																														
});




function init()
{
	new SmoothScroll({ duration:scroll_dur }, window);				
	initSpecialNav();
	

}



function initSpecialNav()
{
	
		var szNormal = 90, szSmall  = 80, szFull   = 120;
			
		var links = $$("#green_top .moduletable a");
		if (links) 
		{
			var fx = new Fx.Elements(links, {wait: false, duration: 400, transition: Fx.Transitions.Back.easeOut});
			links.each(function(eLink, i) 
			{
				eLink.addEvent("mouseenter", function(event) 
				{
					var o = {};
					o[i] = {width: [eLink.getStyle("width").toInt(), szFull]}
					links.each(function(other, j) 
					{
						if(i != j) 
						{
							var w = other.getStyle("width").toInt();
							if(w != szSmall) o[j] = {width: [w, szSmall]};
						}
					});
					fx.start(o);
				});
				
				eLink.addEvent("click", function(event) 
				{					
					new Event(event).stop(); 					
					getPage(this.href);
				});
			});
			
			var green_top = $("green_top"); 
			
			if (green_top) {
				green_top.addEvent("mouseleave", function(event) {
					var o = {};
					links.each(function(eLink, i) {
						o[i] = {width: [eLink.getStyle("width").toInt(), szNormal]}
					});
					fx.start(o);
				});
				
				
			}
		}		
		
}

initLoadedPage = function()
{
	$(container).removeClass('ajax-loading');
}


function getPage(id)
{
	var append = '?' + ajaxAppend;
	switch(id)
	{
		case "home":
				currentPage = baseUrl + append;
			break;		
		default:
			currentPage = id + '&' + ajaxAppend;
		break;
	}
	
	if (currentPage != lastPage) 
	{
				$(container).empty().addClass('ajax-loading');
				new Ajax(currentPage,{method: 'get',update: $(container), onComplete: initLoadedPage }).request();	
				lastPage = currentPage;
	}		
}
