jQuery.noConflict();

// Put all your code in your document ready area
jQuery(document).ready(function($){

    // PNG fix
    // $(document).pngFix();

    // clear search box on click
    $('#SearchForm_SearchForm_Search').click( function () {
        if ($(this).val() == 'Search') {
            $(this).val('');
        }
    });

    lastBlock = $("#a1");
    maxWidth = 620;
    minWidth = 310;

    // Set up homepage accordian
    $("#home-banner-promos ul li a").hover( function(){
        $(lastBlock).animate({width: minWidth+"px", backgroundPosition: '180px 0'}, { queue:false, duration:400 });
        $(this).animate({width: maxWidth+"px", backgroundPosition: '290px 0'}, { queue:false, duration:400});

        if (this != lastBlock) {
            $(this).find('.promo-label .arrow').hide();
            $(lastBlock).find('.promo-label .arrow').show();
        }
        lastBlock = this;
    }, function() {});




    // Set up the e-mail a friend Ajax link
    // musthappen before initilazing Shadowbox
    AjaxEmailFriendForm_link = $('#AjaxEmailFriendForm').attr('rel');
    $('#AjaxEmailFriendForm').html(
        "&nbsp;|&nbsp;<a href='" + AjaxEmailFriendForm_link + "' rel='shadowbox;player=iframe;width=650;height=450;title=Email a Friend'>email</a>"
    );

    // Set up the PrintPage link
    $('#PrintPage').html(
        "<a href='#'><span>print</span></a>"
    );
    $('#PrintPage a').click( function() {
        window.print();
        return false;
    });

    // Set up the Share This link
    $('#ShareThis').each( function() {
        $(this).html(
            "&nbsp;|&nbsp;<span>share</span>"
        );
        $(this).find('span').bookmark({
            popup: true,
            popupText: 'share',
            icons: '/mysite/javascript/jquery.bookmark/bookmarks.png',
            sites: ['digg', 'slashdot', 'google', 'yahoobuzz', 'facebook', 'technorati', 'tumblr', 'stumbleupon', 'squidoo', 'friendfeed', 'twitthis', 'bloglines']
        });
    });


    // initialize Shadowbox
    // A custom build of shadowbox-2.0/shadowbox-2.0.js is already loaded
    // it includes:
    // - the jquery integration
    // - the players: img, swf, flv, qt, wmp, iframe, html
    // - the skin: shadowbox-2.0/skin/classic
    //
    var sb_options = {
        autoplayMovies:     false
    };
    Shadowbox.init(sb_options);



    // load the metadata extension
    $.getScript('/mysite/javascript/jquery.metadata.2.0/jquery.metadata.min.js', function() {

        // load the media extension
        $.getScript('/mysite/javascript/jquery.media.js', function() {

            // set the default flv player
            $.fn.media.defaults.flvPlayer = '/mysite/javascript/mediaplayer/player.swf';

            // set the default mp3 player
            $.fn.media.defaults.mp3Player = '/mysite/javascript/mediaplayer/player.swf';

            // hide the text from media anchors
            $('.media').text('');

            // update all class=media elements
            $('.media').media();
        });
    });

    // set the correct visible|hidden class on toggle items
    $("[id^='toggle-']").each( function() {
        // figure out what to toggle
        toggle_source = $(this).attr('id');
        toggle_target = toggle_source.replace(/^toggle-/i, '');

        if ( $('#' + toggle_target).is(':visible') ) {
            $(this).removeClass('hidden').addClass('visible');
        }
        else {
            $(this).removeClass('visible').addClass('hidden');
        }
    });

    // get all the toggle-* ID elements and add a toggle effect
    $("[id^='toggle-']").click( function() {

        // figure out what to toggle
        toggle_source = $(this).attr('id');
        toggle_target = toggle_source.replace(/^toggle-/i, '');

        console.log(toggle_source + '|' + toggle_target);

        $('#' + toggle_target).slideToggle("slow", function() {
            if ( $(this).is(':visible') ) {
                $('#' + toggle_source).removeClass('hidden').addClass('visible');
            }
            else {
                $('#' + toggle_source).removeClass('visible').addClass('hidden');
            }
        });

    });

    // suckerfish code to support IE6
    if ($.browser.msie && $.browser.version == '6.0') {
        $('ul.nav>li').hover(function () {
            $(this).addClass('sfhover');
            var ul = jQuery('ul.nav li.sfhover ul');
            var parent = ul.parent();
            if (parent.is('ul.nav li.sfhover')) {
                var ppos = parent.position();
//                ul.css({left: ppos.left, top: ppos.top + 28});
                ul.css({left: 0, top: ppos.top + 30});
            }
        },
        function () {
            var ul = jQuery('ul.nav li.sfhover ul');
            ul.css({left: '-999em'});
            $(this).removeClass('sfhover');
        });
    }


    if ($.browser.msie && $.browser.version < 8.1 ) {
//        $('div#GA0>ins').css({zIndex: '-1'});
//        $('div#GA0 iframe').css({
//            zIndex: '-1000',
//            border: '2px solid red'
//            });
    }



});




