var adminscript = 'zones/videoadmin.cfm';

$(document).ready(function() {
	if (!isHTML5VideoSupported() && pluginlist.indexOf("Flash")==-1) {$('.cmsVideo').html('Flash is not installed.  You need Adobe Flash to view this page.  Please go to: http://www.adobe.com/go/getflashplayer<br/><a href="javascript:location.reload();">Close</a>')}
});

isHTML5VideoSupported = function() {
    return (typeof HTMLVideoElement != 'undefined');
}


zoneSettings = function() {
    $.ajax({
        type: "POST",
        url: cmshomepath + adminscript,
        data: "action=zonesettings&zoneid="+ zoneid,
        success: function(msg){
        	$('#'+dialogWindowName).html(msg);
        	//$('#'+dialogWindowName).dialog('close');
        	//skinIt($('#settingsForm'));
        	$('button').button();
        	skinIt($('#settingsForm'));
        	return false;
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
        	alert(errorThrown+'--'+textStatus);
        	return false;
        }
    });
};
zoneSettingsSubmit = function(){
    var postData = $('#settingsForm').serialize();
    $.ajax({
        type: "POST",
        url: cmshomepath + adminscript,
        data: "action=zonesettingssubmit&zoneid="+ zoneid +"&"+postData,
        success: function(msg){
        	$('#'+dialogWindowName).html(msg);
        	$('button').button();
        	//$('#'+dialogWindowName).dialog('close');
        	//skinIt($('#settingsForm'));
        	return false;
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
        	alert(errorThrown+'--'+textStatus);
        	return false;
        }
    });
    return false;
};

vtypeCheck = function() {
	thistype = $('#vtype').val();
	if (thistype == 'youtube') {
		//window.alert('YouTube videos not available yet.  Coming soon.');
		//return false;
		$('.local').hide();
		$('.youtube').show();
	}
	if (thistype == 'local') {
		$('.youtube').hide();
		$('.local').show();
	}
}

launchVideo = function(videoid,width,height) {
	$('#video'+videoid).dialog({
		modal:true,
		width:parseInt(width)+24,
		height:parseInt(height)+56,
		close: function() {
			//$(this).html('');
		},
		open: function() {
			var delay = function() { playVideo(videoid); };
			setTimeout(delay,2000); 
			//playVideo(videoid);
		}
	});
	$('.cmsVideo').siblings('.ui-dialog-titlebar').hide();
}

playVideo = function(videoid,width,height) {
		$('#posterlink'+videoid).hide();
		if (width) $('#video'+videoid).css('width',width+'px').css('height',height+'px');
		var html5video = document.getElementById('embeddedvideo'+videoid);
		if(isHTML5VideoSupported() && html5video.play) {
			html5video.play();
			}
		else if (document.getElementById("videoplayer"+videoid)) {ColdFusion.Mediaplayer.startPlay("videoplayer"+videoid)};
};

closeVideo = function(videoid) {
	if (navigator.appVersion.indexOf("MSIE") != -1) {   //prevents a bug where CF media player is unable to stop a second time in IE.
		location.reload(true);
	}
	else {
		var html5video = document.getElementById('embeddedvideo'+videoid);
		if(html5video.pause) html5video.pause();
		if(document.getElementById("videoplayer"+videoid)) {ColdFusion.Mediaplayer.stopPlay("videoplayer"+videoid)};
		$('#video'+videoid).dialog("close");
	}
};

clearPoster = function() {
	$('#cmsCurrentPoster').html('');
	$('#vposter').val('');
};

//plugin Detection
var agt=navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var ns  = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);

if (ie && win) {	pluginlist = detectIE("Adobe.SVGCtl","SVG Viewer") + detectIE("SWCtl.SWCtl.1","Shockwave Director") + detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") + detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer") + detectIE("QuickTimeCheckObject.QuickTimeCheck.1","QuickTime") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player") + detectIE("PDF.PdfCtrl.5","Acrobat Reader"); }
if (ns || !win) {
		nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
		pluginlist = detectNS("image/svg-xml","SVG Viewer") + detectNS("application/x-director","Shockwave Director") + detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("audio/x-pn-realaudio-plugin","RealPlayer") + detectNS("video/quicktime","QuickTime") + detectNS("application/x-mplayer2","Windows Media Player") + detectNS("application/pdf","Acrobat Reader");
}

function detectIE(ClassID,name) { result = false; document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n'); if (result) return name+','; else return ''; }
function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }

pluginlist += navigator.javaEnabled() ? "Java," : "";
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);

//SAMPLE USAGE- detect "Flash"
//if (pluginlist.indexOf("Flash")!=-1)
//document.write("You have flash installed")


