$(document).ready(function(){

    $('#first .content .overflow').hide();
    $('#first .content #' + $('#first a.current').attr('id') + 'Content').show();
    $('#first ul a').click(function () {
        if ($(this).hasClass('current')) return false;
        $('#first ul a').removeClass('current');
        $(this).addClass('current');
        $('#first .content .overflow, #first .content .normal').hide();
        $('#first .content #' + $(this).attr('id') + 'Content').show();
        return false;
    });

    $('#second .content .overflow, #second .content .normal').hide();
    $('#second .content #' + $('#second a.current').attr('id') + 'Content').show();
    $('#second ul a').click(function () {
        if ($(this).hasClass('current')) return false;
        $('#second ul a').removeClass('current');
        $(this).addClass('current');
        $('#second .content .overflow, #second .content .normal').hide();
        $('#second .content #' + $(this).attr('id') + 'Content').show();
        return false;
    });

    // IE only related JavaScript
    if($.browser.msie){
        // PNG Fix (IE 5.5 and 6)
        if($.browser.version >= 5.5 && $.browser.version < 7){
            // Load jQuery ifixpng plugin
            $.getScript('/js/jquery/jquery.ifixpng2.js', function(){
                // PNG Fix
                $.ifixpng("/media/jquery/pixel.gif");
                $(".homepageTabs,img[src$='.png']").ifixpng();
            });
        }
    }

    $(".back-button").click(function () {
        history.back();
        return false;
    });


    if ($('#seealso').length > 0) {
        $('#seealso').change(function () {
            location = $('#seealso').val();
            if (location.len > 0) {
                document.location = location;
            }
        });
    }

    if ($('a.popup').length > 0) {
        $('a.popup').each(function () {
            $(this).click(function () {
                window.open(this.href,'popup','status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=1,width=780,height=640');
                return false;
            });
        });
    }

    if ($('.mailtofriend').length > 0) {
        $('.mailtofriend').click(function () {
            mail_str = "mailto:?subject=Check out the " + document.title;
            mail_str += "&body=I thought you might be interested in the " + document.title;
            mail_str += ". You can view it at " + location.href;
            location.href = mail_str;
            return false;
        });
    }

    if ($('a.lightbox').length > 0) {
        $('a.lightbox').lightbox();
    }

    if ($('span.shorten').length > 0) {
        count = 0;
        $('span.shorten').each(function () {
            count++;
            text = $(this).text();
            if (text.length > 200) {
                a = $('<a href="#"> View All</a>').click(function () {
                    text = $(this).parent().find('span').text();
                    $(this).parent().parent().html(text);
                    return false;
                });
                t = $('<span id="fulltext-' + count + '">' + text + '</span>').hide();
                s = $('<span id="shortened-' + count + '">' + text.substr(0, 200) + '...</span>').append(a).append(t);
                $(this).html(s);
            }
        });
    }

    defaultPopup = {
        'frameWidth': 902,
        'zoomSpeedIn': 600,
        'hideOnContentClick': false,
        'centerOnScroll': true,
        'overlayOpacity': 0.9
    };

    // Add external link classes to external links -
    $('a').filter(function(){
        //Compare the anchor tag's host name with location's host name
        return this.hostname && this.hostname !== location.hostname;
    }).attr('target', '_blank');

    // $("div.content a[href^='http://']").attr("target", "_blank");

    if ($('a.external-popup').length > 0 && $('#menu').length > 0) {
        $('a.external-popup').fancybox(defaultPopup);
    }
    if ($('a.orangeBox').length > 0 && $('#menu').length > 0) {
        $('a.orangeBox').each(function() {
            var hrefValue = $(this).attr('href');
            var qsGlue = (hrefValue.indexOf('?') > -1 ? '&' : '?');
            $(this).attr('href', hrefValue + qsGlue + 'popup=true');
        });
        $('a.orangeBox').fancybox(defaultPopup);
    }

    // Hover effect for 'Related Info' boxes
    $('.hover-panel').each(function(){
        var $this = $(this);
        $this.hover(
            function(){
                $this.addClass('hover-panel-hover');
            },
            function(){
                $this.removeClass('hover-panel-hover');
            }
            );
    });


     $('#slideshow').crossSlide({
      sleep: 2,
      fade: 1
    }, [
      { src: '/media/wb/h1.jpg'},
      { src: '/media/wb/h2.jpg' },
      { src: '/media/wb/h3.jpg' },
      { src: '/media/wb/h4.jpg' },
      { src: '/media/wb/h5.jpg' },
      { src: '/media/wb/h6.jpg' }
    ]);

});

function clearSearchBox(e){
    e.value = '';
}

// Used in all pages to submit a form and optionally set a hidden
// form varaible called 'navigate' to direct navgiation
function submitForm(formName, navigateValue) {
    if (navigateValue != null && navigateValue != "") {
        document.forms[formName].navigate.value = navigateValue;
    }
    document.forms[formName].submit();
}

