/* stop IE6 flicker */
try { document.execCommand("BackgroundImageCache", false, true); } catch(err) {}

// variables for various things
var mouseOvers = new Array();

// embed our flash with UFO
if(!!document.getElementById("flash-image-area")) {
    var FO = { movie:"/flash/home.swf", width:"740", height:"240", majorversion:"7", build:"0", bgcolor:"#FFFFFF", wmode:"opaque" };
    UFO.create(FO, "flash-image-area");
}

/* on dom loaded (jquery) */
$(document).ready(function(){
    
    // add wrapper divs to make shadows (except for IE 6)
    if (!$.IE6Below()) {
        $("#main").wrap("<div id='main-wrapper'></div>");
        $("#main-wrapper").append("<div id='top-shadow'></div><div id='bottom-shadow'></div>");
    };
    
    // preload some images we use for rollovers 
    // this will find a background image such as something.png and preload something-o.png
    // this should work with any extension, .png .gif .jpg .jpeg etc
    $("#navigation ul a").each(function(i){
        if ($(this).css("background-image")!='none') {
            var imageURL = $(this).css("background-image"); // e.g. "url(http://foo/bla.png)"
            var cleanImageURL = imageURL.substring(4, imageURL.length-1); // e.g. "http://foo/bla.png"
            var imageSuffix = cleanImageURL.substring(cleanImageURL.lastIndexOf('.'), cleanImageURL.length); // e.g. ".png"
            var lastTwoChars = cleanImageURL.substring(cleanImageURL.length-imageSuffix.length-2,cleanImageURL.length-imageSuffix.length);// e.g. "-o"
            if (lastTwoChars!='-o') {
                var newImageURL = cleanImageURL.substring(0,cleanImageURL.length-imageSuffix.length) + "-o" + imageSuffix;
                mouseOvers[i] = new Image();
                mouseOvers[i].src = newImageURL;
            };            
        };
    });
    
    // add default text functionality to input fields
    $('.input-default-text').each(function(i) {
        var defaultValue = $(this).attr('value');
        $(this).focus(function () { if (this.value == defaultValue) this.value = ''; this.style.color = '#333333' });
        $(this).blur(function () { if (this.value == '') { this.value = defaultValue; this.style.color = '#666666' }});
    });
    
    
    
});


/**************** other misc functions *****************/

// Return true if browser is Internet Explorer and version 6 or earlier
$.IE6Below = function() {
    if ($.browser.msie) {
        try {
            if (ScriptEngineMajorVersion() <= 5 && ScriptEngineMinorVersion() < 7) { // ie 6- only
                return true;
            }
        } catch(err) { return false; };
        return false;
    } else {
        return false;
    };
}
