function GenerateGetElement()
{
	if (document.getElementById) return function(id) { return document.getElementById(id); }
	else if (document.all) return function(id) { return document.all[id]; }
	else if (document.layers) return function(id) { document.layers[id]; }
}
var GetElement;
GetElement = GenerateGetElement();

function roll(element, type)
{
    if (element != null)
    {
        var old = element.src;

        var newsrc = ""; 
        if (type == "on")
            newsrc = old.replace("_off", "_on");
        else 
            newsrc = old.replace("_on", "_off");  

        element.src = newsrc;    
    }
}

function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=800,height=1300,scrollbars=yes');
return false;
}

/*
function ShowGalleryImage(strImageSource)
{
    GetElement("imgMainGalleryImage").src = strImageSource;
}
*/

function ShowGalleryImage(strMainImageElement, strMainImageSource)
{
    //Update Main Image
    GetElement(strMainImageElement).src = strMainImageSource;
}

//ShowGalleryImage
//e.g. Input: 'imgPrivateSuite', 'images/lgPrivate2.jpg', this, 'thPrivate2,thPrivate3,thXXXX0'
//Notes: Quick Configuration over Convention Implementation
function ShowGalleryImage(strMainImageElement, strMainImageSource, OnObject, Off_ID_List)
{
	//Update the Main Image
    GetElement(strMainImageElement).src = strMainImageSource;
	
	//Turn all thumbnails off
	TurnThumbnailsOff(Off_ID_List);
	
	//Turn the clicked thumbnail image on
	roll(OnObject, 'on');
}

function TurnThumbnailsOff(Off_ID_List)
{
	var OffArray = Off_ID_List.split(",");
	var Index = 0;
	var Element;
	
	for(Index=0; Index < OffArray.length; Index++)
	{
		Element = document.getElementById(OffArray[Index]);
		roll(Element, 'off');
	}
}

function ClearCommentBox(tb)  
{   
    if (tb.value=="Please write additional requests here.")
        tb.value="";
}
function RestoreCommentBox(tb) 
{
    if (tb.value=="")
        tb.value="Please write additional requests here.";
}

//function SetUniqueRadioButton(nameregex, current)
//{
//      re = new RegExp(nameregex);
//      for(i = 0; i < document.forms[0].elements.length; i++)
//      {
//            elm = document.forms[0].elements[i]
//            if (elm.type == 'radio')
//            {
//                  if (re.test(elm.name))
//                  {
//                          elm.checked = false;
//                  }
//             }
//      }
//      current.checked = true;
//}

function openWindow(type,x)
{
    var newwin;
    
    switch(type)
    {
        case "LINK":
            newwin = window.open(x);
            break; 
        case "PDF":
            newwin = window.open("/pdfs/" + x + ".pdf","pdf_download","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=150,top=150,alwaysRaised=1");
            break;
        case "SPEAKER":
            newwin = window.open(x,"speaker_bio","width=340,height=500,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=150,top=150,alwaysRaised=1");
            break;
    }
    
    newwin.focus();
}
$(document).ready(function() {

    // get current active code for image replacement
    var strULID = $("#pnav").children("li.CMSListMenuHighlightedLI").children("ul").attr("id");
    
    // set the initial sub menu to display
    $("ul#" + strULID).css("left", GetSubMenu($("ul#" + strULID).attr("id")));
    $("ul#" + strULID).show();


    // this is for the primary LIs
    $("#pnav").children("li").hover(
        function(event) { /* HOVER ON */
        
        // let's first hide the active menu
        $("ul#" + strULID).hide();
                
        $(this).children("ul").show();
        $(this).children("ul").css("left", GetSubMenu($(this).children("ul").attr("id")));
        
        $(this).children("a").children("img").attr("src", $(this).children("a").children("img").attr("src").replace("_off", "_on"));
        $(this).children("a").toggleClass("CMSListMenuLI", true);
       
        
        // show sub menu for selected navigation
        $(this).children("ul").show();
        $(this).children("ul").css("left", GetSubMenu($(this).children("ul").attr("id")));

        // replace pnav image with it's on state and set background to be highlighted
        $(this).children("a").children("img").attr("src", $(this).children("a").children("img").attr("src").replace("_off", "_on"));
        $(this).children("a").toggleClass("CMSListMenuLinkHighlighted", true);
        
        },
        function(event) { /* HOVER OFF */
        $(this).children("ul").show();

        // only switch back to the off state if we aren't in that nav
        if ($(this).attr("class").indexOf("CMSListMenuHighlightedLI") < 0) {
            // hide menu
            $(this).children("ul").hide();

            $(this).children("a").toggleClass("CMSListMenuLinkHighlighted", false);
            $(this).children("a").children("img").attr("src", $(this).children("a").children("img").attr("src").replace("_on", "_off"));
            
            $("ul#" + strULID).show();

        }
        });

    // this is for the active ULs
    $("#pnav li ul li").hover(
        function(event) { /* HOVER ON */

            $("ul#" + strULID).show();

            // show menu
            $(this).show();
            $(this).css("left", GetSubMenu($(this).attr("id")));

            // switch out image
            $(this).children("a").children("img").attr("src", $(this).children("a").children("img").attr("src").replace("_off", "_on"));
            $(this).children("a").toggleClass("CMSListMenuLinkHighlighted", true);

        },
        function(event) { /* HOVER OFF */

            // only switch back to the off state if we aren't in that nav
            if ($(this).attr("class").indexOf("CMSListMenuHighlightedLI") < 0) {
                // hide menu
                $(this).show();

                $(this).children("a").children("img").attr("src", $(this).children("a").children("img").attr("src").replace("_on", "_off"));
                $(this).children("a").toggleClass("CMSListMenuLinkHighlighted", true);

                $("ul#" + strULID).show();
            }
        });
});




function GetSubMenu(strSubMenuID) {
    switch (strSubMenuID) {
        case "pnav_UL_1":
            return "-3px";
            break;
        case "pnav_UL_2":
            return "-119px";
            break;
        case "pnav_UL_3":
            return "-213px";
            break;
        case "pnav_UL_4":
            return "-320px";
            break;
        case "pnav_UL_5":
            return "-418px";
            break;
        default:
            return "0";
            break;
    }
}


var strOrg1, strOrg2, strOrg3, strOrg4, strOrg5;
function Roll(obj, strOrgSrc, status) {
    if (obj != null) {
    
        // let's find out what section this incoming image needs to highlight.
        if (status == "on") {
            var strCodeID;
            if (obj.src.indexOf("-1-") > -1) {
                strCodeID = "1";
                strOrg1 = strOrgSrc;
            }
            else if (obj.src.indexOf("-2-") > -1) {
                strCodeID = "2";
                strOrg2 = strOrgSrc;
            }
            else if (obj.src.indexOf("-3-") > -1) {
                strCodeID = "3";
                strOrg3 = strOrgSrc;
            }
            else if (obj.src.indexOf("-4-") > -1) {
                strCodeID = "4";
                strOrg4 = strOrgSrc;
            }
            else if (obj.src.indexOf("-5-") > -1) {
                strCodeID = "5";
                strOrg5 = strOrgSrc;
            }

            alert(strOrgSrc);


            obj.src = "/images/nav/" + strCodeID + "_on.gif";
        }
        else {
            if (obj.src.indexOf("-1-") > -1) {
                obj.src = strOrg1;
            }
            else if (obj.src.indexOf("-2-") > -1) {
                obj.src = strOrg2;
            }
            else if (obj.src.indexOf("-3-") > -1) {
                obj.src = strOrg3;
            }
            else if (obj.src.indexOf("-4-") > -1) {
                obj.src = strOrg4;
            }
            else if (obj.src.indexOf("-5-") > -1) {
                obj.src = strOrg5;
            }

        }
    }
}
