$ = jQuery = $ektron;

function sramk_flash_product_video(video) {
    // Set up variables for easy reference
    var video = {
        title: $('span.title', video).text(),
        autoPlay: $('span.autoPlay', video).text(),
        aspectRatio: $('span.aspectRatio', video).text(),
        checkBw: $('span.checkBW', video).text(),
        filename: $(video).attr('rel')
    };
    
    // Internap flashvars
    var flashfile = "videoPlayer_internap";
    var flashvars = {
        autoplay: video.autoPlay,
        aspectratio: video.aspectRatio,
        BWDetection: video.checkBw,
        media: video.filename,
        fullscreenpage: "true",
        fsreturnpage: "true"
    };
    
    // Global Flash settings
    var params = {
        allowfullscreen: "true",
        bgcolor: "#eeeeee",
        quality: "best"
    };
    var attributes = { id: 'videoGallery', name: 'videoGallery' };
    
    // Prepare the markup
    $('div.video-container').empty().append('<h3>' + video.title + '</h3>').append('<div id="flash-video"/>');

    // Load Flash
    if (userHasFlashVersion) {
        swfobject.embedSWF("/_ui/sramk08/swf/global/"+ flashfile +".swf", "flash-video", "540", "400", flashVersion, expressInstall, flashvars, params, attributes);
    }
}

$(document).ready(function() {
    // Flash Video
    if ($('#flash-video').length > 0) {
        
        // Iterate through videos
        $('div.videoList ul.videos a').each(function() {
            // Switch Flash
            $(this).click(function() {
                // Change active classes
                $('ul.videos a').removeClass('active');
                $(this).addClass('active');
                
                // Switch video
                sramk_flash_product_video(this);
                return false;
            });
        });
        
        // Display first video
        $('ul.videos li:first-child a').trigger('click');
        
        // Hide list if only one
        if($('ul.videos li').length <= 1) {
            $('ul.videos').hide();
        }
    }
});
