// JavaScript Document

document.joining = false;

document.loggedInHTML = "<span class=\"headlineLink\" style=\"float:right; margin-right:15px;\">Logged in as [THEIKRUSER] | <a href=\"http://www.iveknownrivers.org/community/\" class=\"headlineLink\">my settings</a> | <a href=\"#\" onclick=\"javascript:logout();\" id=\logoutbutton\" class=\"headlineLink\">logout</a></span>";

document.loggedOutHTML = "<span class=\"headlineLink\" style=\"float:right; margin-right:15px;\"><a href=\"#\" id=\"showlogin\" class=\"headlineLink\">login</a><span id=\"ajaxlogin\">: <input name=\"userlogin\" type=\"text\" class=\"loginfield\" id=\"userlogin\" size=\"10\" /> password: <input name=\"userpassword\" type=\"password\" class=\"loginfield\" id=\"userpassword\" size=\"10\" /> <span class=\"formerror\" id=\"loginerror\"></span> <a href=\"#\" onclick=\"javascript:login();\" id=\"loginbutton\" class=\"headlineLink\">go</a> | <a href=\"#\" id=\"hidelogin\" class=\"headlineLink\">cancel</a></span> | <a href=\"#\"id=\"joinikrlink\" class=\"headlineLink\">join IKR</a></span></span>";

function storyEventsInit() {
	
	document.getElementById("motherheader").onmouseover = hiliteheadlineon;
	document.getElementById("motherheader").onmouseout = hiliteheadlineoff;
	document.getElementById("motherheader").style.cursor = "pointer";


	document.getElementById("hidelogin").onclick = hidelogin;
	document.getElementById("showlogin").onclick = showlogin;

	document.getElementById("joinikrlink").onclick = joinIKR;
	
}

function hiliteheadlineon(evt) {
	evt = (evt) ? evt : ((window.event) ? window.event : "")
    if (evt) {
        // process event here	
		this.blur();
		document.images.headlineimage.src = "http://www.iveknownrivers.org/images/interface-2.0/headline-ikr-ov.png";
    }
}

function hiliteheadlineoff(evt) {
		evt = (evt) ? evt : ((window.event) ? window.event : "")
    if (evt) {
        // process event here	
		this.blur();
		document.images.headlineimage.src = "http://www.iveknownrivers.org/images/interface-2.0/headline-ikr.png";
    }
}


function joinIKR(evt) {
	evt = (evt) ? evt : ((window.event) ? window.event : "")
    if (evt) {
		// process event here	
		this.blur();
		document.joining = true;
		document.getElementById("joinpanel").style.display = "block";
		document.getElementById("thelogin").innerHTML = document.loggedOutHTML;
		document.getElementById("showlogin").onclick = showlogin;
		document.getElementById("hidelogin").onclick = hidelogin;
		document.getElementById("joinikrlink").onclick = joinIKR;
    }
	return false;
}

function showlogin(evt) {
		evt = (evt) ? evt : ((window.event) ? window.event : "")
    if (evt) {
        // process event here
		this.blur();
		if (document.joining == true) {
			document.getElementById("joinpanel").style.display = "none";
			document.joining = false;
		}
		document.getElementById("ajaxlogin").style.display = "inline";
    }
	return false;
}

function hidelogin(evt) {
	evt = (evt) ? evt : ((window.event) ? window.event : "")
    if (evt) {
		// process event here	
		this.blur();
		document.getElementById("ajaxlogin").style.display = "none";
		if (document.commenting == true) { document.commenting = false; }
		document.forms[0].userlogin.value = "";
		document.forms[0].userpassword.value = "";
    }
	return false;
}


function login() {
	document.forms[0].action = "javascript:sendData('../lib/login-user.php',0);";
	document.forms[0].submit();
	return false;
}

function logout() {
	document.forms[0].action = "javascript:sendData('../lib/logout-user.php',1);";
	document.forms[0].submit();
	return false;
}