// JavaScript Document

function videoNav(vidNum,vidPart) {
	    var newVideo = "";

        if (endsWith(vidPart, '.flv')) {
	        newVideo = "<object id=\"vid\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" width=\"370\" height=\"298\" title=\"VideoPlayer\"><param name=\"movie\" value=\"player.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"flashvars\" value=\"file=/images/asSeenOn/" + vidPart + "&autostart=true\" /><embed id=\"vid\" src=\"player.swf\" quality=\"high\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" flashvars=\"file=/images/asSeenOn/" + vidPart + "&autostart=true\" width=\"370\" height=\"298\"></embed></object>";

	        if ($("#flashvideo_wrapper").length > 0) {
	            $("#flashvideo").remove();
	            $("#flashvideo_wrapper").attr("id", "flashvideo");
	        }

	        $("#flashvideo").html(newVideo);
        }
        else if (endsWith(vidPart, '.wmv')) {            
            newVideo = "<object id=\"MediaPlayer\" width=494 height=278 classid=\"clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6\" standby=\"Loading Windows Media Player components...\" type=\"application/x-ms-wmp\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112\"><param name=\"URL\" value='/images/asSeenOn/" + vidPart + "'><param name=\"Showcontrols\" value=\"True\"><param name=\"autoStart\" value=\"True\"><param name=\"cache\" value=\"false\"><param name=\"stretchToFit\" value=\"0\"><param name=\"targetcache\" value=\"false\"><embed cache=\"false\" targetcache=\"false\" stretchToFit=\"0\" autoplay=\"true\" type=\"application/x-ms-wmp\" src='/images/asSeenOn/" + vidPart + "' name=\"MediaPlayer\" width=494 height=278></embed></object>";

            if ($("#flashvideo_wrapper").length > 0) {
                $("#flashvideo").remove();
                $("#flashvideo_wrapper").attr("id", "flashvideo");
            }

            $("#flashvideo").html(newVideo);
        }
        else if (endsWith(vidPart, '.3gp')) {
            if (DetectHTML5Stream()) {
                $("#flashvideo").append("<video src=\"http://cloud.relentlesstechnology.net:80/vod/_definst_/btv/includes/clips/asseenon/mp4:" + vidPart + "/playlist.m3u8\" height=\"160\" poster=\"/images/2011/videoplayer_sml.jpg\" controls=\"controls\" width=\"285\"></video>");
            } 
            else if (DetectSmartPhone()) {
                $("#flashvideo").append("<a href=\"rtsp://cloud.relentlesstechnology.net:554/vod/_definst_/btv/includes/clips/asseenon/mp4:" + vidPart + "\"><img src=\"/images/2011/videoplayer_sml.jpg\"></a>");
            }
            else {
                jwplayer("flashvideo").setup({
                    file: "btv/includes/clips/asseenon/mp4:" + vidPart + "",
                    streamer: 'rtmp://cloud.relentlesstechnology.net:80/vod/',
                    flashplayer: "/swf/player-licensed.swf",
                    autostart: false,
                    skin: "/swf/player-skin.swf",
                    stretching: 'none',
            		screencolor: 'ffffff',
            		image: '/images/2011/videoplayer.jpg',
                    controlbar: 'over',
                    'controlbar.idlehide': true,
                    icons: false,
                    width: 640,
                    height: 360,
                    plugins: {
                        "/swf/action_call.swf": {}
 
                    },
                    "action_call.media": "/images/2011/videoplayer.jpg"
                });
 
                var videoInit = false;
 
                jwplayer("flashvideo").onPlay(
			        function (event) {
			            if (videoInit == false) {
			                _gaq.push(['_trackEvent', 'Video Player', 'Episodes', 'Play']);
			                videoInit = true;
			            }
			        }
		        );
 
                var clickArray = new Object();
 
                function flash_Clicktag(id) {
                    var clickTag = clickArray[id];
                }
	        }
        }
		
    }
	
	var x = 0;
	var timer;
	function startRotate(withWhat) {
		var img = document.getElementById("homeflash");
		img.className = "homeflash" + withWhat;
		timer = setInterval('rotate()',3000);
	}
	
	function rotate() {
		var img = document.getElementById("homeflash");
		var theClass = img.className;
		x = theClass.charAt(9);
		if(x<5){
			x++;
		} else {
			x = 0;
		}
		img.className = "homeflash" + x;
	}
	function jumpRotate(toWhat) {
		clearInterval(timer);
		var img = document.getElementById("homeflash");
		img.className = "homeflash" + toWhat;
		timer = setInterval('rotate()',5000);
	}

function endsWith(str, suffix) 
{
    return str.indexOf(suffix, str.length - suffix.length) !== -1; 
}
