/**
 * Function loader
 * @param function (func) function to load
 * @return mixed
 */
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    }
    else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}


/**
 * Check flash version
 * @return mixed
 */
function checkFlash(file) {
    // Major version of Flash required
    var requiredMajorVersion = 9;
    // Minor version of Flash required
    var requiredMinorVersion = 0;
    // Minor version of Flash required
    var requiredRevision = 28;

    // Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
    var hasProductInstall = DetectFlashVer(6, 0, 65);

    // Version check based upon the values defined in globals
    var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);


    var content;

    if ( hasProductInstall && !hasRequestedVersion ) {
        // DO NOT MODIFY THE FOLLOWING FOUR LINES
        // Location visited after installation is complete if installation is required
        var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
        var MMredirectURL = window.location;
        document.title = document.title.slice(0, 47) + " - Flash Player Installation";
        var MMdoctitle = document.title;

        content = AC_FL_RunContent(
            "src", "/js/fouroverplayer/playerProductInstall",
            "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
            "width", "660",
            "height", "530",
            "align", "middle",
            "id", "FourOverPlayer",
            "quality", "high",
            "name", "FourOverPlayer",
            "allowScriptAccess","sameDomain",
            "type", "application/x-shockwave-flash",
            "pluginspage", "http://www.adobe.com/go/getflashplayer"
        );
    } else if (hasRequestedVersion) {
        // if we've detected an acceptable version
        // embed the Flash Content SWF when all tests are passed
        content = AC_FL_RunContent(
                "src", "/js/fouroverplayer/FourOverPlayer",
                "width", "660",
                "height", "530",
                "align", "middle",
                "id", "FourOverPlayer",
                "quality", "high",
                "name", "FourOverPlayer",
                "allowScriptAccess","sameDomain",
                "FlashVars","play=" + file + ".flv",
                "type", "application/x-shockwave-flash",
                "pluginspage", "http://www.adobe.com/go/getflashplayer"
        );
    } else {  // flash is too old or we can't detect the plugin
        var alternateContent = 'Alternate HTML content should be placed here. '
        + 'This content requires the Adobe Flash Player. '
        + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
        content = alternateContent;  // insert non-flash content
    }

    return content;
}
function checkFlashAudio(file) {
    // Major version of Flash required
    var requiredMajorVersion = 9;
    // Minor version of Flash required
    var requiredMinorVersion = 0;
    // Minor version of Flash required
    var requiredRevision = 28;

    // Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
    var hasProductInstall = DetectFlashVer(6, 0, 65);

    // Version check based upon the values defined in globals
    var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);


    var content;

    if ( hasProductInstall && !hasRequestedVersion ) {
        // DO NOT MODIFY THE FOLLOWING FOUR LINES
        // Location visited after installation is complete if installation is required
        var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
        var MMredirectURL = window.location;
        document.title = document.title.slice(0, 47) + " - Flash Player Installation";
        var MMdoctitle = document.title;

        content = AC_FL_RunContent(
            "src", "/js/fouroverplayer/playerProductInstall",
            "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
            "width", "660",
            "height", "530",
            "align", "middle",
            "id", "FourOverPlayer",
            "quality", "high",
            "name", "FourOverPlayer",
            "allowScriptAccess","sameDomain",
            "type", "application/x-shockwave-flash",
            "pluginspage", "http://www.adobe.com/go/getflashplayer"
        );
    } else if (hasRequestedVersion) {
        // if we've detected an acceptable version
        // embed the Flash Content SWF when all tests are passed
        content = AC_FL_RunContent(
                "src", "/js/fouroverplayer/FourOverAudio",
                "width", "660",
                "height", "630",
                "align", "middle",
                "id", "FourOverPlayer",
                "quality", "high",
                "name", "FourOverPlayer",
                "allowScriptAccess","sameDomain",
                "FlashVars","play=" + file + ".mp3",
                "type", "application/x-shockwave-flash",
                "pluginspage", "http://www.adobe.com/go/getflashplayer"
        );
    } else {  // flash is too old or we can't detect the plugin
        var alternateContent = 'Alternate HTML content should be placed here. '
        + 'This content requires the Adobe Flash Player. '
        + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
        content = alternateContent;  // insert non-flash content
    }

    return content;
}

/**
 * Initiatialize Fisheye Captions
 * @return mixed
 */
function initFishEye() {
    if (!document.getElementById) return;
    if (!document.getElementById("fisheye_menu")) return;

    var fishEyeMenu = document.getElementById("fisheye_menu");

    if (isMSIE6 == false) {
        var anchors = fishEyeMenu.getElementsByTagName("a");
        var imgs = fishEyeMenu.getElementsByTagName('img');
        for (var i=0; i<anchors.length; i++) {
            anchors[i].onmouseover = function() {
                var img = this.getElementsByTagName('img');
                var span = this.getElementsByTagName('span');
                new Effect.Morph(img[0], {
                  style: {
                      margin: '-8px',
                      height: '50px',
                      width: '50px'
                  },
                  duration: 0.1
                });
                //span[0].style.display = 'block';
            }
            anchors[i].onmouseout = function() {
                var img = this.getElementsByTagName('img');
                var span = this.getElementsByTagName('span');
                new Effect.Morph(img[0], {
                  style: {
                      margin: '0px',
                      height: '30px',
                      width: '30px'
                  },
                  duration: 0.1
                });
                //span[0].style.display = 'none';
            }
        }

        fishEyeMenu.onmouseout = function() {
            var imgs_reset = fishEyeMenu.getElementsByTagName('img');
            for (var i=0; i<imgs_reset.length; i++) {
                imgs_reset[i].style.margin = '0px';
                imgs_reset[i].style.height = '30px';
                imgs_reset[i].style.width = '30px';
            }
        }
    }
    else {
        var anchors = fishEyeMenu.getElementsByTagName("a");
        fishEyeMenu.style.marginLeft = '-25px';
        for (var i=0; i<anchors.length; i++) {
            var imgsIE = anchors[i].getElementsByTagName('img');
            var idA = anchors[i].getAttribute('id');
            var idAAr = idA.split('_');
            imgsIE[0].src = '/images/icons/ie/' + idAAr[1] + '_sm.gif';
            imgsIE[0].style.width = '46px';
            imgsIE[0].style.height = '46px';
/*
            anchors[i].onmouseover = function() {
                var imgsIE = this.getElementsByTagName('img');

                var idA = this.getAttribute('id');
                var idAAr = idA.split('_');
                imgsIE[0].src = '/images/icons/ie/' + idAAr[1] + '_x.gif';

                imgsIE[0].style.width = '46px';
                imgsIE[0].style.height = '56px';
            }
            anchors[i].onmouseout = function() {
                var imgsIE = this.getElementsByTagName('img');

                var idA = this.getAttribute('id');
                var idAAr = idA.split('_');
                imgsIE[0].src = '/images/icons/ie/' + idAAr[1] + '_sm.gif';

                imgsIE[0].style.width = '46px';
                imgsIE[0].style.height = '46px';
            }
*/
        }
    }
}

function insertAfter(newElement,targetElement) {
     var parent = targetElement.parentNode;
     if (parent.lastChild == targetElement) {
          parent.appendChild(newElement);
     }
     else {
          parent.insertBefore(newElement,targetElement.nextSibling);
     }
}

function removeChildren(node) {
    if (node.hasChildNodes()) {
        while (node.childNodes.length >= 1) {
            node.removeChild(node.firstChild);
        }
    }
}

var isMSIE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
var isMSIE = /*@cc_on!@*/false;


addLoadEvent(initFishEye);



