

// Print Page
function printPage() {
    var userAgent=navigator.userAgent.toLowerCase();

    if (window.print) {
        window.print();
    }
    else if (userAgent.indexOf("mac") != -1) {
        alert("Press 'Cmd+p' on your keyboard to print article.");
    }
    else {
        alert("Press 'Ctrl+p' on your keyboard to print article.")
    }
}

//Beta Dropdown Script
var myLast = null;

window.onload = initDropdowns;

function initDropdowns()
{
    var nav = "nav";
    var link_pre = "nav_";
    var drop_pre = "drop_";
    //
    myLinks = document.getElementById(nav).getElementsByTagName('a');
    //
    for (i = 0; i < myLinks.length; i++) {
        if (myLinks[i].id.substring(0,4) == link_pre && myLinks[i].className != 'button_at'){
            //
            myLink = myLinks[i];
            myDrop = document.getElementById(drop_pre+myLink.id.substring(4));
            //
            if(myDrop){
                myDrop.parentLink = myLink;
                myLink.dropMenu   = myDrop;
                //
                myLink.onmouseover = function(){ show(this,this.dropMenu) };
                myDrop.onmouseover = function(){ show(this.parentLink,this) };
                myLink.onmouseout  = function(){ trigger_hide(this,this.dropMenu) };
                myDrop.onmouseout  = function(){ trigger_hide(this.parentLink,this) };
            }else
                error("no corresponding dropdown found for "+myLink.id);
        }
    }
}
/*
   the 'myLink' variable being passed into the following two functions can be used for any
   changes to the actual link, i.e. backgrounds, color, etc...
*/
function show(myLink,myObject)
{
    if (myLast != null && myLast != myObject){
        clearTimeout(myLast.trigger);
        hide(myLast.id);
    }
    myLast = myObject;
    clearTimeout(myObject.trigger);
    //
    myObject.style.visibility = "visible";
    myLink.firstChild.style.backgroundPosition = "right top";
}
function trigger_hide(myLink,myObject)
{
    myObject.trigger = setTimeout('hide("'+myObject.id+'")',200);
	if(document.getElementById("home"))
        myLink.firstChild.style.backgroundPosition = "center bottom";
    else
        myLink.firstChild.style.backgroundPosition = "center top";
}
function hide(myId)
{
    document.getElementById(myId).style.visibility = "hidden";
}
function error(msg)
{
    alert("error: "+msg);
}
// END Drop Down Menus

// START Telescoping Functions

function showItem(id) {
	document.getElementById("item"+id).className = "itemList_expanded";
	document.getElementById("plus"+id).className = "hideBtn";
	document.getElementById("minus"+id).className = "showBtn";
}
function hideItem(id) {
	document.getElementById("item"+id).className = "itemList_collapsed";
	document.getElementById("plus"+id).className = "showBtn";
	document.getElementById("minus"+id).className = "hideBtn";
}

// END Telescoping Functions

//Internal Popup Scripts

function createPopup(width,height,target,title)
{
    window.onscroll = checkResize;
    window.onresize = checkResize;
    
    var myPopup = createDiv();
    var myHTML = '<div id="'+myPopup.id+'back" class="popupBack"></div>';
    myHTML += '<div style="width:'+(Number(width)+16)+'px; height:'+(Number(height)+16)+'px; margin:-'+(height/2+8)+'px 0 0 -'+(width/2+8)+'px;" class="popupCenter popupBorder" ></div>';
    myHTML += '<div style="width:'+width+'px; height:'+height+'px; margin:-'+(height/2)+'px 0 0 -'+(width/2)+'px;" class="popupCenter" >';
    myHTML += '<iframe class="popupIframe" src="'+target+'" id="popup" name="popup"></iframe>';
    myHTML += '<p class="popupLabel">'+title+' <a href="#" onClick="fadeLastDiv(); return false;"><img src="http://www.countrysideucc.org/images/close.gif" border="0" alt="Close" /></a></p>';
    myHTML += '</div>';
    
    myPopup.style.position = "absolute";
    myPopup.style.opacity = 0;
    myPopup.innerHTML = myHTML;
    
    resizePopup(myPopup);
    new Effect.Fade(myPopup.id+'back',{duration:.5, from:0.0, to:0.2 });
    new Effect.Appear(myPopup.id,{duration:.5});
    myPopups.push(myPopup);
}
var myPopups = new Array();
function checkResize()
{
    for(var i=0; i<myPopups.length; i++){
        if(myPopups[i])
            resizePopup(myPopups[i]);
        else
            myPopups.splice(i,1);
    }
}
function resizePopup(myPopup)
{
    var myWidth = 0, myHeight = 0;
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    myPopup.style.width = myWidth+"px";
    myPopup.style.height = myHeight+"px";
    myPopup.style.left = scrOfX+"px";
    myPopup.style.top = scrOfY+"px";
}

var curDepth = 100;
function createDiv()
{	
    var myDiv = parent.document.createElement('div');
    var myId = 'div' + parent.curDepth;
    myDiv.setAttribute('id',myId);
    myDiv.style.zIndex = parent.curDepth;
    //
    parent.document.body.appendChild(myDiv);
    parent.curDepth++;
    return myDiv;
}
function removeDiv(myDiv)
{
    myDiv.parentNode.removeChild(myDiv);
}
function removeLastDiv()
{
    parent.curDepth = 100;

    while(parent.curDepth > 100 && !parent.document.getElementById('div' + parent.curDepth)) { parent.curDepth--; }
    removeDiv(parent.document.getElementById('div' + parent.curDepth));
}
var myFadeTrigger = null;
function fadeLastDiv()
{
    while(parent.curDepth > 100 && !parent.document.getElementById('div' + parent.curDepth)) { parent.curDepth--; }

    // To make this work anywhere, inside the iFrame and the Div, we must grab the id from the parent
    topDiv = parent.document.getElementById("div" + parent.curDepth)

    clearTimeout(myFadeTrigger);
    myFadeTrigger = setTimeout('removeDiv(topDiv)', 400);
    new Effect.Fade(topDiv, {duration:.5});
}
