﻿//use browser sniffing to determine if IE or Opera (ugly, but required)
var isOpera, isIE = false;
if (typeof (window.opera) != 'undefined') { isOpera = true; }
if (!isOpera && navigator.userAgent.indexOf('Internet Explorer')) { isIE = true; }

/*fix both IE and Opera (adjust when they implement this method properly)*/
if (isOpera || isIE) {
    document.nativeGetElementById = document.getElementById;
    /*redefine it!*/
    document.getElementById = function(id) {
        var elem = document.nativeGetElementById(id);
        if (elem) {
            /*verify it is a valid match!*/
            if (elem.attributes['id'] && elem.attributes['id'].value == id) {
                /*valid match!*/
                return elem;
            } else {
                /*not a valid match! the non-standard, document.all array has keys for all name'd, and id'd elements start at one, because we know the first match, is wrong! */
                for (var i = 1; i < document.all[id].length; i++) {
                    if (document.all[id][i].attributes['id'] && document.all[id][i].attributes['id'].value == id) {
                        return document.all[id][i];
                    }
                }
            }
        }
        return null;
    };
}
animatedcollapse.addDiv('divContentWrapper', 'fade=1,speed=500');
animatedcollapse.addDiv('ninjaPage', 'fade=0,speed=500');
animatedcollapse.addDiv('divFormSubWrap', 'fade=1,speed=500,hide=1,height=270px');
animatedcollapse.init();

var formIsOpen;
var hashParm = document.location.toString().split('#')[1];

//used to callback/update the flash content
function getFlashMovie(movieName) {
    // Get a reference to the player
    var player = null;
    try {
        if (document.all)
            player = document.all(movieName);
        else
            player = document.getElementById(movieName);
    }
    catch (err) { }

    return player;
}
function sendPageName(pageName) {
    try {
        var flashHeader = getFlashMovie("flashBanner");
        flashHeader.refreshPage(pageName);
    }
    catch (err) { }
}
function launchMarketingVideo() {
    $("#marketingVideo").modal({ onOpen: function(dialog) {
        dialog.overlay.fadeIn('slow', function() {
            dialog.data.hide();
            if (typeof document.body.style.maxHeight === "undefined") {
                $('.simplemodal-overlay').animate({ height: '1000px' });
            }
            dialog.container.show();

            dialog.data.show();
            var flashvars = false;
            var params = {
                wmode: "transparent"
                //menu: "false",
                //flashvars: "name1=hello&name2=world&name3=foobar"
            };
            var attributes = {};

            swfobject.embedSWF("/swf/f92Marketing.swf", "flashReplace", "660", "380", "9.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);

        });
    },
        onClose: function(dialog) {
            dialog.data.hide();
            dialog.container.hide();
            dialog.overlay.fadeOut('slow', function() {
                $('#marketingVideo').html("<div id='flashReplace'></div>");
                $.modal.close();
            });
        },
        overlayClose: true, 
        autoPosition: false
    });
}

function sendToggleForm(formName, isOpen) {
    if (isOpen == 0 || isOpen == 1) {
        //send into to flash
        try {
            var flashHeader = getFlashMovie("flashBanner");
            flashHeader.toggleForm(formName + ',' + isOpen);
        }
        catch (err) { }
    }
    formIsOpen = isOpen
    //close or open the correct form
    if (isOpen == -1 || isOpen == 0)
        animatedcollapse.hide('divFormSubWrap');
    else {
        var dLunch = document.getElementById('Form_Lunch');
        var dStrategic = document.getElementById('Form_Strategic');
        var dDigital = document.getElementById('Form_Digital');
        var dJoin = document.getElementById('Form_Join');

        //dLunch.style.visibility = "hidden";
        dLunch.style.display = "none";
        //dStrategic.style.visibility = "hidden";
        dStrategic.style.display = "none";
        //dDigital.style.visibility = "hidden";
        dDigital.style.display = "none";
        //dJoin.style.visibility = "hidden";
        dJoin.style.display = "none";

        if (formName == 'Form_Join') {
            animatedcollapse.hide('divFormSubWrap');
            window.open('http://careers.fusion92.com/careers/index.php');
        }
        else {
            //document.getElementById(formName).style.visibility = "visible";
            document.getElementById(formName).style.display = "block";
            animatedcollapse.show('divFormSubWrap');
        }
    }

}
function openLink(linkType) {
    var linkURL = "";
    switch (linkType) {
        case "facebook":
            linkURL = "http://www.facebook.com/pages/Arlington-Heights-IL/Fusion92/51698183088";
            break;
        case "linkedin":
            linkURL = "http://www.linkedin.com/companies/fusion92";
            break;
        case "delicious":
            linkURL = "http://www.delicious.com/fusion92";
            break;
        case "twitter":
            linkURL = "http://www.twitter.com/fusion92";
            break;
        case "map":
            linkURL = "http://maps.google.com/maps?f=q&source=embed&hl=en&geocode=&q=59%20w%20seegers,%2060005&sll=37.0625,-95.677068&sspn=50.424342,114.257812&ie=UTF8&ll=42.057068,-87.981777&spn=0.030589,0.054932&z=14&iwloc=addr";
            break;
        case "email":
            linkURL = "mailto:inquiry@fusion92.com";
            break;
    }
    window.open(linkURL);
}
//end flash update

// this method is invoked from the flash animation as well
function FormUpdate(formName) {
    //alert("'" + formName + "'")
    if (formName == '' || formName == ' ') {
        sendToggleForm('Form_Lunch', -1);
    }
    else { sendToggleForm(formName, 2);}
}

function EndRequest(sender, args) {
    var uprog = document.getElementById('updateProgress');
    uprog.style.display = "none";
    uprog.style.visibility = "hidden";
    /*
    // Check to see if there's an error on this request.
    var error = args.get_error();
    if (error != null) {
    // Set the error handled flag to avoid a runtime error
    //reaching the user.
    args.set_errorHandled(true);

    // Remove the error name from the message
    var msg = error.message.replace("Sys.WebForms.PageRequestManagerServerErrorException: ", "");                                
    alert(msg);                
    }*/
    if (hashParm != "" && hashParm != "/" && hashParm != "think.aspx" && hashParm != "do.aspx") {
        animatedcollapse.show('divContentWrapper');
    }
    if (hashParm != null && hashParm != "undefined") {
        try { sendPageName(hashParm); }
        catch (err) { /*alert(err);*/ }
    }

    animatedcollapse.hide('ninjaPage');
}
function scrollUpCollapse(collapseDiv) {
    var offy;
    if (self.pageYOffset) {
        offy = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        offy = document.documentElement.scrollTop;
    } else {
        offy = document.body.scrollTop;
    }
    if (offy <= 0) {
        /*now start collapse*/
        animatedcollapse.show(collapseDiv);
        return;
    }
    window.scrollBy(0, -100);
    setTimeout("scrollUpCollapse('" + collapseDiv + "')", 10);
}
