// Browser Checks

var BROWSER_IE = false;
var BROWSER_IE6 = false;
var BROWSER_IE7 = false;
var BROWSER_SAF = false;

if ($.browser.msie) {
    BROWSER_IE = true;
    if ($.browser.version.substr(0,1) == 6) {
        BROWSER_IE6 = true;
    } else if ($.browser.version.substr(0,1) == 7) {
        BROWSER_IE7 = true;
    }
} else if (navigator.userAgent.indexOf("safari")) {
    BROWSER_SAF = true;
}

// Functions

function hideWidgets() {
    if ( $('.widget_container') ) {
        $('.widget_container').hide();
        
        if (BROWSER_IE6) {
            $('select').show();
        }
    } else {
        window.close();
    }
}

// RT common functions

jQuery.preloadImages = function() {
  for(var i = 0; i<arguments.length; i++) {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

// RT common jQuery calls

$(document).ready(function() {

    // Removed outlines when elements are selected 
    $("input[type='radio'],input[type='checkbox'],button").focus(function(){
        this.blur();
    });

    // Widget Tooltip
    // Requires jquery.tooltip.min.js
    if (jQuery.fn.tooltip) {
        $("a.widget_access_icon").tooltip({
            delay: 500, showURL: false, fixPNG: true, opacity: 1, showBody: " - ",  extraClass: "bubbleFixedLeftXSmallTop", top: -75, left: -2
        });
    }

    // Google SearchBar Tooltip
    var searchbar_google_Target     = $('#searchBar_google a');
    var searchbar_google_Tooltip    = $('#searchBar_google_tooltip');
    if ($('div#searchBar') && (jQuery.fn.hoverIntent)) {
        searchbar_google_Target.hoverIntent(
            function(){
                searchbar_google_Tooltip.show();
            },
            function(){
                searchbar_google_Tooltip.hide();
            }
        );
    }
    
    // Prepend Named Anchor to Box Module for IE6 only
    if (BROWSER_IE6) {
        $('div.content').each(function(i){
            var boxID = $(this).attr('id');
            $(this).prepend('<a name="' + boxID + '" id="' + boxID + '"></a>');
        });
    }

    // Keep Google IMG from resizing after pngFix
    if (BROWSER_IE6) {
        $("img#searchBar_googleImg").attr("src", "http://images.rottentomatoes.com/images_REDESIGN/template/searchbar_poweredbygoogle.gif");
    }

    // Selects after click in primary navigation
    $('#nav_primary a').click(function() {
        $('#nav_primary a').removeClass('selected');
        $(this).addClass('selected');
    });

    // Selects after clicks for all abstract imgs  
    $('.abstract img').click(function(){
        $(this).addClass('selected');
    });

    // Video Image control
    if (!BROWSER_IE6) {
        $('.videoImg').each(function() {
            if ($(this).children('div.videoImgControl a')) {
                $(this)
                    .mouseover(function() {
                        $(this).children('a.abstract').addClass("hover");
                        $(this).children('div.videoImgControl').children('a').addClass("hover");
                    })
                    .mouseout(function() {
                        $(this).children('a.abstract').removeClass("hover");
                        $(this).children('div.videoImgControl').children('a').removeClass("hover");
                    })
                    .mousedown(function() {
                        $(this).children('div.videoImgControl').children('a').toggleClass("active");
                    })
                    .mouseup(function() {
                        $(this).children('div.videoImgControl').children('a').removeClass("hover active");
                    });
            }
        });
    }
  
    $("#nav_primary_movies").hover(function() {
        $("#nav_bg").css({height: ""});
    }, function() { });
   
});