

// Video Player ////////////////////////////////////////////////////////////////

loadVideo();

function loadVideo() {

	var flashvars = {
		file:'../../../videos/insider/Golf.flv',
		image:'../../../videos/insider/golf-poster.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", "video", "430", "241", "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-hill").click(); break;
				case 2: $("#vid-fish").click(); break;
				case 3: $("#vid-food").click(); break;
				case 4: $("#vid-surf").click(); break;
				case 5: $("#vid-golf").click(); break;
			}
		}
};


function playerReady(thePlayer) {
	player = window.document[thePlayer.id];
	addListeners();
	player.sendEvent('PLAY');
	
}

function addListeners() {
	if (player) {
		player.addModelListener('STATE', 'stateMonitor');
	} 
	else {
		setTimeout("addListeners()",100);
	}
}


///// OPEN / CLOSE VIDEO OVERLAY ////////////////////////////////////////

function init_Reason_Vids() {
	
	$("#vid-golf").click(function () {
		current_vid = 1;
		player.sendEvent('STOP');
		player.sendEvent('LOAD',{file:'../../../videos/insider/Golf.flv',image:'../../../videos/insider/golf-poster.jpg'});
		player.sendEvent('PLAY');
		$('.video-playlist a').removeClass('selected');
		$(this).addClass('selected');
		$('.video-playlist li div.wedge').remove();
		$(this).before('<div class="wedge"></div>');
		$("p.title").text("Insiders Guide to Golfing in Ireland");
		$("p.subtitle").text("Joe Bedford - Course Designer & Pro-golfer");
	});
	
	$("#vid-hill").click(function () {
		current_vid = 2;
		player.sendEvent('STOP');
		player.sendEvent('LOAD',{file:'../../../videos/insider/Hill.flv',image:'../../../videos/insider/hillwalking-poster.jpg'});
		player.sendEvent('PLAY');
		$('.video-playlist a').removeClass('selected');
		$(this).addClass('selected');
		$('.video-playlist li div.wedge').remove();
		$(this).before('<div class="wedge"></div>');
		$("p.title").text("Hill Walking in Ireland - Insider tips and great locations");
		$("p.subtitle").text("Alun Richardson - Expert Mountaineer and Author");
	});

	$("#vid-fish").click(function () {
		current_vid = 3;
		player.sendEvent('STOP');
		player.sendEvent('LOAD',{file:'../../../videos/insider/Angling.flv',image:'../../../videos/insider/angling-poster.jpg'});
		player.sendEvent('PLAY');
		$('.video-playlist a').removeClass('selected');
		$(this).addClass('selected');
		$('.video-playlist li div.wedge').remove();
		$(this).before('<div class="wedge"></div>');
		$("p.title").text("Tips to make the best out of your Angling trip to Ireland");
		$("p.subtitle").text("Dave Houghton - Journalist and Expert Angler");
	});
	
	$("#vid-food").click(function () {
		current_vid = 4;
		player.sendEvent('STOP');
		player.sendEvent('LOAD',{file:'../../../videos/insider/Food.flv',image:'../../../videos/insider/food-poster.jpg'});
		player.sendEvent('PLAY');
		$('.video-playlist a').removeClass('selected');
		$(this).addClass('selected');
		$('.video-playlist li div.wedge').remove();
		$(this).before('<div class="wedge"></div>');
		$("p.title").text("Great Food from Across Ireland");
		$("p.subtitle").text("Margaret Jeffares - Food expert and MD of Good Food Ireland");
	});
	
	$("#vid-surf").click(function () {
		current_vid = 5;
		player.sendEvent('STOP');
		player.sendEvent('LOAD',{file:'../../../videos/insider/Surf.flv',image:'../../../videos/insider/surfing-poster.jpg'});
		player.sendEvent('PLAY');
		$('.video-playlist a').removeClass('selected');
		$(this).addClass('selected');
		$('.video-playlist li div.wedge').remove();
		$(this).before('<div class="wedge"></div>');
		$("p.title").text("Surfing in Ireland - All you need to know");
		$("p.subtitle").text("Stuart Green - Surf school owner and Instructor");
	});
	

}


jQuery(document).ready(function($) {
	
	init_Reason_Vids();
	
});

