		jQuery.cookie = function(name, value, options) {
			if (typeof value != 'undefined') { // name and value given, set cookie
				options = options || {};
				if (value == null) {
					value = '';
					options.expires = -1;
				}
				var expires = '';
				if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
					var date;
					if (typeof options.expires == 'number') {
						date = new Date();
						date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
					} else {
						date = options.expires;
					}
					expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
				}
				// CAUTION: Needed to parenthesize options.path and options.domain
				// in the following expressions, otherwise they evaluate to undefined
				// in the packed version for some reason...
				var path = options.path ? '; path=' + (options.path) : '';
				var domain = options.domain ? '; domain=' + (options.domain) : '';
				var secure = options.secure ? '; secure' : '';
				document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
			} else { // only name given, get cookie
				var cookieValue = null;
				if (document.cookie && document.cookie != '') {
					var cookies = document.cookie.split(';');
					for (var i = 0; i < cookies.length; i++) {
						var cookie = jQuery.trim(cookies[i]);
						// Does this cookie string begin with the name we want?
						if (cookie.substring(0, name.length + 1) == (name + '=')) {
							cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
							break;
						}
					}
				}
				return cookieValue;
			}
		};

			$(document).ready(function() { 
				$("a[name~='download']").click(function(){
					var linkHREF = $(this).attr('href');
					if ($.cookie('agree_policy') == null) {
						$("#agreeTerms").show('fast', function(){
							$("#agreeTwo").show();
						});
					} else {
						return true;
					}
					$('#agree-terms').click(function(){
						if ($('#agree:checked').val() == '1') {
							$.cookie('agree_policy', 'true');
							window.location = '/harrypotter/'+linkHREF;
							return true;
						} else {
							window.alert('You must agree to the terms before proceeding');
							return false;
						}
					})
					return false;
				});
				$("#close-box").click(function(){
					$("#agreeTwo").hide('fast');
					$("#agreeTerms").hide('fast');
				});
			});


var player = null;
var currentItem = 0;
var fileLink = 0;



function stopPlayer()
{
	player = gid("mpl");
	player.sendEvent("PLAY","false");
}


function playerReady(obj)
{
player = gid(obj.id);

player.addControllerListener('ITEM', 'itemMonitor');
player.addModelListener('STATE', 'stateMonitor');
};

function itemMonitor(obj)
{
currentItem = obj.index;
};

function stateMonitor(obj)
{
	if(obj.newstate == 'PLAYING')
	{
		var playlist = player.getPlaylist();
		gid('title').innerHTML = playlist[currentItem]['title'];
		gid('captionTitle').innerHTML = playlist[currentItem]['title'];
		gid('downloadLink').href = playlist[currentItem]['link'];
		gid('downloadLink2').href = playlist[currentItem]['file'];
	}
};



function gid(name)
{
return document.getElementById(name);
};


