/* SGF video feature, updated 2010-04-19 07:12 am */

// constants
var VIDEO_FEATURE_IMAGE_BASE = "http://a59.g.akamai.net/f/59/9312/1m/ernstyoung.download.akamai.com/9312/fy2010/markets/sgm/sgf/";
var VIDEO_FEATURE_FLV_BASE = "http://a59.g.akamai.net/f/59/9312/1m/ernstyoung.download.akamai.com/9312/fy2010/markets/sgm/sgf/";
var VIDEO_CYCLE_TIME = 7*1000;
var TV_CYCLE_TIME = 9*1000;

// globals
var VideoFeatures = [];
var TVFeatures = [];
var VideoFeatureIndex = 0, VideoFeatureTimer = null;
var TVFeatureIndex = 0, TVFeatureTimer = null;

// video feature class
function VideoFeature(title, imageUrl, mediaUrl, description, aspect)
{
    this.Title = title;
    this.MediaUrl = mediaUrl;
    this.ImageUrl = imageUrl;
    this.Description = description;
    this.Aspect = aspect;
    
    this.PlayInBox = function(baseUrl)
    {
        loadMovieInBox(baseUrl+this.MediaUrl, this.Aspect, this.Title, this.Description);
    }
    
    return(this);
}

/*
    Create list of video and TV features
*/

VideoFeatures[VideoFeatures.length] = new VideoFeature(""
            , "20105363promo/20105363 SGF External Promo_Vers04 4-9-2010r2.jpg"
            , "20105363promo/20105363 SGF External Promo_Vers04 4-9-2010r1.flv"
            , ""
            , "wide");


function LoadVideoFeature()
{
    if (VideoFeatures.length>0) {
        var lastVideoIndex = VideoFeatureIndex;
        do {
            VideoFeatureIndex = Math.floor(Math.random()*VideoFeatures.length);
        } while (VideoFeatures.length>1 && VideoFeatureIndex==lastVideoIndex);
        try {
            $('#VideoFeatureSection').show();
            $('#VideoFeatureImage').attr('src', VIDEO_FEATURE_IMAGE_BASE + VideoFeatures[VideoFeatureIndex].ImageUrl);
            $('#VideoFeatureTitle').text(VideoFeatures[VideoFeatureIndex].Description);
        } catch(e) {}
        VideoFeatureTimer = window.setTimeout(LoadVideoFeature, VIDEO_CYCLE_TIME);
    } else {
        try {
            $('#VideoFeatureSection').parent().hide();
        } catch(e) {}
    }
}

function PlayVideoFeature()
{
    VideoFeatures[VideoFeatureIndex].PlayInBox(VIDEO_FEATURE_FLV_BASE);
}


function LoadTVFeature()
{
    if (TVFeatures.length>0) {
        var lastVideoIndex = TVFeatureIndex;
        do {
            TVFeatureIndex = Math.floor(Math.random()*TVFeatures.length);
        } while (TVFeatures.length>1 && TVFeatureIndex==lastVideoIndex);
        try {
            $('#TVFeatureSection').show();
            $('#TVFeatureImage').attr('src', VIDEO_FEATURE_IMAGE_BASE + TVFeatures[TVFeatureIndex].ImageUrl);
            $('#TVFeatureTitle').text(TVFeatures[TVFeatureIndex].Description);
        } catch(e) {}
        TVFeatureTimer = window.setTimeout(LoadTVFeature, TV_CYCLE_TIME);
    } else {
        try {
            $('#TVFeatureSection').parent().hide();
        } catch(e) {}
    }
}

function PlayTVFeature()
{
    TVFeatures[TVFeatureIndex].PlayInBox(VIDEO_FEATURE_FLV_BASE);
}



