// This is for the Video Gallery page

var videoPlaylist = 'xml/videoPlaylist.xml';
var isFirst;

jQuery(function($) {

    if ($('.video_scroll_contents').length) {
        var so = new SWFObject('flash/videoModule.swf', 'oeVideoModule', '100%', '100%', '8', '#000000');
        if (so.installedVer.major >= 7) {
            so.useExpressInstall('flash/expressinstall.swf');
            so.addParam('allowScriptAccess', 'always');
            so.write("videoPlayer");
        } else {
            $('#videoPlayer').html('<h2>Please <a href="http://www.adobe.com/products/flashplayer/" target="blank">upgrade your Flash Player</a><br /> to experience this site to its fullest.</h2>');
        }
        $.ajax({
            type: "GET",
            url: videoPlaylist,
            dataType: "xml",
            success: function(xml) {
                isFirst = true;
                $(xml).find('playlist media').each(function() {
                    var id_text = $(this).attr('id');
                    var thumbnail = $(this).find('asset[type=thumbnail]').text();
                    var video_still = $(this).find('asset[type=video_still]').text();
                    var video = $(this).find('asset[type=video]').text();
                    var href = $(this).find('asset[type=href]').text();
                    var video_title = $(this).find('description').attr('title');
                    var short_desc = $(this).find('description > short-description').text();
                    var long_desc = $(this).find('description > long-description').text();
                    var tag = $(this).find('tags').attr('type');
                    if (isFirst) {
                        $('.video_player_container h2:eq(0)').text(video_title);
                        $('.video_player_container img:eq(0)').attr('src', video_still);
                        //$('.video_player_container p:eq(0)').html(long_desc);
                        setTimeout(function() {
                            getFlashMovie('oeVideoModule').loadMedia(video_still, video);
                        }, 500);
                    }
                    isFirst = false;
                    var html = '<a href="' + href + '"><img src="' + thumbnail + '" alt=""/></a><h2>' +
								  '<a href="' + href + '">' + video_title + '</a></h2><p>' + short_desc + '</p><span style="display: none;">' +
								  '</span><span style="display: none;" title="' + video + '">' + video_still + '</span><span ' +
								  'style="display: none;">' + tag + '</span>';
                    $('<li></li>').html(html).appendTo('.video_scroll_contents ul');
                });
                //$('.video_scroll_contents').jScrollPane({ showArrows: true });
                $('.video_scroll_contents ul li a').click(function(e) {
                    e.preventDefault();
                    var video_title = $(this).parents('li').find('h2 a').text();
                    var video_still = $(this).parents('li').find('span:eq(1)').text();
                    var long_desc = $(this).parents('li').find('span:eq(0)').text();
                    var video = $(this).parents('li').find('span:eq(1)').attr('title');
                    $('.video_player_container h2:eq(0)').text(video_title);
                    getFlashMovie('oeVideoModule').loadMedia(video_still, video);
                    $('.video_player_container img:eq(0)').attr('src', video_still);
                    $('.video_player_container img:eq(0)').attr('title', video);
                    //$('.video_player_container p:eq(0)').html(long_desc);
                });
            }
        });

        $('.video_nav li a').click(function(e) {
            e.preventDefault();
            var aLink = $(this);
            $('.video_scroll_contents ul li').each(function() {
                if ($(this).find('span:last').text() != aLink.attr('href') && $(this).is(':visible')) $(this).stop(false, true).slideUp(500);
                else if ($(this).find('span:last').text() == aLink.attr('href') && $(this).is(':hidden')) $(this).stop(false, true).slideDown(500);
            });
            setTimeout("$('.video_scroll_contents').jScrollPane({showArrows:true});", 550);
        });

    }
});


function getFlashMovie(movieName) {   
	var isIE = navigator.appName.indexOf("Microsoft") != -1;   
	return (isIE) ? window[movieName] : document[movieName];  
}  

