﻿/*/***************************************************************************************************************************
/// <name>     HDSF - Common Java Script Library</name>
/// <summary>  This JavaScript provides common functions for the menu and other dynamic navigation functionality.</summary>
/// <history>
///            Konrad Kyc [2008 © Vantagesoft.ca] - 2008-09-14 - Created.
/// </history>
/// <notes>
/// </notes>
///***************************************************************************************************************************/

var hdsfWhatIsShown = false;
var loginPopupShown = false;
var brandExperienceInfoShown = false;
var directionsPopupShown = false;
var siteBlockPosition = [0, 0];
var siteBlockPositionCalculated = false;

var LOGIN_FORM_HTML = '<div id="divInnerLogin"><div style="padding: 20px 20px 0px 0px;"><label for="txtUserName">User Name </label><input id="txtUserName" class="LoginTextBox" size="12" /></div><div style="padding: 10px 20px 13px 0px;"><label for="txtUserName">Password </label><input id="txtPassword" type="password" class="LoginTextBox" size="12" /></div><div style="padding: 0px 20px 0px 0px;"><a onclick="Login(); return false;" href=""><img src="Images/Global-SubmitButton.gif" alt="Submit" /></a></div><div style="clear: both;" class="ClearFF"></div></div>';
var LOGIN_FORM_HTML_ADMIN = '<div id="divInnerLogin"><div style="padding: 20px 20px 0px 0px;"><label for="txtUserName">User Name </label><input id="txtUserName" class="LoginTextBox" size="12" /></div><div style="padding: 10px 20px 13px 0px;"><label for="txtUserName">Password </label><input id="txtPassword" type="password" class="LoginTextBox" size="12" /></div><div style="padding: 0px 20px 0px 0px;"><a onclick="Login(); return false;" href=""><img src="../Images/Global-SubmitButton.gif" alt="Submit" /></a></div><div style="clear: both;" class="ClearFF"></div></div>';

window.onload = InitializeOnLoad;
window.onresize = ReCalculateSiteBlockPosition;

///**********************************************************************************
/// <name>    Initialize </name>
/// <summary> Initialize function that loads immediately when content is downloaded.</summary>
///**********************************************************************************
function Initialize()
{
    PageInit();
    siteBlockPosition = FindPosition(GetElementObjectById("divSiteBlock"));
}

///**********************************************************************************
/// <name>    InitializeOnLoad </name>
/// <summary> Initialize function that loads on PageLoad.</summary>
///**********************************************************************************
function InitializeOnLoad()
{
    PageInitOnLoad();
}

///**********************************************************************************
/// <name>    CalculateSiteBlockPosition </name>
/// <summary> Calculates the position of the siteblock after resize.</summary>
///**********************************************************************************
function CalculateSiteBlockPosition()
{
    if(!siteBlockPositionCalculated)
    {
        siteBlockPosition = FindPosition(GetElementObjectById("divSiteBlock"));
        siteBlockPositionCalculated = true;
    }
}

///**********************************************************************************
/// <name>    ReCalculateSiteBlockPosition </name>
/// <summary> Re-calculates the position of the siteblock after resize.</summary>
///**********************************************************************************
function ReCalculateSiteBlockPosition()
{
    siteBlockPosition = FindPosition(GetElementObjectById("divSiteBlock"));
    siteBlockPositionCalculated = true;
}

function PageInitOnLoad(){} // Virtual Function
function PageInit(){}       // Virtual Function

///**********************************************************************************
/// <name>    OpenHDWhatPopUp </name>
/// <summary> Opens the Popup for the HDSF Caption.</summary>
///**********************************************************************************
function OpenHDWhatPopUp()
{
    OpenHDWhatPopUpCustomPath('');
}

///**********************************************************************************
/// <name>    OpenHDWhatPopUp </name>
/// <summary> Opens the Popup for the HDSF Caption. This override lets you specify the
///           base path of the images</summary>
///**********************************************************************************
function OpenHDWhatPopUpCustomPath(basePath)
{
    // Calculate Site Block Position (if not calculated)
    CalculateSiteBlockPosition();
    
    var elementDiv = GetElementObjectById("divHDWhatPopup");
    var innerElementDiv = GetElementObjectById("divHDWhatInnerPopup");    
    var elementPos = FindPosition(GetElementObjectById("imgHDWhatCaption"));
    var elementPosX = elementPos[0] - siteBlockPosition[0]; // This position is relative to the site block
    var elementPosY = elementPos[1] - siteBlockPosition[1]; // This position is relative to the site block
    
    var initLeftPos = (elementPosX - 0) + "px";
    var initTopPos = (elementPosY - 0) + "px";
    var destLeftPos = (elementPosX - 273) + "px";
    var destTopPos = (elementPosY - 0) + "px";
    var closeTopPos =   (elementPosY - 0) + "px";
            
    if(BrowserSupportsJQuery())
    {           
        if(!hdsfWhatIsShown)
        {           
            innerElementDiv.innerHTML = '<div class="HDWhatPopup"><div>Need some help with your pronunciation?</div><br /><div class="HDPronunciation"><span>&quot;Huht-Nur | Day-Co-Lohnj&quot;</span></div><div><object id="hfsfPronounce" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="59" height="20"><param name="movie" value="Images/Flash/Global-HDPronounciation.swf" /><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><!--[if !IE]>--><object type="application/x-shockwave-flash" data="' + basePath + 'Images/Flash/Global-HDPronounciation.swf" width="59" height="20"><!--<![endif]--><img src="' + basePath + 'Images/Global-Spacer.gif" alt="" longdesc="" /><!--[if !IE]>--></object><!--<![endif]--></object></div></div>';
            
            var flashvars = {};
            var params = {
                bgcolor: "#ffffff",
                wmode: "transparent",
                quality: "high",
                allowfullscreen: "false"
            };
            var attributes = {};
            swfobject.embedSWF(basePath + "Images/Flash/Global-HDPronounciation.swf", "hfsfPronounce", "59", "20", "8.0.0", basePath + "Images/Flash/Flash-ExpressInstall.swf", flashvars, params, attributes);            
            
            $("#divHDWhatPopup").css({width:"0px", height:"0px", left:initLeftPos, top:initTopPos});
            $("#divHDWhatPopup").animate({width:"298px", height:"162px", left:destLeftPos, top:destTopPos},400);
            hdsfWhatIsShown = true;
        }
        else
        {
            $("#divHDWhatPopup").animate({ width: "0px", height: "0px", left: elementPosX, top: closeTopPos }, 600, function() { innerElementDiv.innerHTML = ''; $(this).hide(); });            
            hdsfWhatIsShown = false;
        }
    }
    else
    {
        if(!hdsfWhatIsShown)
        {
            innerElementDiv.innerHTML = '<div class="HDWhatPopup"><div>Need some help with your pronunciation?</div><br /><div class="HDPronunciation"><span>&quot;Huht-Nur | Day-Co-Lohnj&quot;</span></div><div><object id="hfsfPronounce" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="59" height="20"><param name="movie" value="' + basePath + 'Images/Flash/Global-HDPronounciation.swf" /><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><!--[if !IE]>--><object type="application/x-shockwave-flash" data="' + basePath + 'Images/Flash/Global-HDPronounciation.swf" width="59" height="20"><!--<![endif]--><img src="' + basePath + 'Images/Global-Spacer.gif" alt="" longdesc="" /><!--[if !IE]>--></object><!--<![endif]--></object></div></div>';

            var flashvars = {};
            var params = {
                bgcolor: "#ffffff",
                wmode: "transparent",
                quality: "high",
                allowfullscreen: "false"
            };
            var attributes = {};
            swfobject.embedSWF(basePath + "Images/Flash/Global-HDPronounciation.swf", "hfsfPronounce", "59", "20", "8.0.0", basePath + "Images/Flash/Flash-ExpressInstall.swf", flashvars, params, attributes);            
               
            elementDiv.style.display = 'block';
            elementDiv.style.left = destLeftPos;
            elementDiv.style.top = destTopPos;
            hdsfWhatIsShown = true;
        }
        else
        {
            elementDiv.style.display = 'none';
            hdsfWhatIsShown = false;
            innerElementDiv.innerHTML = ''; 
        }
    }
    return false;
}

///**********************************************************************************
/// <name>    CloseHDWhatPopUp </name>
/// <summary> Closes the HDSF Caption popup.</summary>
///**********************************************************************************
function CloseHDWhatPopUp()
{
    if(hdsfWhatIsShown)
    {
        var innerElementDiv = GetElementObjectById("divHDWhatInnerPopup");
        
        if(BrowserSupportsJQuery())
        {
            var elementPos = FindPosition(GetElementObjectById("imgHDWhatCaption"))
            var elementPosX = elementPos[0] - siteBlockPosition[0]; // This position is relative to the site block
            var elementPosY = elementPos[1] - siteBlockPosition[1]; // This position is relative to the site block
            
            var initLeftPos = (elementPosX - 0) + "px";
            var initTopPos = (elementPosY - 0) + "px";
            var destLeftPos = (elementPosX - 273) + "px";
            var destTopPos = (elementPosY - 0) + "px";
            var closeTopPos =   (elementPosY - 0) + "px";
                    
            $("#divHDWhatPopup").animate({width:"0px", height:"0px", left:elementPosX, top:closeTopPos},600, function() {innerElementDiv.innerHTML = '';});
            $("#divHDWhatPopup").hide(1);            
            hdsfWhatIsShown = false;
        }
        else
        {
            GetElementObjectById("divHDWhatPopup").style.display = 'none';
            hdsfWhatIsShown = false;
            innerElementDiv.innerHTML = '';
        }
    }
}

///**********************************************************************************
/// <name>    OpenLoginPopUp </name>
/// <summary> Opens the Popup for the Login Form.</summary>
///**********************************************************************************
function OpenLoginPopUp(isAdminPage)
{
    // Calculate Site Block Position (if not calculated)
    CalculateSiteBlockPosition();
    
    var elementDiv = GetElementObjectById("divLoginPopup");
    var innerElementDiv = GetElementObjectById("divLoginInnerPopup");
    var elementPos = FindPosition(GetElementObjectById("divLoginLabel"))
    var elementPosX = elementPos[0] - siteBlockPosition[0]; // This position is relative to the site block
    var elementPosY = elementPos[1] - siteBlockPosition[1]; // This position is relative to the site block
    
    var initLeftPos = (elementPosX + 0) + "px";
    var initTopPos = (elementPosY + 15) + "px";
    var destLeftPos = (elementPosX - 187) + "px";
    var destTopPos = (elementPosY + 15) + "px";
    var closeTopPos =   (elementPosY + 15) + "px";    
    
    if(BrowserSupportsJQuery())
    {                   
        if(!loginPopupShown)
        {           
            if(isAdminPage)
                innerElementDiv.innerHTML = LOGIN_FORM_HTML_ADMIN;
            else
                innerElementDiv.innerHTML = LOGIN_FORM_HTML;
                
            $("#divLoginPopup").css({width:"0px", height:"0px", left:initLeftPos, top:initTopPos});
            $("#divLoginPopup").animate({width:"219px", height:"127px", left:destLeftPos, top:destTopPos},400, function() {GetElementObjectById("txtUserName").focus();});
            loginPopupShown = true;
        }
        else
        {
            $("#divLoginPopup").animate({width:"0px", height:"0px", left:elementPosX, top:closeTopPos},600, function() {innerElementDiv.innerHTML = '';});
            $("#divLoginPopup").hide(1);            
            loginPopupShown = false;
        }
    }
    else
    {
        if(!loginPopupShown)
        {
            if(isAdminPage)
                innerElementDiv.innerHTML = LOGIN_FORM_HTML_ADMIN;
            else
                innerElementDiv.innerHTML = LOGIN_FORM_HTML;
                
            elementDiv.style.display = 'block';
            elementDiv.style.left = destLeftPos;
            elementDiv.style.top = destTopPos;
            GetElementObjectById("txtUserName").focus();
            loginPopupShown = true;
        }
        else
        {
            GetElementObjectById("divLoginPopup").style.display = 'none';
            loginPopupShown = false;
            innerElementDiv.innerHTML = '';
        }
    }
    return false;
}

///**********************************************************************************
/// <name>    CloseLoginPopUp </name>
/// <summary> Closes the Login Form popup.</summary>
///**********************************************************************************
function CloseLoginPopUp()
{
    if(loginPopupShown)
    {    
        var innerElementDiv = GetElementObjectById("divLoginInnerPopup");
        
        if(BrowserSupportsJQuery())
        {
            var elementDiv = GetElementObjectById("divLoginPopup");
            var elementPos = FindPosition(GetElementObjectById("divLoginLabel"))
            var elementPosX = elementPos[0] - siteBlockPosition[0]; // This position is relative to the site block
            var elementPosY = elementPos[1] - siteBlockPosition[1]; // This position is relative to the site block
            
            var initLeftPos = (elementPosX + 0) + "px";
            var initTopPos = (elementPosY + 15) + "px";
            var destLeftPos = (elementPosX - 187) + "px";
            var destTopPos = (elementPosY + 15) + "px";
            var closeTopPos =   (elementPosY + 15) + "px";  
                    
            $("#divLoginPopup").animate({width:"0px", height:"0px", left:elementPosX, top:closeTopPos},600, function() {innerElementDiv.innerHTML = '';});
            $("#divLoginPopup").hide(1);            
            loginPopupShown = false;
        }
        else
        {
            GetElementObjectById("divLoginPopup").style.display = 'none';
            loginPopupShown = false;
            innerElementDiv.innerHTML = '';
        }
    }
}

///**********************************************************************************
/// <name>    Login </name>
/// <summary> Logs in the user based on the given credentials. Once the user is
///           logged in, the menu is changed to show authenticated and authorized options.</summary>
///**********************************************************************************
function Login()
{
    var userName = $("#txtUserName").val();
    var password = $("#txtPassword").val();
    var postData = 'CallbackAction=Login&UserName=' + userName + '&Password=' + password;
    
    // Change the floorplan image (by fading-out previous and fading-in next)
    $("#divInnerLogin").fadeTo("slow", 0.0, function (){
        $.ajax({
           type: "POST",
           url: ResolveUrl("~/Login.aspx"),
           cache: false,
           data: postData,
           success: function(jsonResponse){
             var loginResponse = eval("(" + jsonResponse + ")");
             
             // If an error occurs while trying to login, display the error message
             if(loginResponse.ResponseCode > 0)
             {
                $("#divInnerLogin").fadeTo("slow", 0.0, function (){
                    GetElementObjectById("divInnerLogin").innerHTML = loginResponse.ResponseHtml;
                    setTimeout(function() {$("#divInnerLogin").fadeTo("slow", 1.0);}, 0);
                    }
                  );
             }
             else
             {
                // If the login is successful, then close the login pop-up and display the user information
                CloseLoginPopUp();
                             
                // Change the login Label
                $("#divLoginLabel").fadeTo("slow", 0.0, function (){
                    GetElementObjectById("divLoginLabel").innerHTML = loginResponse.ResponseHtml;
                    setTimeout(function() {$("#divLoginLabel").fadeTo("slow", 1.0);}, 0);
                    }
                  );
                  
                // Change the menu (based on the current credentials).
                $("#ctl00_divMenu").fadeTo("slow", 0.0, function (){
                    GetElementObjectById("ctl00_divMenu").innerHTML = loginResponse.MenuHtml;
                    ddaccordion.initHelper(menuConfiguration);
                    setTimeout(function() {$("#ctl00_divMenu").fadeTo("slow", 1.0)}, 100);
                    }
                  );                                   
             }
           }
         });

        // Show the Loading icon before the response comes back
        GetElementObjectById("divInnerLogin").innerHTML = '<div class="LoginValidation"><img src="' + ResolveUrl("~/Images/Global-Loading.gif") + '" alt="Validating" /><div style="margin-top: 5px;">Validating...</div>';
        setTimeout(function() {$("#divInnerLogin").fadeTo("slow", 1.0)}, 100);
    });

    return false;
}

///**********************************************************************************
/// <name>    Logout </name>
/// <summary> Logs out the current user, and resets the menu to the unauthenticated view.</summary>
///**********************************************************************************
function Logout()
{
    var postData = 'CallbackAction=Logout';
    
    // Sign the user out
    $.ajax({
       type: "POST",
       url: ResolveUrl("~/Login.aspx"),
       cache: false,
       data: postData,
       success: function(htmlResponse)
       {
            // Change the login Label to show the Login link
            $("#divLoginLabel").fadeTo("slow", 0.0, function (){
                GetElementObjectById("divLoginLabel").innerHTML = '<a onclick="OpenLoginPopUp(false); return false;" href="Login.aspx">Login</a><div id="divLoginPopup"><div style="text-align: right;" id="divLoginInnerPopup"><!-- Login - Popup Place Holder --></div></div>';
                LoginFormReset();
                setTimeout(function() {$("#divLoginLabel").fadeTo("slow", 1.0);}, 0);
                }
              );
              
           // Change the menu (based on the Anonymous status).
            $("#ctl00_divMenu").fadeTo("slow", 0.0, function (){
                GetElementObjectById("ctl00_divMenu").innerHTML = htmlResponse;
                ddaccordion.initHelper(menuConfiguration);
                setTimeout(
                    function() 
                    {
                        $("#ctl00_divMenu").fadeTo("slow", 1.0);                     
                    }, 0);
                }
              );          
        }
    });
}

///**********************************************************************************
/// <name>    LoginFormReset </name>
/// <summary> Resets the login form.</summary>
///**********************************************************************************
function LoginFormReset()
{
    // Change the floorplan image (by fading-out previous and fading-in next)
    $("#divInnerLogin").fadeTo("slow", 0.0, function (){
        GetElementObjectById("divInnerLogin").innerHTML = LOGIN_FORM_HTML;
        setTimeout(function() {$("#divInnerLogin").fadeTo("slow", 1.0);}, 0);
    });
    
    return false;
}

///**********************************************************************************
/// <name>    OpenBrandExperiencePopUp </name>
/// <summary> Opens the Popup for the Brand Experience Info.</summary>
///**********************************************************************************
function OpenBrandExperiencePopUp()
{
    // Calculate Site Block Position (if not calculated)
    CalculateSiteBlockPosition();

    var imgBrandExperienceInfo = GetElementObjectById("imgBrandExperienceInfo")
    var elementDiv = GetElementObjectById("divBrandExperiencePopup");
    var elementPosX = imgBrandExperienceInfo.offsetLeft;  // This position is relative to the parent relative block
    var elementPosY = imgBrandExperienceInfo.offsetTop;   // This position is relative to the parent relative block
           
    var initLeftPos = (elementPosX + 5) + "px";
    var initTopPos = (elementPosY - 30) + "px";
    var destLeftPos = (elementPosX + 5) + "px";
    var destTopPos = (elementPosY - 138) + "px";
    var closeTopPos =   (elementPosY - 30) + "px";
        
    if(BrowserSupportsJQuery())
    {
        if(!brandExperienceInfoShown)
        {
            elementDiv.innerHTML = '<div style="margin-bottom: 15px;"><em>The "i" symbol indicates projects which include a brand experience case study.</em></div><h3>What is Brand Experience?</h3><div>The strategic development of consistent messaging and design over a diverse range of media.</div>';
            $("#divBrandExperiencePopup").css({width:"0px", height:"0px", left:initLeftPos, top:initTopPos});
            $("#divBrandExperiencePopup").animate({width:"196px", height:"108px", left:destLeftPos, top:destTopPos},400);
            brandExperienceInfoShown = true;
        }
        else
        {
            $("#divBrandExperiencePopup").animate({width:"0px", height:"0px", left:destLeftPos, top:closeTopPos},600);
            $("#divBrandExperiencePopup").hide(1, function() {elementDiv.innerHTML = '';});
            brandExperienceInfoShown = false;
        }
    }
    else
    {
        if(!brandExperienceInfoShown)
        {
            elementDiv.innerHTML = '<div style="margin-bottom: 15px;"><em>The "i" symbol indicates projects which include a brand experience case study.</em></div><h3>What is Brand Experience?</h3><div>The strategic development of consistent messaging and design over a diverse range of media.</div>';
            elementDiv.style.display = 'block';
            elementDiv.style.left = destLeftPos;
            elementDiv.style.top = destTopPos;
            brandExperienceInfoShown = true;
        }
        else
        {
            elementDiv.style.display = 'none';
            elementDiv.innerHTML = '';
            brandExperienceInfoShown = false;
        }
    }
    
    return false;
}

///**********************************************************************************
/// <name>    CloseBrandExperiencePopUp </name>
/// <summary> Closes the Brand Experience Info popup.</summary>
///**********************************************************************************
function CloseBrandExperiencePopUp()
{        
    if(brandExperienceInfoShown)
    {        
        var elementDiv = GetElementObjectById("divBrandExperiencePopup");
        
        if(BrowserSupportsJQuery())
        {
            var imgBrandExperienceInfo = GetElementObjectById("imgBrandExperienceInfo")
            var elementPosX = imgBrandExperienceInfo.offsetLeft;  // This position is relative to the parent relative block
            var elementPosY = imgBrandExperienceInfo.offsetTop;   // This position is relative to the parent relative block
                   
            var initLeftPos = (elementPosX + 5) + "px";
            var initTopPos = (elementPosY - 30) + "px";
            var destLeftPos = (elementPosX + 5) + "px";
            var destTopPos = (elementPosY - 138) + "px";
            var closeTopPos =   (elementPosY - 30) + "px";        
        
            $("#divBrandExperiencePopup").animate({width:"0px", height:"0px", left:destLeftPos, top:closeTopPos},600);
            $("#divBrandExperiencePopup").hide(1, function() {elementDiv.innerHTML = '';});
            brandExperienceInfoShown = false;
        }
        else
        {
            elementDiv.style.display = 'none';
            elementDiv.innerHTML = '';
            brandExperienceInfoShown = false;
        }
    }
    
    return false;
}

///**********************************************************************************
/// <name>    OpenDirectionsPopUp </name>
/// <summary> Opens the Popup for the Directions Form.</summary>
///**********************************************************************************
function OpenDirectionsPopUp()
{
    // Calculate Site Block Position (if not calculated)
    CalculateSiteBlockPosition();
    
    var elementDiv = GetElementObjectById("divDirectionsPopup");
    var elementPos = FindPosition(GetElementObjectById("hrefDirections"))
    var elementPosX = elementPos[0] - siteBlockPosition[0]; // This position is relative to the site block
    var elementPosY = elementPos[1] - siteBlockPosition[1]; // This position is relative to the site block
    
    var initLeftPos = (elementPosX + 0) + "px";
    var initTopPos = (elementPosY + 15) + "px";
    var destLeftPos = (elementPosX + 0) + "px";
    var destTopPos = (elementPosY + 15) + "px";
    var closeTopPos =   (elementPosY + 15) + "px";    
    
    if(BrowserSupportsJQuery())
    {                   
        if(!directionsPopupShown)
        {
            elementDiv.innerHTML = '<div id="divDirectionsInnerPopup"><div style="float: left;"><label for="txtDirectionsFrom">From:</label></div><div style="float: left;"><input id="txtDirectionsFrom" onkeyup="javascript:GetDirections(true, event);" size="20" /><div style="margin-top: 5px;"><a onclick="javascript:GetDirections(false, event); return false;" href="http://maps.google.com/maps?f=d&amp;hl=en&amp;geocode=&amp;daddr=875+Battery+Street,+San+Francisco,+CA+94111" target="_blank"><img style="" src="Images/Global-GetDirectionsButton.gif" alt="Get Directions" /></a></div></div><div style="clear: both;" class="ClearFF"></div></div>';
            $("#divDirectionsPopup").css({width:"0px", height:"0px", left:initLeftPos, top:initTopPos});
            $("#divDirectionsPopup").animate({width:"238px", height:"72px", left:destLeftPos, top:destTopPos},400, function() {GetElementObjectById("txtDirectionsFrom").focus();});
            directionsPopupShown = true;
        }
        else
        {
            $("#divDirectionsPopup").animate({width:"0px", height:"0px", left:elementPosX, top:closeTopPos},600, function() {elementDiv.innerHTML = '';});
            $("#divDirectionsPopup").hide(1);
            directionsPopupShown = false;
        }
    }
    else
    {
        if(!directionsPopupShown)
        {
            elementDiv.innerHTML = '<div id="divDirectionsInnerPopup"><div style="float: left;"><label for="txtDirectionsFrom">From:</label></div><div style="float: left;"><input id="txtDirectionsFrom" onkeyup="javascript:GetDirections(true, event);" size="20" /><div style="margin-top: 5px;"><a onclick="javascript:GetDirections(false, event); return false;" href="http://maps.google.com/maps?f=d&amp;hl=en&amp;geocode=&amp;daddr=875+Battery+Street,+San+Francisco,+CA+94111" target="_blank"><img style="" src="Images/Global-GetDirectionsButton.gif" alt="Get Directions" /></a></div></div><div style="clear: both;" class="ClearFF"></div></div>';
            elementDiv.style.display = 'block';
            elementDiv.style.left = destLeftPos;
            elementDiv.style.top = destTopPos;
            GetElementObjectById("txtDirectionsFrom").focus();
            directionsPopupShown = true;
        }
        else
        {
            elementDiv.style.display = 'none';
            elementDiv.innerHTML = '';
            directionsPopupShown = false;
        }
    }
    return false;
}

///**********************************************************************************
/// <name>    CloseDirectionsPopUp </name>
/// <summary> Closes the Directions Form popup.</summary>
///**********************************************************************************
function CloseDirectionsopUp()
{
    if(directionsPopupShown)
    {    
        var elementDiv = GetElementObjectById("divDirectionsPopup");
        
        if(BrowserSupportsJQuery())
        {
            var elementPos = FindPosition(GetElementObjectById("hrefDirections"))
            var elementPosX = elementPos[0] - siteBlockPosition[0]; // This position is relative to the site block
            var elementPosY = elementPos[1] - siteBlockPosition[1]; // This position is relative to the site block

            var initLeftPos = (elementPosX + 0) + "px";
            var initTopPos = (elementPosY + 15) + "px";
            var destLeftPos = (elementPosX + 0) + "px";
            var destTopPos = (elementPosY + 15) + "px";
            var closeTopPos =   (elementPosY + 15) + "px";
                    
            $("#divDirectionsPopup").animate({width:"0px", height:"0px", left:elementPosX, top:closeTopPos},600, function() {elementDiv.innerHTML = '';});
            $("#divDirectionsPopup").hide(1);       
            directionsPopupShown = false;
        }
        else
        {
            GetElementObjectById("divDirectionsPopup").style.display = 'none';
            elementDiv.innerHTML = '';
            directionsPopupShown = false;
        }
    }
}

///**********************************************************************************
/// <name>    ToggleExpandableNewsArea </name>
/// <summary> Performs the toggle expand/collapse of the expandable area. Upon an expand,
///           the Read More link is hidden; upon a collapse the Read More link is shown.</summary>
///**********************************************************************************
function ToggleExpandableNewsArea(itemNumber, expandableAreaId, readMoreLinkId)
{
    // If the Browser supports jQuery
    if(BrowserSupportsJQuery())
    {
        $("#" + expandableAreaId).slideToggle("slow");
        
        if(GetElementObjectById(expandableAreaId).style.height == '1px')
        {
            $("#" + readMoreLinkId).fadeTo("slow", 0.0, function() { $("#" + readMoreLinkId).hide();}); 
        }
        else
        {
            $("#" + readMoreLinkId).fadeTo("slow", 1.0, function() { $("#" + readMoreLinkId).show();});
        }
    }
    else
    {
        var elementExpandableArea = GetElementObjectById(expandableAreaId);
        var elementReadMoreLink = GetElementObjectById(readMoreLinkId);
        
        if(elementExpandableArea.style.display == null || elementExpandableArea.style.display == '' || elementExpandableArea.style.display.toLowerCase() == 'none')
        {
            elementExpandableArea.style.display = 'block';
            elementReadMoreLink.style.display = 'none';
        }
        else
        {
            elementExpandableArea.style.display = 'none';
            elementReadMoreLink.style.display = 'block';
        }
    }
}

///**********************************************************************************
/// <name>    GetDirections </name>
/// <summary> Opens Google Maps with the directions to HDSF Office, from the
///           specified location.</summary>
///**********************************************************************************
function GetDirections(isKeyPress, event) 
{
    var showDirections = false;
    
    if(isKeyPress)
    {
        var pressedKey;
        
        if (window.Event == null) 
        {   // ie
            pressedKey = event.which;
        } 
        else  // mozilla
        { 
            pressedKey = event.keyCode;
        }
     
        // When 'Enter' is pressed from the textbox, show the directions.
        if (pressedKey == 13) 
        {
            showDirections = true;  // Enter
        }
    }
    else
        showDirections = true;
    
    if(showDirections)
    {
        var directionsFrom = GetElementObjectById("txtDirectionsFrom").value;
        var directionsTo = '&daddr=875+Battery+Street,+San+Francisco,+CA+94111';   
        
        // Open the directions to HDSF in a new window
        OpenNewWindow('http://maps.google.com/maps?f=d&hl=en&geocode=&saddr=' + directionsFrom + directionsTo, null, null);
        CloseDirectionsopUp();
    }
}

///**********************************************************************************
/// <name>    OpenNewWindow </name>
/// <summary> Opens a new window with the specified parameters.</summary>
///**********************************************************************************
function OpenNewWindow(url, width, height) 
{
    OpenNewWindow(url, width, height, false);
}

///**********************************************************************************
/// <name>    OpenNewWindow </name>
/// <summary> Opens a new window with the specified parameters.</summary>
///**********************************************************************************
function OpenNewWindow(url, width, height, scrollbars) 
{
    if(width != null && width > 0 && height != null && height > 0)
    {
        if(scrollbars)
            window.open(url,'','height=' + height + ',width=' + width + ',scrollbars=yes,status=no,menubar=no,toolbar=no,location=no');
        else
            window.open(url,'','height=' + height + ',width=' + width + ',status=no,menubar=no,toolbar=no,location=no');
    }
    else
        window.open(url,'','');      
}

///**********************************************************************************
/// <name>    ClosePopUp </name>
/// <summary> Closes the Modal (pop-up).</summary>
///**********************************************************************************
function ClosePopUp()
{
    // Close the Modal
    tb_remove();
}

///**********************************************************************************
/// <name>    SwitchImage </name>
/// <summary> Switches the image for a given object.</summary>
///**********************************************************************************
function SwitchImage(img, imagePath)
{
    img.src = imagePath;
}

///**********************************************************************************
/// <name>    ChangePOV </name>
/// <summary> Changes the Point of View image on request (i.e. by image click).</summary>
///**********************************************************************************
function ChangePOV(povType, divPOVId, imgId, imgNumber)
{
    ChangePOV(povType, divPOVId, imgId, imgNumber, false);
}

///**********************************************************************************
/// <name>    ChangePortfolioIdentity </name>
/// <summary> Changes the Portfolio Identity for a given project.</summary>
///**********************************************************************************
function ChangePOV(povType, divPOVId, imgId, imgNumber, isInitialLoad)
{   
    var projectSetData = null;
    var projectTotalCount = 0;
    var isFlash = false;
    var isBrandExperience = false;
    
    // Close any open pop-ups
    CloseHDWhatPopUp();
    CloseBrandExperiencePopUp();
        
    switch(povType.toLowerCase())
    {
        case 'brandexperience':
            projectSetData = projectData.brandExperience[imgNumber];
            projectData.selectedImagePosition.brandExperience = imgNumber;
            projectTotalCount = projectData.brandExperience.length;
            isBrandExperience = true;
            break;
        case 'identity':
            projectSetData = projectData.identity[imgNumber];
            projectData.selectedImagePosition.identity = imgNumber;
            projectTotalCount = projectData.identity.length;
            break;
        case 'print':
            projectSetData = projectData.print[imgNumber];
            projectData.selectedImagePosition.print = imgNumber;
            projectTotalCount = projectData.print.length;
            break;
        case 'interactive':
            projectSetData = projectData.interactive[imgNumber];
            projectData.selectedImagePosition.interactive = imgNumber;
            projectTotalCount = projectData.interactive.length;
            break;             
        case 'environments':
            projectSetData = projectData.environments[imgNumber];
            projectData.selectedImagePosition.environments = imgNumber;
            projectTotalCount = projectData.environments.length;
            break;
        case 'advertisement':
            projectSetData = projectData.advertisement[imgNumber];
            projectData.selectedImagePosition.advertisement = imgNumber;
            projectTotalCount = projectData.advertisement.length;
            break;
        case 'packaging':
            projectSetData = projectData.packaging[imgNumber];
            projectData.selectedImagePosition.packaging = imgNumber;
            projectTotalCount = projectData.packaging.length;
            break;            
    }
    
    // Check if this item contains a Flash POV
    if(projectSetData.flashPath != null)
    {
        isFlash = true;
        EmbedFlashMovie("divPOVBlock", projectSetData.flashPath, projectSetData.imagePath, projectSetData.flashWidth, projectSetData.flashHeight, projectSetData.pageTitle);
    }
    else
    {
        var imgPOV = GetElementObjectById(imgId);
        
        if (!BrowserSupportsJQuery())
        {
            // If the Image POV area is not found (i.e. due to the fact that it may have been removed by a Flash embedded file)
            // then re-insert it in the POV Block.
            if(imgPOV == null)
            {
                GetElementObjectById("divPOVBlock").innerHTML = '<img id="' + imgId + '" src="' + projectSetData.imagePath + '" alt="' + projectSetData.altText + '" />'
            }
            else
            {
                imgPOV.src = projectSetData.imagePath;
                imgPOV.alt = projectSetData.altText;
            }
        }
        else
        {
            // If the Image POV area is not found (i.e. due to the fact that it may have been removed by a Flash embedded file)
            // then re-insert it in the POV Block.
            if(imgPOV == null)
            {
                GetElementObjectById("divPOVBlock").innerHTML = '<img id="' + imgId + '" src="Images/Global-Spacer.gif" alt="" />'            
                imgPOV = GetElementObjectById(imgId);
            }
            
            if(isInitialLoad)
            {
                // Fade-in the content
                $("#" + imgId).attr('src', projectSetData.imagePath);
                $("#" + imgId).attr('alt', projectSetData.altText);
                setTimeout(function() {$("#imgProjectPOV").fadeIn(1500);}, 0);
            }
            else
            {
                // Change the floorplan image (by fading-out previous and fading-in next)
                $("#imgProjectPOV").fadeTo("slow", 0.0, function (){
                    $("#" + imgId).attr('src', projectSetData.imagePath);
                    $("#" + imgId).attr('alt', projectSetData.altText);
                    setTimeout(function() {$("#imgProjectPOV").fadeTo("slow", 1.0);}, 0);
                });
            }
        }
    }
    
    // If the style has been defined for the POV, then add it.
    if(projectSetData.povStyle != null && projectSetData.povStyle != '')
    {
        GetElementObjectById(divPOVId).setAttribute("style", projectSetData.povStyle.toString());
    }
    else
    {
        GetElementObjectById(divPOVId).setAttribute("style", "");
    }
    
    // If there is a website defined, change the link
    if(projectSetData.website != null)
    {
        var divProjectActionLink = GetElementObjectById("hrefProjectActionLink");
        if(projectSetData.website != '')
        {
            divProjectActionLink.style.display = 'block'; 
            divProjectActionLink.href = projectSetData.website;
            divProjectActionLink.setAttribute("title", "Launch website: " + projectSetData.headerText);
            divProjectActionLink.getElementsByTagName("img").item(0).setAttribute("alt", "Launch website: " + projectSetData.headerText);;
        }
        else
        {
            divProjectActionLink.style.display = 'none'; 
        }
         
    }
    
    // If a Project Description is Added, change the description section
    if(projectSetData.headerText != null)
    {
        var headerText = projectSetData.headerText;
        
        // If the current section is Brand Experience, then add the "Case Study" title prefix
        if(isBrandExperience)
        {
            headerText = '<span class="CaseStudyLabel">Case Study:</span> ' + headerText;
        }
        
        // If Brand Experience is available, then add the information icon
        if(projectSetData.brandExperienceId != null)
            headerText += '&nbsp;&nbsp;<a href="#BrandExperience" onclick="OpenBrandExperiencePopUp(); return false;"><img id="imgBrandExperienceInfo" src="Images/Global-BrandExperienceInfo.gif" style="z-index: 1000; position: relative;" alt="What is Brand Experience?" /></a><span id="divBrandExperiencePopup" style="z-index: 99; display: none;"></span>';
        
        GetElementObjectById("h2ProjectTitle").innerHTML  = headerText;
        GetElementObjectById("divProjectBrief").innerHTML  = projectSetData.projectBrief;
    }
    
    // If a Project Relations are added, change the relation section
    if(projectSetData.relationLinks != null)
    {
        GetElementObjectById("divRelationLinks").innerHTML  = projectSetData.relationLinks;
    }
    else
    {
        GetElementObjectById("divRelationLinks").innerHTML  = '';
    }

    // If a ADs section is present, then add the adds section.
    
    if(projectSetData.ads != null)
    {
        var projectPopupActions = "";
        var i = 0;

        for(i = 0; i < projectSetData.ads.length; i++)
        {
            if(i == 0)
            {
                projectPopupActions += '<a href="' + projectSetData.ads[i].imagePath + '" rel="lytebox[' + projectSetData.ads[i].groupName + ']" title="' + projectSetData.ads[i].altText + '"><img src="Images/Global-Enlarge.gif" alt="Enlarge - ' + projectSetData.ads[i].altText + '" style="padding-top: 1px;" /></a>';
            }
            else
            {
                projectPopupActions += '<a href="' + projectSetData.ads[i].imagePath + '" rel="lytebox[' + projectSetData.ads[i].groupName + ']" title="' + projectSetData.ads[i].altText + '" style="display: none;">&nbsp;</a>';
            }
        }      
        
        GetElementObjectById("divProjectActionLink").innerHTML  = projectPopupActions;
        initLytebox();
    }
          
    // Show the currently selected project number (i.e. 1 / 9)
    GetElementObjectById("spanProjectStatusNumber").innerHTML = (imgNumber + 1) + " / " + projectTotalCount;

    if (!isFlash)
        $("#" + imgId).attr('alt', projectSetData.altText);
        //imgPOV.alt = projectSetData.altText;
    
    // If the browser doesn't support jQuery, then just change the hash, otherwise animate the scroll to the top
    if (!BrowserSupportsJQuery())
    {
        window.location.hash = "Project" + (imgNumber + 1).toString();
    }
    else
    {
        // Change the hash so that Project can be bookmarked and restored properly (by javascript)
        $.scrollTo( 0, 800, {onAfter:function(){window.location.hash = "Project" + (imgNumber + 1).toString();}} );
    }

    // Set the page title and the alt text    
    document.title = projectSetData.pageTitle;
}

///**********************************************************************************
/// <name>    EmbedFlashMovie </name>
/// <summary> Embeds a Flash Movie in the POV area.</summary>
///**********************************************************************************
function EmbedFlashMovie(elementId, flassMoviePath, alternateImagePath, flashWidth, flashHeight, pageTitle)
{
    var movieBlock = GetElementObjectById(elementId);
    var flashInteractivePOV = GetElementObjectById("flashInteractivePOV")
    
    if(BrowserSupportsJQuery())
    {
        $("#" + elementId).fadeTo("slow", 0.0, function() {
            // If the flash interactive POV does not exists, create it (this will happen when there is a mix of Images and SWFs in a given grid)
            if (flashInteractivePOV == null) {
                movieBlock.innerHTML = '<object id="flashInteractivePOV" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + flashWidth + '" height="' + flashHeight + '"><param name="movie" value="Images/Flash/Global-HDPronounciation.swf" /><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><!--[if !IE]>--><object type="application/x-shockwave-flash" data="' + flassMoviePath + '" width="' + flashWidth + '" height="' + flashHeight + '"><!--<![endif]--><img id="imgFlashAlternate" src="' + alternateImagePath + '" alt="" longdesc="" /><!--[if !IE]>--></object><!--<![endif]--></object>';
            }

            var alternateImage = GetElementObjectById("imgFlashAlternate")

            // Change the path of the alternate image
            if (alternateImage != null)
                alternateImage.src = alternateImagePath;

            var flPOVFlashvars = {};
            var flPOVParams = {
                bgcolor: "#ffffff",
                wmode: "transparent",
                quality: "high",
                allowfullscreen: "false"
            };
            var flPOVAttributes = {};
            swfobject.embedSWF(flassMoviePath, "flashInteractivePOV", flashWidth, flashHeight, "8.0.0", "Images/Flash/Flash-ExpressInstall.swf", flPOVFlashvars, flPOVParams, flPOVAttributes);
            setTimeout(function() { $("#" + elementId).fadeTo("slow", 1.0,  function() { document.title = pageTitle; }); }, 0);
        });
        
    }
    else
    {
        // If the flash interactive POV does not exists, create it (this will happen when there is a mix of Images and SWFs in a given grid)
        if(flashInteractivePOV == null)
        {
            movieBlock.innerHTML = '<object id="flashInteractivePOV" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + flashWidth + '" height="' + flashHeight + '"><param name="movie" value="Images/Flash/Global-HDPronounciation.swf" /><param name="wmode" value="transparent" /><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><!--[if !IE]>--><object type="application/x-shockwave-flash" data="' + flassMoviePath + '" width="' + flashWidth + '" height="' + flashHeight + '"><!--<![endif]--><img id="imgFlashAlternate" src="' + alternateImagePath + '" alt="" longdesc="" /><!--[if !IE]>--></object><!--<![endif]--></object>';
        }    
        
        var alternateImage = GetElementObjectById("imgFlashAlternate")
        
        // Change the path of the alternate image
        if(alternateImage != null)
            alternateImage.src = alternateImagePath;
        
        var flPOVFlashvars = {};
        var flPOVParams = {
            bgcolor: "#ffffff",
            wmode: "transparent",
            quality: "high",
            allowfullscreen: "false"
        };
        var flPOVAttributes = {};
        swfobject.embedSWF(flassMoviePath, "flashInteractivePOV", flashWidth, flashHeight, "8.0.0","Images/Flash/Flash-ExpressInstall.swf", flPOVFlashvars, flPOVParams, flPOVAttributes);
    }
}

///**********************************************************************************
/// <name>    MoveToPreviousPOV </name>
/// <summary> Changes the Project Environment to the next image.</summary>
///**********************************************************************************
function MoveToPreviousPOV(povType, divPOVId, imgId)
{
    var projectSetData = null;
    var currentImagePosition = 0;
    var previousImageNumber = 0;
    
    switch(povType.toLowerCase())
    {
        case 'brandexperience':
            projectSetData = projectData.brandExperience;
            currentImagePosition = projectData.selectedImagePosition.brandExperience;
            break;
        case 'identity':
            projectSetData = projectData.identity;
            currentImagePosition = projectData.selectedImagePosition.identity;
            break;
        case 'print':
            projectSetData = projectData.print;
            currentImagePosition = projectData.selectedImagePosition.print;
            break;            
        case 'interactive':
            projectSetData = projectData.interactive;
            currentImagePosition = projectData.selectedImagePosition.interactive;
            break;            
        case 'environments':
            projectSetData = projectData.environments;
            currentImagePosition = projectData.selectedImagePosition.environments;
            break;
        case 'advertisement':
            projectSetData = projectData.advertisement;
            currentImagePosition = projectData.selectedImagePosition.advertisement;
            break;
        case 'packaging':
            projectSetData = projectData.packaging;
            currentImagePosition = projectData.selectedImagePosition.packaging;
            break;
    }

    if(currentImagePosition == 0)
    {
        previousImageNumber = (projectSetData.length - 1);
    }
    else
    {
        previousImageNumber = (currentImagePosition - 1);
    }

    ChangePOV(povType, divPOVId, imgId, previousImageNumber);
}

///**********************************************************************************
/// <name>    MoveToNextPOV </name>
/// <summary> Changes the Project Environment to the next image.</summary>
///**********************************************************************************
function MoveToNextPOV(povType, divPOVId, imgId)
{
    var projectSetData = null;
    var currentImagePosition = 0;
    var nextImageNumber = 0;
    
    switch(povType.toLowerCase())
    {
        case 'brandexperience':
            projectSetData = projectData.brandExperience;
            currentImagePosition = projectData.selectedImagePosition.brandExperience;
            break;    
        case 'identity':
            projectSetData = projectData.identity;
            currentImagePosition = projectData.selectedImagePosition.identity;
            break;
        case 'print':
            projectSetData = projectData.print;
            currentImagePosition = projectData.selectedImagePosition.print;
            break;       
        case 'interactive':
            projectSetData = projectData.interactive;
            currentImagePosition = projectData.selectedImagePosition.interactive;
            break;            
        case 'environments':
            projectSetData = projectData.environments;
            currentImagePosition = projectData.selectedImagePosition.environments;
            break;
       case 'advertisement':
            projectSetData = projectData.advertisement;
            currentImagePosition = projectData.selectedImagePosition.advertisement;
            break;
        case 'packaging':
            projectSetData = projectData.packaging;
            currentImagePosition = projectData.selectedImagePosition.packaging;
            break;        
    }
    
    if(projectSetData.length == (currentImagePosition + 1))
    {
        nextImageNumber = 0;
    }
    else
    {
        nextImageNumber = (currentImagePosition + 1);
    }
    
    ChangePOV(povType, divPOVId, imgId, nextImageNumber);
}

///**********************************************************************************
/// <name>    FindPosition </name>
/// <summary> Finds the position (returns an [x,y] array) of the given element.</summary>
///**********************************************************************************
function FindPosition(element) 
{
	var curLeft = curTop = 0;
	
	if (element.offsetParent) 
	{
	    do {
		    curLeft += element.offsetLeft;
		    curTop += element.offsetTop;
        } while (element = element.offsetParent);
    }
    return [curLeft, curTop];
}

///**********************************************************************************
/// <name>    ResolveUrl </name>
/// <summary> Resolves the URL based the application path (i.e. ~/Default.aspx).</summary>
///**********************************************************************************
function ResolveUrl(url) 
{
    if (url.indexOf("~/") == 0) {
        url = baseUrl + url.substring(2);
    }
    return url;
}

///**********************************************************************************
/// <name>    UseGoogleAnalytics </name>
/// <summary> Based on the current host, it determines whether to log statistics.
///           This is to ignore staging environments.</summary>
///**********************************************************************************
function UseGoogleAnalytics()
{
    return document.location.hostname.toLowerCase() == 'www.hdsf.com';
}

///**********************************************************************************
/// <name>    BrowserSupportsModals </name>
/// <summary> Determines whether the broswer can support the imitated modal overlays.
///           if the browser does not support modals, then a regular pop-up will be
///           open.</summary>
///**********************************************************************************
function BrowserSupportsModals()
{
    try
    {
        if(BrowserDetect.browser == "Explorer" && BrowserDetect.majorVersion < 6)
            return false;
        else if(BrowserDetect.browser == "Firefox" && BrowserDetect.majorVersion < 1)
            return false; 
        else if(BrowserDetect.browser == "Netscape" && BrowserDetect.majorVersion < 6)
            return false;
        else if(BrowserDetect.browser == "Mozilla" && BrowserDetect.majorVersion < 2)
            return false;        
        else if(BrowserDetect.browser == "Safari" && BrowserDetect.majorVersion < 3)
            return false;
        else if(BrowserDetect.browser == "Opera" && BrowserDetect.majorVersion < 8)
            return false;                               
        else
        {
            // For anything else, return true by default.
            return true;
        }
    }
    catch(e)
    {
        // return false when error occurs
        return false;
    }
}

///**********************************************************************************
/// <name>    BrowserSupportsJQuery </name>
/// <summary> Determines whether the broswer can support the JQuery functionality.
///           if the browser does not support JQuery, then features such as animtaion
///           will not be initiated.</summary>
///**********************************************************************************
function BrowserSupportsJQuery()
{
    try
    {
        if(BrowserDetect.browser == "Explorer" && BrowserDetect.majorVersion < 6)
            return false;
        else if(BrowserDetect.browser == "Firefox" && BrowserDetect.majorVersion < 1)
            return false; 
        else if(BrowserDetect.browser == "Netscape" && BrowserDetect.majorVersion < 6)
            return false;
        else if(BrowserDetect.browser == "Mozilla" && BrowserDetect.majorVersion < 2)
            return false;        
        else if(BrowserDetect.browser == "Safari" && BrowserDetect.majorVersion < 3)
            return false;
        else if(BrowserDetect.browser == "Opera" && BrowserDetect.majorVersion < 8)
            return false;                               
        else
        {
            // For anything else, return true by default.
            return true;
        }
    }
    catch(e)
    {
        // return false when error occurs
        return false;
    }
}

///**********************************************************************************
/// <name>    GetElementObject </name>
/// <summary> Gets an element object based on the given ID (depending on the browser).</summary>
///**********************************************************************************
function GetElementObjectById(elementName)
{
    var elementObject;
    
	if (ns4) 
	{
		elementObject = GetObjNN4(document, elementName);
	} 
	else 
	{
		if(document.getElementById) 
		{
			elementObject = document.getElementById(elementName);
		} 
		else if (document.all)
		{
			elementObject = document.all[elementName];
		}
    }
    return elementObject;
}

///**********************************************************************************
/// <name>    GetElementHeight </name>
/// <summary> Gets the given element's height.</summary>
///**********************************************************************************
function GetElementHeight(element) 
{
	if (ns4) 
	{
		return element.clip.height;
	} 
	else 
	{
	    var elementHeight = 0;
	    
		if (op5) 
		{ 
			elementHeight = element.style.pixelHeight;
		} 
		else 
		{
			elementHeight = element.offsetHeight;
		}
		
		return elementHeight;
	} 
}

///**********************************************************************************
/// <name>    GetElementWidth </name>
/// <summary> Gets the given element's width.</summary>
///**********************************************************************************
function GetElementWidth(element) 
{
	if (ns4) 
	{
		return element.clip.width;
	} 
	else 
	{
        var elementWidth = 0;
        
        if (op5) 
        {
	        elementWidth = element.style.pixelWidth;
        } 
        else 
        {
	        elementWidth = element.offsetWidth;
        }

        return elementWidth;
	}
}

///**********************************************************************************
/// <name>    GetObjNN4 </name>
/// <summary> Gets the element for Netscape 4.</summary>
///**********************************************************************************
function GetObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

///**********************************************************************************
/// <name>    Browser Detection </name>
/// <summary> Detects which browser the user is using.</summary>
/// <credit>  http://www.quirksmode.org/js/detect.html</credit>
///**********************************************************************************
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.majorVersion = (this.version.toString()).split(".")[0];
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		
		var extractedVersion = dataString.substring(index+this.versionSearchString.length+1);
		
		try 
		{
		    var cleansedVersion = extractedVersion.match(/^\d*(\.\d+)?/)[0];		    
		    return parseFloat(cleansedVersion);
        }
		catch(e) {return parseFloat(extractedVersion);}
		
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{ 	string: navigator.userAgent,
			subString: "Chrome",
			versionSearch: "Chrome",
			identity: "Chrome"
		},		
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

BrowserDetect.init()

var ie = document.all;
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var op5 = BrowserDetect.browser == "Opera" && BrowserDetect.majorVersion == 5;