/* (c) dev.osiacat.ru, 2007 */

var menu = [
	{ name : 'about_project', uri : '/about/',    caption: 'О проекте', width: 110,  height: 27 },
	{ name : 'leaves',        uri : '/leaves/',   caption: '&laquo;Leaves&raquo;', width: 110,  height: 27 },
	{ name : 'contact',       uri : '/contact/',  caption: 'Связаться', width: 110,  height: 27 },
	{ name : 'forum',         uri : '/forum/',    caption: 'Форум', width: 110,  height: 27 }
];

function FlashInstalled(version){
	var plugin;
	if( !version ){
		var version = 5;	
	}
	var flash = false;
	
	if (navigator.plugins) {
	    if (navigator.plugins["Shockwave Flash"]) {
	        plugin = navigator.plugins["Shockwave Flash"].description;
	        flash =
	            parseInt(plugin.charAt(plugin.indexOf('.') - 1)) >= version;
	
	    } else {
	        if ((navigator.userAgent.indexOf('MSIE') != -1)
	            && (navigator.userAgent.indexOf('Win') != -1))
	        {
	            var vb = '<script language="vbscript">\n'
	                   + 'if ScriptEngineMajorVersion >= 2 then\n'
	                   + '  on error resume next\n'
	                   + '  flash = IsObject(CreateObject('
	                   + '     "ShockwaveFlash.ShockwaveFlash.'
	                   +        version + '"))\n'
	                   + 'end if\n'
	                   + '<' + '/script>';
	            obj = document.getElementById('menu');
				obj.innerHTML = vb + obj.innerHTML;
	        }
	    }
	}
	    
	return flash;
}
	
function addEvent(elt, name, handler, atEnd) {
	name = name.replace(/^(on)?/, 'on'); 
	var prev = elt[name];
	var tmp = '__tmp';
	elt[name] = function(e) {
		if (!e) e = window.event;
		var result;
		if (!atEnd) {
			elt[tmp] = handler; result = elt[tmp](e); elt[tmp] = null;
			if (result === false) return result;
		}
		if (prev) {
			elt[tmp] = prev; result = elt[tmp](e); elt[tmp] = null;
		}
		if (atEnd && result !== false) {
			elt[tmp] = handler; result = elt[tmp](e); elt[tmp] = null;
		}
		return result;
	}
	return handler;
}

function addOnloadEvent(handler)
{
	var vr = window.addEventListener ||
				window.attachEvent ? window :
					document.addEventListener ? document : null;
	return addEvent(vr, "onload", handler);
}

function PrintFlashMenu(){
	var active = false;
	var swfObj = new PublishSWF();
	swfObj.bgcolor = "#daf8d3";//e1f0d5
	var elt = document.getElementById("menu");
	for( var i =0; i < menu.length; i++ ){
		var swf = menu[i];
		if( window.location.pathname.match(new RegExp(swf.uri)) ){
			active = true;
		}
		else{
			active = false;
		}
		swfObj.src = 'swf/'+swf.name+'.swf?uri='+swf.uri+(active? '&active=true' : '');
		swfObj.id = swf.name;
		swfObj.name = swf.name;
		swfObj.width = swf.width;
		swfObj.height = swf.height;
		elt.innerHTML = elt.innerHTML + swfObj.Publish();
	}
}

function PrintStaticMenu(){
	var active = false;
	var elt = document.getElementById("menu");
	var result = new Array();
	for( var i =0; i < menu.length; i++ ){
		var item = menu[i];
		if( window.location.pathname.match(new RegExp(item.uri)) ){
			item.caption = '<b>' + item.caption + '</b>';
		}
		result.push('<a href="'+item.uri+'">'+item.caption+'</a>');
	}
	elt.innerHTML = result.join(" | ");
}

addOnloadEvent(function(){
	if( FlashInstalled(6) ){
		PrintFlashMenu();
	}
	else{
		PrintStaticMenu();
	}
	
});

