/**
 * Magic Dragon UK Ltd Javascript Library
 * Copyright 2011 Lamped.co.uk
 * Copyright 2011 Magic Dragon UK Ltd
 *
 * @version 2011-04-14
 * @author Marc Gray support@lamped.co.uk
 */

lecClient.onReady(function() {
	// Browser specific fixes. Oh look, it's just IE.
	if (lecClient.isIE == 6)
		$('#content').append('<div style="height: '+ (1300-parseInt($('#content').height())) +';">');

	// Apply prettyPhoto
	$("a[rel^='prettyPhoto']").prettyPhoto({'overlay_gallery': false});

	// Alert Box
	$('input[name=mdt-alert-proceed]').attr('disabled', true);
	$('input[name=mdt-alert-understand]').click(function() {
		if ($(this).is(':checked')) {
			$('input[name=mdt-alert-proceed]').removeAttr('disabled');
			$(this).next().remove();
			$(this).remove();
		}
	});
	$('input[name=mdt-alert-proceed]').click(function() {
		$('#mdt-alert').fadeOut(1500, function() { $('#mdt-alert').remove(); });
		lecClient.flashResume();
	});

	// Stop and delay index video
	if ($('.mdt-video-background video').length) {
		var video = $('.mdt-video-background video')[0];
		if (video.pause) {
			video.pause();
			setTimeout(function() { $('.mdt-video-background video')[0].play(); }, 5000);
		}
	}
});

lecClient.onFlashReady(function() {
	// Apply flash banner
	swfobject.embedSWF('/inc/flash/magicdragonbanner.swf', 'mdt-banner', 768, 80, '9.0.115', {}, {'wmode': 'transparent'});

	// Apply flash video
	$('.mdt-js-flashvideo').each(function() {
		var id = $(this).attr('id');
		var width = $(this).attr('data-width');
		var height = $(this).attr('data-height');
		var video = $(this).attr('data-video');
		var autoplay = $(this).attr('data-auto');
		swfobject.embedSWF(
			'/inc/flash/player.swf',
			id,
			width,
			height,
			'9.0.115',
			false,
			{
				file: video,
				image: video,
				title: "Video",
				autostart: autoplay == 1
			},
			{
				allowfullscreen: "true",
				allowscriptaccess: "always"
			},
			{}
		);
	});
});
