
function checkJavaVersion() {
    var app = document.applets[0];
    var appContent =  app.toString() + "";
    appContent = appContent.length;
    if( appContent < 30  ) {
        return false;
    }

    var version = app.getVersion();
    version =  version.substring(0,3);
    if( version >= 1.6 ) {
        return true;
    }
    return false;
}

function show_more(text_id) {
    document.getElementById( text_id + '_full' ).style.display = 'block';
    document.getElementById( text_id + '_short' ).style.display = 'none';
}

function show_less(text_id) {
    document.getElementById( text_id + '_short' ).style.display = 'block';
    document.getElementById( text_id + '_full' ).style.display = 'none';
}

/**
 * Goes through and finds links of "button_link" class and replaces with
 * equivalent forms so that user will see platform native button.
 */
function tweakButtons() {
    $("a[class='button_link']").each(function(i){
        var href= $(this).attr("href");
        var qs = null;
        var tmp = href.split("?");
        if (tmp.length > 1) {
            qs = tmp[1];
        }

        var html = '<form method="GET" action="' + href +
            '" class="form_link">' +'<input type="submit" value="' +
            $.trim($(this).text()) + '"/>';
        if (qs) {
            kv_pairs = qs.split("&");
            for ( var i in kv_pairs ) {
                var kv = kv_pairs[i].split("=");
                html += '<input type="hidden" name="' + kv[0] + '" value="' +
                    unescape(kv[1]) + '"/>';
            }
        }
        html += '</form>';

        $(this).replaceWith(html);
    });
    $("input[@type='submit']").removeClass("button_link");
}

function installMainNavRollovers() {
    $("#mainnav a").each(function(i){
        var name = $(this).attr("name");

        // Preload Rollover images
        jQuery("<img>").attr("src", "/img/" + name + "_txt_roll.gif");
        jQuery("<img>").attr("src", "/img/" + name + "_txt.gif");

        // Install Rollovers
        $(this).children("img").hover(
            function(){
                $(this).attr("src", "/img/" + name + "_txt_roll.gif");
            },
            function(){
                $(this).attr("src", "/img/" + name + "_txt.gif");
            }
        );
    });

    // Let's include the Check Out button while we're at it
    jQuery("<img>").attr("src", "/img/checkout_roll.gif");
    jQuery("<img>").attr("src", "/img/checkout.gif");

    $("#mainnav_container #checkout img").hover(
        function(){
            $(this).attr("src", "/img/checkout_roll.gif");
        },
        function(){
            $(this).attr("src", "/img/checkout.gif");
        }
    );
}

/**
 * Finds external links and gives them a target="_blank" attribute so they
 * will open in a new window or tab.
 */
function decorateExternalLinks() {
    $("a[href^=http]").filter(":not([target])").attr("target","_blank");
}

function installThumbnailRollovers() {
    $("div.thumbnail").hover(
        function() {
            $(this).addClass("thumbnail_hover");
        },
        function() {
            $(this).removeClass("thumbnail_hover");
        }
    );
}
$(document).ready(function(){
    tweakButtons();
    installMainNavRollovers();
    decorateExternalLinks();
    installThumbnailRollovers();
});
