

// Video Player ////////////////////////////////////////////////////////////////

loadVideo();

function loadVideo() {

	var flashvars = {
		file:'../videos/'+videoFile, 
		image:'../videos/posters/belfast.jpg',
		stretching:"fill",
		autostart:"false",
		smoothing:"true",
		controlbar:"over"
	}
	
	var params = {
		allowfullscreen:"true", 
		allowscriptaccess:"always",
		base:"flash/home/mediaplayer/",
		wmode:"transparent"
	}
	
	var attributes = {
		id:"player",  
		name:"player"
	}

	swfobject.embedSWF("flash/home/mediaplayer/player.swf", "player", "512", "288", "9", false, flashvars, params, attributes);
	
}

var player = null;
var current_vid = 1;


function stateMonitor(obj)
	{
		if(obj.newstate == 'COMPLETED')
		{
			player.sendEvent('STOP');
			switch(current_vid) {
				case 1: $("#vid-dublin").click(); break;
				case 2: $("#vid-galway").click(); break;
				case 3: $("#vid-belfast").click(); break;
			}
		}
};


function playerReady(thePlayer) {
	player = window.document[thePlayer.id];
	addListeners();
}

function addListeners() {
	if (player) {
		player.addModelListener('STATE', 'stateMonitor');
	} 
	else {
		setTimeout("addListeners()",100);
	}
}


///// OPEN / CLOSE VIDEO OVERLAY ////////////////////////////////////////

function init_Homepage_Vids() {
	
	function openVideo() {
		$(".video-container").fadeIn(function() {
			player.sendEvent('PLAY');
		});
	}
	function closeVideo() {
		player.sendEvent('STOP');
		$(".video-container").fadeOut();
	}
	 
	$('#open-video').click(function (e) {
		e.preventDefault();
		openVideo();
	});
	
	$('a.modalCloseImg').click(function (e) {
		e.preventDefault();
		closeVideo();
	});
	$("#overlay").click(function () {
		closeVideo();
	});
	
	$("#vid-belfast").click(function () {
		current_vid = 1;
		player.sendEvent('STOP');
		player.sendEvent('LOAD',{file:'../videos/tourisme_belfast20_169_irish_modif_060510_MPEG1_finalcut_169.flv',image:'../videos/posters/belfast.jpg'});
		player.sendEvent('PLAY');
		$('.video-nav a').removeClass('selected');
		$(this).addClass('selected');
	});
	
	$("#vid-dublin").click(function () {
		current_vid = 2;
		player.sendEvent('STOP');
		player.sendEvent('LOAD',{file:'../videos/tourisme_dublin20_169_irish_modif_060510_MPEG1_finalcut_169.flv',image:'../videos/posters/dublin.jpg'});
		player.sendEvent('PLAY');
		$('.video-nav a').removeClass('selected');
		$(this).addClass('selected');
	});

	$("#vid-galway").click(function () {
		current_vid = 3;
		player.sendEvent('STOP');
		player.sendEvent('LOAD',{file:'../videos/tourisme_galway20_169_irish_modif_060510_MPEG1_finalcut_169.flv',image:'../videos/posters/galway.jpg'});
		player.sendEvent('PLAY');
		$('.video-nav a').removeClass('selected');
		$(this).addClass('selected');
	});
	

}
