var swfWidth = 640;
var swfHeight = 508;
var movWidth = 480;
var movHeight = 375;

function isiOSDevice() {
	if(navigator.userAgent.match(/iPhone/i)) {
		return true;
	}
	if(navigator.userAgent.match(/iPod/i)) {
		return true;
	}
	if(navigator.userAgent.match(/iPad/i)) {
		return true;
	}
	return false;
}

function detectExplorer() {
	if(navigator.userAgent.match(/MSIE/i)) {
		return true;
	}
	if(navigator.userAgent.match(/Explorer/i)) {
		return true;
	}
	return false;
}

function determineContent(flaHTML, iHTML, altHTML, targetDIV) {
	if(DetectFlashVer(9,0,0)==true) {
		$('div.'+targetDIV).html(''+flaHTML);
	} else if(isiOSDevice()==true) {
		$('div.'+targetDIV).html(''+iHTML);
	} else {
		$('div.'+targetDIV).html(''+altHTML);
	}
}

function useH264(s) {
    $('div.movieContainer')
    	.css('width', movWidth)
    	.css('height', movHeight)
    	.html('<object width="'+movWidth+'" height="'+movHeight+
    	+'" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"'
    	+' codebase="http://www.apple.com/qtactivex/qtplugin.cab">'
    	+'<param name="src" value="media/movie/'+s+'.m4v"/>'
    	+'<param name="autoplay" value="false"/>'
    	+'<param name="controller" value="true"/>'
    	+'<embed src="media/movie/'+s+'.m4v" width="'+movWidth+'" height="'+movHeight
    	+'" autoplay="false" controller="true" '
    	+'type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/">'
    	+'</embed></object>');
	 
}

function useFlash(s) {
    if(detectExplorer()==true) {
    	$('div.movieContainer')
    	.css('width', swfWidth)
    	.css('height', swfHeight)
    	.html('<embed src="videoPlayback.swf" width="'+swfWidth+'" height="'+swfHeight+'"'
    	+'allowFullscreen="true"'
    	+'flashVars="url=media/movie/'+s+'.m4v"'
    	+'wmode="window">'
    	+'</embed>');
    } else {
    	$('div.movieContainer')
    	.css('width', swfWidth)
    	.css('height', swfHeight)
    	.html('<object width="'+swfWidth+'" height="'+(swfHeight)+'" '
    	+'type="application/x-shockwave-flash" data="videoPlayback.swf">'
    	+'<param name="movie" value="videoPlayback.swf"/>'
    	+'<param name="flashVars" value="url=media/movie/'+s+'.m4v"/>'
    	+'<param name="allowfullscreen" value="true"/>'
    	+'<param name="wmode" value="window"/>'
    	+'</object>'
    );
    }
}

function playMovie(s) {
    if(DetectFlashVer(9,0,0)==false) {
		useH264(s+'.m4v');
    } else {
		useFlash(s);
    }
}

function setSwfSize(w, h) {
	swfWidth = w;
	swfHeight = h+28;
}

function setMovSize(w, h) {
	movWidth = w;
	movHeight = h+15;
}
