/***********************************************
* Pop-it menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var defaultMenuWidth="9.4em" //set default menu width.

var linkset=new Array()
var menuObj = null
var linkObj = null
var prevlinkObj = null

////No need to edit beyond here

var ie5=document.all && !window.opera
var ns6=document.getElementById

if (ie5||ns6)
document.write('<div id="popitmenu" onMouseover="clearhidemenu();" onMouseout="dynamichide(event)"></div>')

function iecompattest(){
return (document.compatMode && document.compatMode.indexOf("CSS")!=-1)? document.documentElement : document.body
}

function showmenu(linkobj, menuobj, menuPosition, xmargin, ymargin, optlinkWidth, optWidth){
//alert("ALERT1: inside showmenu()");
if (!document.all&&!document.getElementById)
    return;
clearhidemenu()
if(!menuobj)
    return;
//alert("ALERT2: inside showmenu()");

menuobj.contentwidth=menuobj.offsetWidth
menuobj.contentheight=menuobj.offsetHeight

if (typeof xmargin == "undefined")
xmargin = 0

if (typeof ymargin == "undefined")
ymargin = 0

var eventX
var eventY
var linkWidth
var coord=new Array()
var diff;

if(menuPosition.charAt(0) == 'c') {
    coord = cursorPos(window.event);
    menuPosition = menuPosition.substr(1);
}
else
    coord = findPos(linkobj);
    
linkWidth = ((typeof optlinkWidth != "undefined") && (optlinkWidth > 0)) ? optlinkWidth : linkobj.offsetWidth 

if (menuPosition == 'n') {  /* Position menu north of link */
eventX = coord[0]
eventY = coord[1] - menuobj.contentheight
} else if (menuPosition == 'nw') {
eventX = coord[0] - menuobj.contentwidth
eventY = coord[1] - menuobj.contentheight
} else if (menuPosition == 'se') {  /* Position menu southeast of link */
eventX = coord[0] + linkWidth
eventY = coord[1]
} else if (menuPosition == 'sw') {  /* Position menu southwest of link */
eventX = coord[0] - menuobj.contentwidth
eventY = coord[1]
} else {  /* Position menu south of link */
eventX = coord[0]
eventY = coord[1] + linkobj.offsetHeight
}

// Apply margins
eventX += xmargin
eventY += ymargin

//alert("xmargin="+xmargin+"\nymargin="+ymargin+"\neventX="+eventX+"\neventY="+eventY);
/*
if (ie5) {
    alert("ie5\niecompattest().scrollTop+eventY="+iecompattest().scrollTop+eventY);
}
else {
    alert("not ie5\nwindow.pageYOffset+eventY="+window.pageYOffset+eventY);
}
*/

//Find out how close the mouse is to the corner of the window
var rightedge=ie5? iecompattest().clientWidth-eventX : window.innerWidth-eventX
var bottomedge=ie5? iecompattest().clientHeight-eventY : window.innerHeight-eventY
//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.contentwidth) {
// Changed by SHC (5/27/09): move the horizontal position of the menu to the left by the difference 
// of the menu object that extends beyond the edge plus 10 pixels.
diff = menuobj.contentwidth - rightedge + 10;
menuobj.style.left=ie5? iecompattest().scrollLeft+eventX-diff+"px" : window.pageXOffset+eventX-diff+"px";
}
else {
//position the horizontal position of the menu where the mouse was clicked
menuobj.style.left=ie5? iecompattest().scrollLeft+eventX+"px" : window.pageXOffset+eventX+"px";
}

// Changed by SHC (5/27/09): move the vertical position of the menu upwards by the difference 
// of the menu object that extends beyond the edge plus 10 pixels.
if (bottomedge<menuobj.contentheight) {
diff = menuobj.contentheight - bottomedge + 10;
menuobj.style.top=ie5? iecompattest().scrollTop+eventY-diff+"px" : window.pageYOffset+eventY-diff+"px";
//alert("Y1: diff="+diff+"\ntop="+menuobj.style.top);
}
else {
menuobj.style.top=ie5? iecompattest().scrollTop+eventY+"px" : window.pageYOffset+eventY+"px";
//alert("Y2: top="+menuobj.style.top);
}
menuobj.style.visibility="visible";
menuObj = menuobj;
return false;
}

function convertpx2em(px) {
    return ((px/16) + "em");
}

function contains_ns6(a, b) {
//Determines if 1 element in contained in another- by Brainjar.com
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function hidemenu(){
    if (window.menuObj) {
        menuObj.style.visibility="hidden"
    }
}

function dynamichide(e){
if (ie5&&!menuObj.contains(e.toElement))
hidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
hidemenu()
}

function delayhidemenu(){
delayhide=setTimeout("hidemenu()",500)
}

function clearhidemenu(){
    if (window.delayhide)
        clearTimeout(delayhide)
}

function findPos(obj) {
//	alert("ENTRY: scrollTop = " + obj.scrollTop + ", X = " + obj.offsetLeft + ", Y = " + obj.offsetTop)
	var curleft = curtop = scrtop = i = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		scrtop = obj.scrollTop
		while (obj = obj.offsetParent) {
			++i
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
			scrtop += obj.scrollTop
//			alert("count = " + i + ", scrollTop = " + scrtop + ", X = " + curleft + ", Y = " + curtop)
		}
	}
//	alert("iecompattest().scrollTop = " + iecompattest().scrollTop)
	if (iecompattest().scrollTop > 0)
	    curtop -= iecompattest().scrollTop

	if (iecompattest().scrollLeft > 0)
	    curleft -= iecompattest().scrollLeft
	    
//	alert("scrollTop = " + scrtop + ", X = " + curleft + ", Y = " + curtop)
	return [curleft,curtop];
}

function cursorPos(evt) {
	evt = window.event;
	cursorX = evt.screenX;
	cursorY = evt.screenY;
	return [cursorX, cursorY];
}

function setMenuObj(id) {
    menuObj = ie5 ? document.all[id] : document.getElementById(id);
}

function setLinkObj(obj) {
    linkObj = obj;
}

function setPrevLinkObj(saveObj) {
    prevlinkObj = saveObj
}

function getcss(selector, property) {
//    alert("In getcss - start");
    var i, r, s=document.styleSheets && document.styleSheets[0];
    if(s) {
	r = s.rules ? s.rules : s.cssRules;
	if(r) {
	    for(i = 0; i < r.length; i++) {
		if(r[i].selectorText.toLowerCase() === selector.toLowerCase()) {
		    return ( r[i].style[property] );
		}
	    }
	}
    }
    return null;
}

function setWrapperHeight(max) {
    var lh = document.getElementById('leftside').offsetHeight;
    var rh = document.getElementById('rightside').offsetHeight;
    var m = 0;
//    alert("lh="+lh+"\nrh="+rh);
    if (typeof max != "undefined")
        m = max;
    if((m > rh) && (m > lh))
        document.getElementById('wrapper').style.height = m+"px";
    else
    if(lh < rh)
        document.getElementById('wrapper').style.height = rh+"px";
    else
        document.getElementById('wrapper').style.height = lh+"px";
    return;
}

function compare(first, second) {
    if(first.constructor == Array) {
//        alert("object is an Array");
        for(var i = 0; i < first.length; i++) {
            if(first[i] == second)
                return true;
        }
    }
    else
    if(first == second)
        return true;
    return false;
}

function showimage(obj, img, id, menupos, xpos, ypos) {

    if (typeof xpos == "undefined")
    xpos = 0

    if (typeof ypos == "undefined")
    ypos = 0

    var i = "<img src=" + "'" + img + "' />";
    var popupimage = document.getElementById(id);
    document.getElementById(id).innerHTML = i;
    showmenu(obj, popupimage, menupos, xpos, ypos);
//    alert("inside showimage() - returned from showmenu()");
}

if (ie5||ns6)
document.onclick=hidemenu

