var jsReady = false;

function isReady() {
    return jsReady;
}

$(document).ready(function() {
    //boolean to tell flash that javascript is loaded
    jsReady = true;

    //overlay the search bar for jquery pop-ups
    OverlayNavBarsOnPage();

    //float the search div right
    $('#p-header-search').css({ 'float': 'right' });
    /* 04/14/10 : Get full-path of page being loaded.  Images are stored
    in a variable locations for each flash carousel but they are all the same.
    This allows us to remove the reference to the css file in each template and place the file in the
    Css folder on the server. TeamSite needs images stored in the same location as .wpd when using a
    carousel. */
    var initLocation = document.location;
    var s = new String(initLocation);
    var strCount = s.lastIndexOf('/');
    var folderPath = s.substring(0, strCount) + "/";

    $('#fancy_title_main').css('background-image', 'url(' + folderPath + 'fancy_title_main.png)');
    $('#fancy_title_left').css('background-image', 'url(' + folderPath + 'fancy_title_left.png)');
    $('#fancy_title_right').css('background-image', 'url(' + folderPath + 'fancy_title_right.png)');
    $('#fancy_close').css('background-image', 'url(' + folderPath + 'fancy_closebox.png)');
});


function createFancyBoxLink(_src, _id, _title) {
    //no title attribute passed
    if (_title) {
        //had to use jQuery because document.write refreshed a blank page
        $('body').append("<a style='display:none; visibility:hidden' id='html" + _id + "' title='" + _title + "' class='iframe' href='" + _src + "'></a>");
    } else {
        $('body').append("<a style='display:none; visibility:hidden' id='html" + _id + "' class='iframe' href='" + _src + "'></a>");
    }
}

function receiveComplexDataTypes(o) {
    //no title attribute passed
    if (o.title != '') {
        //had to use jQuery because document.write refreshed a blank page
        $('body').append("<a style='display:none; visibility:hidden' id='html" + o.id + "' title='" + o.title + "' class='iframe' href='" + o.src + "'></a>");
    } else {
        $('body').append("<a style='display:none; visibility:hidden' id='html" + o.id + "' class='iframe' href='" + o.src + "'></a>");
    }
    return "successful";
}



function viewBox(link, doc_width, doc_height) {
    //if IE
    if ($.browser.msie) {
        doc_width = doc_width + 1;          /*38 change to 1 No need to re-size for IE : Treb 3/29/10 */
        doc_height = doc_height + 4;  /* 75 Change to 4.  Previous value left to much space on right : Treb 3/29/10*/
    }
    //latest version of fancybox changed the attribute names from frameHeight to height and frameWidth to width
    //$("a#html"+ String(link)).fancybox({'width': doc_width,'height': doc_height, 'overlayOpacity': 0, 'enableEscapeButton': true, 'centerOnScroll': false }).trigger('click');
    $('a#html' + String(link)).fancybox({ 'frameWidth': doc_width, 'frameHeight': doc_height, 'overlayOpacity': 0, 'enableEscapeButton': true, 'centerOnScroll': false }).trigger('click');
}

/*
SET CURRENT PAGE
below is the javascript functions for changing the current image in the gallery when using the back and next button.

requirements:

The <object> tag:
- the Flash movie must have an id.  For example, id="aMediaGallery"
The <embed> tag:
- the Flash movie must have a name.  For example name="aMediaGallery"
- the <embed> tag must include swliveconnect="true" attribute, to turn-on the ability to "connect" with the scripting language (JavaScript).

usage:
set parent page's flash gallery to passed number
<script language="Javascript">
<!--
//try to send variable to parent.flash
try {parent.setCurrentPage(21);}catch(err){ };
//-->
</script>
*/

//sets the aMediaGallery image to current fancybox page.
function setCurrentPage(newPage) {
    //send page number to flash
    SendDataToFlashMovie(newPage);
}

//returns flash object
function getFlashMovieObject(movieName) {
    //if current page is a flash object
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    //if browser not IE
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movieName]) {
            return document.embeds[movieName];
        }
    } else {
        return document.getElementById(movieName);
    }
}

//send data to flash
function SendDataToFlashMovie(newPage) {
    //variable of flash object
    var flashMovie = getFlashMovieObject("aMediaGallery");
    //try to send variable to flash object
    try {
        flashMovie.sendTextToFlash(newPage);
    } catch (err) {
        //error handler
    };
}
