﻿var borderWidth = 50;
var columnDistance = 30;
var rightColumnWidthMD = 220;
var extraHeightMD = 60; 
var vDistance = 276;
var noteDistance = 26;
var noteTopDistance = 47 - noteDistance;
var noteHeight = 140;

function setClass(objectID,newClass) {
	if ( document.getElementById(objectID) ) { document.getElementById(objectID).className = newClass; }
}
function setStyle(objectID,styleName,newVal) {
	if ( document.getElementById(objectID) ) { document.getElementById(objectID).style[styleName] = newVal; }
}

function lockeNoteWindowOpen(objectID) {
	var liveHeight = findLivePageHeight();
	var liveWidth = findLivePageWidth();
	var noteWidth = liveWidth - 2 * borderWidth;
	var noteTop = liveHeight - noteTopDistance - noteDistance - noteHeight ;
	var columnHeight = liveHeight - vDistance - noteDistance - noteHeight ; 
	var columnHeightMD = liveHeight - vDistance - noteDistance - noteHeight + extraHeightMD ; 

	setStyle("note_container","width",noteWidth+"px");
	setStyle("note_container","top",noteTop+"px");
	setStyle("note_content","height",noteHeight+"px");
	setStyle("leftcol","height",columnHeight+"px");
	setStyle("rightcol","height",columnHeight+"px");
	setStyle("leftcol_md","height",columnHeightMD+"px");
	setStyle("rightcol_md","height",columnHeightMD+"px");

	var noteContent = document.getElementById("note_content");
	if (noteContent.hasChildNodes()) {
		for (var i=0; i<noteContent.childNodes.length; i++) {
			noteContent.childNodes.item(i).className = "hide_note";
		}
	}
	setClass(objectID,"show_note");
	setClass("note_container","show_me");
}

function lockeNoteWindowClose() {
	setLayout();
}

function findLivePageWidth() {
	if (window.innerWidth) { // Firefox, Safari
		return window.innerWidth;
	} else if (document.body.clientWidth) { // IE
    	return document.body.clientWidth + 50;
    } else {
    	return (null)
    }
}

function findLivePageHeight() {
	if (document.body.clientHeight) {
		return document.body.clientHeight;
	} else {
		return (null)
	}
}

function setLayout() { setLayoutCorrected(0) }
function setLayoutSafariOnload() { setLayoutCorrected(0) }
function setLayoutCorrected(correction) {
	var liveWidth = findLivePageWidth() + correction;
	var liveHeight = findLivePageHeight();
	var minWidth = (720 - columnDistance) / 2;
	var minWidthMD = 720 - columnDistance - rightColumnWidthMD ;
	var columnWidth = (liveWidth - 2 * borderWidth - columnDistance) / 2; if ( columnWidth < minWidth ) { columnWidth = minWidth };
	var leftColumnWidthMD = liveWidth - 2 * borderWidth - columnDistance - rightColumnWidthMD ; if ( leftColumnWidthMD < minWidthMD ) { leftColumnWidthMD = minWidthMD };
	var columnHeight = liveHeight - vDistance; 
	var columnHeightMD = liveHeight + extraHeightMD - vDistance; 
	var rightcolLeft = borderWidth + columnWidth + columnDistance;
	var rightcolLeftMd = borderWidth + leftColumnWidthMD + columnDistance;

	setStyle("leftcol_container","width",columnWidth+"px");
	setStyle("rightcol_container","width",columnWidth+"px");
	setStyle("rightcol_container","left",rightcolLeft+"px");
	setStyle("leftcol","height",columnHeight+"px");
	setStyle("rightcol","height",columnHeight+"px");
	
	setStyle("leftcol_container_md","width",leftColumnWidthMD+"px");
	setStyle("rightcol_container_md","width",rightColumnWidthMD+"px");
	setStyle("rightcol_container_md","left",rightcolLeftMd+"px");
	setStyle("leftcol_md","height",columnHeightMD+"px");
	setStyle("rightcol_md","height",columnHeightMD+"px");

	setClass("note_container","hide_me");
	setStyle("note_content","height","0px");
}

/* Make menu hoverable in IE */

function over() {
	if (document.getElementById("menu")) {
		var nav1 = document.getElementById("menu").getElementsByTagName("li");
		for (var i=0; i<nav1.length; i++) {
			nav1[i].onmouseover=function() { this.className+=" over" }
			nav1[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" over\\b"), "") }
		}
	}
}

/* Attach onresize and onload */

if (window.attachEvent) { // IE
	window.attachEvent("onresize", setLayout);
	window.attachEvent("onload", setLayout)
	window.attachEvent("onload", over);
}
else if (window.addEventListener) { // Firefox, Safari
	window.addEventListener("resize", setLayout, false);
	if ( navigator.vendor.search(/Apple/) != -1) { // Safari
		window.addEventListener("load", setLayoutSafariOnload, false)
	} else { // Firefox
		window.addEventListener("load", setLayout, false)
	}
}
else { // old fashioned way
	window.onresize = setLayout;
	window.onload = setLayout;
}

// function showparent(Element) { Element.parentNode.style.textDecoration="underline"; }
// function hideparent(Element) { Element.parentNode.style.textDecoration="none"; }

function showparent(Element) { Element.parentNode.style.background="#D5E6FF"; }
function hideparent(Element) { Element.parentNode.style.background="none"; }


/* Overlib style */

var ol_fgcolor="#ffffff";
var ol_bgcolor="#000000";
var ol_width="auto";

