// detect the version of Flash install
function getFlashVersion(){
	
	// ie
	try {
		try {
			// avoid fp6 minor version lookup issues
			var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
			try { 
				axo.AllowScriptAccess = 'always';
			} catch(e) {
				return '6,0,0';
			}
		} catch(e) {}
		return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
		// other browsers
	} catch(e) {
		try {
			if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
				return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
			}
		} catch(e) {}
	}
	return '0,0,0';
	
}

$(function() {
	
	// remove native embedded Flash object
	$('#nojsvideo').before('<video id="videobg" height="100%" width="100%"></video>').remove();
	
	var version = getFlashVersion().replace(/,/g,'.');
	version = parseFloat(version);
	if (version >= 9.0) {
		
		playlist = [
			{file: 'http://rapierec2.regenhosting.co.uk/cam1.flv', provider: 'http', 'http.startparam': 'starttime'},
			{file: 'http://rapierec2.regenhosting.co.uk/cam2.flv', provider: 'http', 'http.startparam': 'starttime'},
			{file: 'http://rapierec2.regenhosting.co.uk/cam3.flv', provider: 'http', 'http.startparam': 'starttime'},
			{file: 'http://rapierec2.regenhosting.co.uk/cam4.flv', provider: 'http', 'http.startparam': 'starttime'},
			{file: 'http://rapierec2.regenhosting.co.uk/cam5.flv', provider: 'http', 'http.startparam': 'starttime'},
			{file: 'http://rapierec2.regenhosting.co.uk/cam6.flv', provider: 'http', 'http.startparam': 'starttime'}
		];	
		
		// setup JW Player
		if (typeof(jwplayer) != 'undefined') {
			jwplayer('videobg').setup({
				flashplayer: 'player.swf',
				playlist: playlist,
				height: '100%',
				width: '100%',
				autostart: 'true',
				stretching: 'fill',
				controlbar: 'none',
				plugins: "clickproxy",
				wmode: "opaque"
			})
		}

	} else {
		
		$('#noflash').html('<p>Sorry, but you much have at least Flash 9.0 or above to view our streams.<br /><a href="http://get.adobe.com/flashplayer/">You can download the latest version of Flash here</a></p>');2
		
	}
	
			
	// toggle background cam image
	$('#controls li a').click(function() {
		var camToggle = $(this);
		var camIndex = $('#controls li a').index(camToggle);
		
		$('#controls li a').removeClass('current');
		camToggle.addClass('current');
		
		jwplayer('videobg').playlistItem(camIndex);

		return false;
	});	
	
	// social link hover
	$('#social li a').hover(function() {
		$(this).next('.popup').stop().animate({top: '-96px'}, {queue:false, duration: 300});										
	}, function() {
		$(this).next('.popup').stop().animate({top: '0px'}, {queue:false, duration: 300});	
	});
						  
});
