// Realization User interface
var video_tooltip_text = 'View the video clip';
var video1 = 'videos/video_amdocs_sm.swf';
var video2 = 'videos/video_ofd_sm.swf';
var video3 = 'videos/video_pg_sm.swf';

// Embed videos for the first time 
swfobject.embedSWF(video1, "video1", "205", "128", "9.0.0", false, false, {wmode: "transparent"});
swfobject.embedSWF(video2, "video2", "205", "128", "9.0.0", false, false, {wmode: "transparent"});
swfobject.embedSWF(video3, "video3", "205", "128", "9.0.0", false, false, {wmode: "transparent"});


var REALIZATION = {

    /**
     * Init functions
     */
    init: function () {

        $(".video").simpletip({ content: video_tooltip_text, fixed: false, delay: 100, offset: [10,10] });
        
        $('.watch-video').bind('click', function() {
            var video = $(this).attr('href').replace('#', '')
            var movie = REALIZATION.getFlashMovie(video);
            if (movie) {
                movie.Play();
            }
            return false;
        }); 
        
        // Tabs
        if ($('.tabs').length) {
            var $tabs = $('.tabs').tabs();
            
            // Remove movie when other tabs is selected in IE
            if ($.browser.msie) {
                $('.tabs .nav a').bind('click', function() {
                    var selected = $tabs.tabs('option', 'selected');
                    switch (selected) {
                        case 0: 
                            swfobject.removeSWF('video2');
                            swfobject.removeSWF('video3');
                            $('#customer2 .video').remove();
                            $('#customer3 .video').remove();
                            REALIZATION.addVideo(1);
                            break;
                        case 1: 
                            swfobject.removeSWF('video1');
                            swfobject.removeSWF('video3');
                            $('#customer1 .video').remove();
                            $('#customer3 .video').remove();
                            REALIZATION.addVideo(2);
                            break;
                        case 2: 
                            swfobject.removeSWF('video1');
                            swfobject.removeSWF('video2');
                            $('#customer1 .video').remove();
                            $('#customer2 .video').remove();
                            REALIZATION.addVideo(3);
                            break;
                    }       
                });
            }
        }
    },
    
    /**
     * Get Flash Movie
     */         
    getFlashMovie: function (id) {
        var movie = null;
        if ($.browser.msie) {
            movie = document.getElementById(id);
        } else {
            movie = document[id];
        }
        return movie;
    },      
    
    /**
     * Add video
     */
    addVideo: function (id) {
        if (!$('#video' + id).length) {
            $('#customer' + id).prepend('<div class="video"><div id="video' + id + '"></div></div>');
            $(".video").simpletip({ content: video_tooltip_text, fixed: false, delay: 100, offset: [10,10] });
            swfobject.embedSWF(eval('video' + id), "video" + id, "205", "128", "9.0.0", false, false, {wmode: "transparent"});
        }
    }
}

$(document).ready(function () {
    REALIZATION.init();
});