/*Needs youtube, accordion, carousel*/

function setTopTab(uitab) {
    mediaCenterTopTabClick('#TT_MCFlash', uitab);
    mediaCenterTopTabClick('#TT_MCPhotos', uitab);
    mediaCenterTopTabClick('#TT_MCMov', uitab);
    mediaCenterTopTabClick('#TT_MCFP', uitab);
}

function mediaCenterTopTabClick(panelId, uitab) {
    var h = $(uitab).attr('href');
    h == panelId ? mediaCenterShowTopTab(panelId) : mediaCenterHideTopTab(panelId);
}

function mediaCenterShowTopTab(panelId) {
    var panel = $(panelId);
    if (panelId == "#TT_MCFlash") {
        var items = panel.find("a.TT_MCVideoItem");
        if (items.length > 0) { $(items[0]).click(); }
    } else if (panelId == "#TT_MCPhotos") {
        panel.find(".start").click();
    } else if (panelId == "#TT_MCMov") {
        var items = panel.find("a.TT_MCMovItem");
        if (items.length > 0) { $(items[0]).click(); }
    } else if (panelId == "#TT_MCFP") {
        return;
    } else { return; }
}
  
function mediaCenterHideTopTab(panelId) {
    var panel = $(panel);
    if (panelId == "#TT_MCPhotos") {
        panel.find(".stop").click();
    } else if (panelId == "#TT_MCFlash") {
        stopYouTubePlayer("TT_MCFlashID");
    } else if (panelId == "#TT_MCMov") {
        panel.find(".TT_MCMovPlayer").empty();
    } else if (panelId == "#TT_MCFP") {
        return;
    } else { return; }
}
      
(function($) {
    $.fn.mediaCenterMov = function(settings) {
        settings = jQuery.extend({
            targetSelector: "div.TT_MCMovPlayer",    // (String) Container into which to load the mov file
            statusSelector: "div.TT_MCMovStatus",        // (String) Place to display the label and possibly link
            videoUrl: "",                     // (String) Video url to be asssigned laterlink to enlarge
            videoLabel: "",                     // (String) Placeholder for status title
            width: 400, //320,                    // (int) Specify video width
            height: 300 //256	                     // (int) Specify video height
        }, settings);

        function _initialize() {
            try {
                _start(this);                         // This refers to object (link) which the user has clicked
            } catch (e) {
                alert(e);
            }
            return false;                             // Prevent the browser from following the link
        };

        function _start(clicked) {
            settings.videoUrl = $(clicked).attr("href");
            settings.videoLabel = $(clicked).attr("title");
            if ($(settings.statusSelector).length > 0) {
                $(settings.statusSelector).empty().append('<a href="' + settings.videoUrl + '">' + settings.videoLabel + '</a>');
            }
            $(settings.targetSelector).html(_embedHTML(settings.videoUrl, settings.width, settings.height)).show();
        };

        function _embedHTML(url, width, height) {
            var html = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="' + height + '" width="' + width + '"> ' +
                '<param name="src" value="' + url + '">' +
                '<param name="controller" value="true">' +
                '<param name="autoplay" value="true">' +
                '<param name="wmode" value="transparent">' +
                '<param name="type" value="video/quicktime" height="' + height + '" width="' + width + '">' +
                '<embed src="' + url + '" height="' + height + '" width="' + width + '" ' + getWmode() + 'controller="true" autoplay="true" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/">' +
                '</object>';
            return html;
        };
        
        function getWmode() {
            if (jQuery.browser.safari == true) {
                return 'wmode="transparent" ';
            }
            return '';
        }

        // Return the jQuery object for chaining
        return this.click(_initialize);
    };
})(jQuery);  // Call and execute the function immediately passing the jQuery object
