// JScript source code
var init="false";

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

jQuery(document).ready(function() {
	$("font").removeAttr('color').removeAttr('size');
    jQuery('#RotatorList').jcarousel({
        scroll:1
    });
    $('#videodiv').hide();
	$('#imagediv').hide();
	$('#RotatorList li.video .vidimg').show();
	$('#RotatorList li').hover(function(){
		$(this).find('.overlay').toggleClass('overlayon');
		$short=$(this).find('.shorttitle');
		var thumbheight=$(this).height();
		var textheight=$short.height();
		if (textheight > 11)
		{
			$short.css('top',thumbheight-textheight);
		}
	}, function(){
		$(this).find('.overlay').toggleClass('overlayon');
		$short=$(this).find('.shorttitle');
		$short.css('top',47);
	});
    $('.rotator_thumb').click(function()
    {
		$id=$(this).attr('id').split('-')[1];
		clearSelected();
		$(this).find('.overlay').addClass('overlayselected');
		$(this).addClass('thumbselected');
		var callback=function(data)
		{
			$data=jQuery(data);
			$params=$data.find('#RotatorParams');
			$text=$data.find('.carousel_text');
			loadContent($params.val(),$text,init);
			$('#RotatorList').show();
			init="true";
		}
		$.ajax({
			type:'POST',
			url: '/HomeRotator/HomeRotatorContent.aspx',
			success: callback,
			cache: false,
			dataType: 'html',
			data:"t-id=" + $id
		});
		return false;
    });
    $('.rotator_thumb:first').click();
});

function clearSelected()
{
	$('.overlay').removeClass('overlayselected');
	$('.rotator_thumb').removeClass('thumbselected');
}
function loadContent(params,$text,autostart)
{
	$('#videocontainer').remove();
	var parray=params.split('|');
	if (parray[0]=="1")
	{
		
		$('#videodiv').append('<div id="videocontainer"></div>').show();
		$('#imagediv').hide();
		stageW = 450;
		var stageH = 253;
		var cacheBuster = Date.parse(new Date());
		var flashvars = {};
		var params = {};
		params.bgcolor = "#000000";
		params.allowfullscreen = "true";
		// note if you use this line, there are issues in IE7 (Microsoft...)
		//params.wmode = "transparent";
		flashvars.stageW = stageW;
		flashvars.stageH = stageH;
		flashvars.imagePath = "/SportKCImages/" + escape(parray[1]);
		flashvars.videoPath = parray[2] + '?t=' + cacheBuster;
		// you can also play h264 files, including .mov
		// make sure you comment the line above
		//flashvars.videoPath = "video.mov";
		flashvars.autoStart = autostart;
		flashvars.autoHide = "true";
		flashvars.autoHideTime = "3";
		flashvars.hideLogo = "true";
		flashvars.volAudio = "60";
		flashvars.disableMiddleButton = "false";
		flashvars.playSounds = "true";
		flashvars.soundBarColor = "0x00415C";
		flashvars.barColor = "0xffffff";
		flashvars.barShadowColor = "0x00415C";
		flashvars.subbarColor = "0xffffff";
		flashvars.extendVideo = "true";
		swfobject.embedSWF("/flvplayer/flvPlayer.swf?t="+cacheBuster, "videocontainer", stageW, stageH, "9.0.0", "/flvplayer/swfobject/expressInstall.swf", flashvars, params);
	}
	else
	{
		$('#imagediv').attr('style','background-image:url(/SportKCImages/' + escape(parray[3]) + ')');
		//$('#imagediv').find('#mainimage').attr('src','SportKCImages/' + parray[3]);
		$('#videodiv').hide();
		$('#imagediv').show();
	}
	$('.carousel_text').attr('style','background-color:' + parray[4]);
	$('.carousel_text').html($text.html());

}

