jQuery(document).ready(function() {

	// jw player flash vars
		function createPlayer() {
		
		var flashvars = {
		autostart: 'true',
		file: 'company/CEO Intro.mp4',
		backcolor: 'E2E2E2',
		frontcolor: '333333',
		lightcolor: '003D79',
		screencolor: 'FFFFFF',
		stretching: 'fill',
		controlbar: 'over',
		skin: 'flash/snel.swf'
		};
	
		var params = {
		allowfullscreen: 'true',
		allowscriptaccess: "always",
		wmode: "transparent",
		menu: 'false'
		};
	
		var attributes = {
			id: 'ceo',
			name: 'ceo'
		};
		
		swfobject.embedSWF("/flash/player.swf", "ceo", "669", "335", "9.0.0", "/flash/expressInstall.swf", flashvars, params, attributes);
		
		player = document.getElementById('ceo');
		
		}
	
	jQuery("li.watch a").click(function() {
	jQuery("div.hideClick").fadeOut(1500, function() {
		jQuery("div#ceoScreen").show();
		createPlayer();
		});
	return false;
	});
	
	jQuery("#ceoScreen a.close").click(function() {	
	closevid();
	return false;
	});


	/* OVERLAY OPEN CLOSE FUNCTION FOR MESSAGE */ 
	jQuery("a[rel=#ceoMessage]").overlay({
		expose: '#000'								 
	});

});
	
function playerReady(obj){
			//alert('the videoplayer '+obj['id']+' has been instantiated');
			addListeners();
}

function addListeners(){
	//alert('adding listeners');
        playlist = player.getPlaylist();

        if((playlist !== null) && (playlist !== undefined))
        {
          player.addModelListener('STATE', 'stateMonitor');
        }
        else
        {
          setTimeout("addListeners()", 100);
        }
	
}

function stateMonitor(obj){
	//alert(obj.newstate);
        if(obj.newstate == 'COMPLETED')
        {
			//alert('closing vid');
          closevid();
        }

}	

	function closevid() {
	jQuery("#ceoScreen").fadeOut(300, function() {
	player.sendEvent('STOP', 'true');
		
	jQuery("div.hideClick").fadeIn(1500);
    swfobject.removeSWF('ceo');
	jQuery("div#ceoScreen").append("<div id='ceo'>");
	});
	}
