token= '4c5c0f1c156391199ccaf8993ea13aa4';
auto_play = 'true';
show_play = 'true';
player    = 'http://cdn-akm.vmixcore.com/core-flash/UnifiedVideoPlayer/UnifiedVideoPlayer.swf'
path      = '/'

function buildObject(token, auto_play, show_play) {
 	flashvar = 'show_control_bar=true&ad_service=vmix&genre=KC%20Big%2012&token='+token+'&auto_play='+auto_play+'&show_play_icon='+show_play;
	newObject = '<object type="application/x-shockwave-flash" data="'+ player +
		    		'" width="608" height="392">'+
		    		'<param name="movie" value="'+player+'" />'+
		    		'<param name="allowfullscreen" value="true" />'+
	     			'<param name="allowscriptaccess" value="always" />'+
	     			'<param name="wmode" value="transparent" />'+
	     			'<param id="flashvars" name="flashVars" value="'+flashvar+'"/>'+
	     			'<param name="flashVersion" value="10" />'+
	     			'</object>';
		return newObject
}

// create a thickbox and populate it with the appropriate info
$('.tb_trigger').live('click', function() {
	hed = $(this).find('h4').html();
	id = $(this).attr('id').replace('vmix','');
	tb = buildObject(id, id, true, false) + '<h4>'+ hed + '</h4>';
	$('#vidhold').html(tb);
	tb_show(hed, "#TB_inline?height=420&width=620&inlineId=vidhold");
});



// * modified liScroll 1.0
jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.07
		}, settings);		
		return this.each(function(){
				tickerinfo = $(this).after('<div id="tickerinfo"></div>');
				var firstUl = $(this).find('ul:first');
				// make sure we have something to scoll
				if ($(firstUl).html().length < 1) {
					return false
				};
				// we're going to create a wrapper and scroll that
				$(firstUl).wrap("<div id='tickercontainer'></div>");
				var tickercontainer = $('#tickercontainer');
				// and now we're going to create a copy of our ul within our strip
				var secondUl = '<ul class="second">' + $(firstUl).html() + '</ul>';
				firstUl.after(secondUl);
				
				UlWidth = 0;
				// now, how wide does tickercontainer need to be?
				firstUl.find('li').each(function() {
		        UlWidth += $(this).outerWidth();  
		      });
		      tickerWidth = UlWidth * 2;
		      $(tickercontainer).width(tickerWidth);
		      var defTiming = tickerWidth/settings.travelocity;

		      /* scroll left the width of one UL. 
		      When done, reset to 0. 
		      The second UL will fill in the blank
		      */
		      function scrollnews(spazio, tempo){
					$(tickercontainer).animate({left: '-='+ spazio}, tempo, "linear", function(){
						$(tickercontainer).css("left", -5);
						scrollnews(UlWidth, defTiming);
					});
				}
				$(tickercontainer).css("left", '0');
				scrollnews(UlWidth, defTiming);
				
				$(tickercontainer).hover(function(){
					jQuery(this).stop();
				}, function(){
					var offset = jQuery(this).offset();
					var residualSpace = offset.left + UlWidth;
					var residualTime = residualSpace/settings.travelocity;
					scrollnews(residualSpace, residualTime);
				});	
		});	
};
				
$(document).ready(function() {
	// load and handle vids
	var url = '/cgi-bin/php/vmixer.php?api=media&action=getMediaList&params='+escape('limit=30&collection_ids=13717');
	$.getJSON(url, function(r){
		for (i in r){
			li = '<li class="tb_trigger" id="vmix'+r[i].token+'">'+
				'<img src="http://image.vmixcore.com/imgman.jpg?width=100&url='+	r[i].thumbnail[0].url+
				'" alt="'+r[i].title+'">'+
				'<h4>'+
				 r[i].title+'</h4>'+
				'<p style="margin-top:0">'+ r[i].description + '</p>'+
				'</li>';
			$('ul#video-thumbs').append(li);
		}
	});
	$('ul#video-thumbs').after('<div id="vidhold"></div>');
	
	// load and handle tsn scores
	 feedurl = '/static/sports/ncaabask_scores.xml';
    function loadFeed() {
      // reset
    	$('#feed-results').html('<ul id="games-ticker"></ul>');
    	$('.live-game').remove();
		jQuery.getFeed({
        url: feedurl,
        success: function(feed) {
            
            items = $(feed).find('game');
            //alert($(items).size());
            for(var i = 0; i < $(items).size(); i++) {
                var item = items[i];
                var html = '<li>';
                // is the game upcoming? Give the time
                if ($(item).attr('status') == 'pending') {
                	html += '<strong>' + $(item).attr('status_text') + ':</strong> ';
                }
                if ($(item).attr('status') == 'live') {
                	html += '<span class="live-game">';
                }
                html += '<a href="'+ $(item).attr('awayURL') + '">' + $(item).attr('away') + '</a> '
                + $(item).attr('away_score');
                if ($(item).attr('status') == 'pending') {
                	html += ' vs. ';
                } else {
                  html += ', ';
                }
                html += '<a href="'+ $(item).attr('homeURL') + '">' + $(item).attr('home') + '</a> '
                + $(item).attr('home_score');
                if ($(item).attr('status') == 'live') {
                	html += " <span> &ndash; ";
                	if ($(item).attr('time') != "") {
                		html += $(item).attr('time') +", ";
                	}
                	html += $(item).attr('period')+" half</span></span>";
                }
                if ($(item).attr('status') == 'final') {
                	html += " (final)";
                }
                html += '</li>';
            jQuery('#feed-results ul').append(html);
            }
            $("#feed-results").append($('.live-game')); 
            $("#feed-results").liScroll({travelocity: 0.1}); 
            
        }    
      });
    }
    loadFeed();
    setInterval(function() {
      //alert('get feed');
       $('#feed-results').html('Reloading...');
       loadFeed();
   }, 1000*60);
   
   active = $('#bracket-menu li.active a').attr('href');
   $('#bracket-box > div').hide();
	$(active).fadeIn();
	 
    // tab out brackets
    $('#bracket-menu li a').click(function(e) {
    		e.preventDefault();
				$('#bracket-menu li').removeClass('active');
				$(this).parent().addClass('active');
				$('#bracket-box > div').hide();
				$($(this).attr('href')).fadeIn();					
			});
    // show bracket game times
    //$('#bracket-box ul').each(function() {
    //	$(this).after('<span class="gametime">' + $(this).attr('title') + '</span>')
    //})
});

