var enabledMenu = true;
var lastMouseOver = false;
function openLeftMenu(e)
{
	lastMouseOver = e;
	var img = e.getElementsByTagName('img')[0];
	tmp = e.id.split("_");
	var eid = tmp[1];
	var submenu = document.getElementById('submenu_'+eid);
	if(submenu != undefined)
	{
		img.src = img.name;
		if( lastSubMenuShown != submenu && enabledMenu == true )
		{
			enabledMenu = false;
			if( lastSubMenuShown != '' )
				Effect.toggle(lastSubMenuShown, 'blind', {duration:0.3});
			Effect.toggle(submenu, 'blind', {duration:0.3,queue:'end',afterFinish:function(){enabledMenu = true;openLeftMenu(lastMouseOver);}});
			lastSubMenuShown = submenu;
			return true;
		}
	}
	else
		return false;
}

function getElementsByClassName(className, tag, elm)
{
	var testClass = new RegExp("(^|s)" + className + "(s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i ];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}

function ajaxUpdater(url, params, htmlId, method, async)
{
	if( method == undefined ) method = "get";
	if( async == undefined ) async = "true";
	var request = new Ajax.Updater( htmlId, url, { method: method, asynchronous: async, parameters: params, evalScripts: true, onComplete: function(){ hideLoading(); } } ); 
}

function overVote(articleID,value)
{
	for(i=1;i<=5;i++)
		$( "note_" + articleID + "_" + i ).src = ( i <= value ) ? $( "note_" + articleID + "_" + i ).src.replace("vote_flash_off", "vote_flash_on") : $( "note_" + articleID + "_" + i ).src.replace("vote_flash_on", "vote_flash_off");
}

function outVote(articleID, score)
{
	for(i=1;i<=5;i++)
		$( "note_" + articleID + "_" + i ).src = ( i <= score ) ? $( "note_" + articleID + "_" + i ).src.replace("vote_flash_off", "vote_flash_on") : $( "note_" + articleID + "_" + i ).src.replace("vote_flash_on", "vote_flash_off");
}

function ajaxPopup(url)
{
	if( $('popupcontent') != undefined )
	{
		$('popup').className = "alternative";
		new Ajax.Updater($('popupcontent'), url, {method:'get', evalScripts:true, onComplete: displayPopup});
	}
}

function displayPopup()
{
	new Effect.Parallel( [ new Effect.Appear("popuplayer", {from:0,to:0.5}), new Effect.Appear("popup", {from:0,to:1.0}) ], { duration: 1.0 } );
	//addEvent($('popup'), "click", closePopup);
}

function closePopup()
{
	new Effect.Fade("popup");
	new Effect.Fade("popuplayer");
}

function incrementViewCount(url)
{
	ajaxUpdater(url, '', $('viewCount'));
}