/*jslint white: true, browser: true, onevar: true, undef: true, nomen: false, eqeqeq: true, plusplus: false, bitwise: true, regexp: true, newcap: true, immed: true*/
/*global window: true, DrVideo: true, version: true, ActiveXObject: true, console: true, $f: true*/
if (typeof DrVideo !== 'object') {
	DrVideo = {};
}
DrVideo.API = {
	execute: function (command, parentElement, parameters) {
		var D = DrVideo, position = D._tools.getPosition(parentElement);
		if (position && typeof D._actions[command] === 'function') {
			return D._actions[command](position, parameters);
		}
		return false;
	},
	load: function (id) {
		return DrVideo._actions.load(id);
	},
	play: function (id, parentElement, optionsObject) {
		return DrVideo.API.execute('play', parentElement, {id: id, optionsObject: optionsObject});
	},
	pause: function (parentElement) {
		return DrVideo.API.execute('pause', parentElement);
	},
	resume: function (parentElement) {
		return DrVideo.API.execute('resume', parentElement);
	},
	togglePause: function (parentElement) {
		return DrVideo.API.execute('togglePause', parentElement);
	},
	isPaused: function (parentElement) {
		return DrVideo.API.execute('isPaused', parentElement);
	},
	seek: function (milliseconds, parentElement) {
		return DrVideo.API.execute('seek', parentElement, milliseconds);
	},
	getVolume: function (parentElement) {
		return DrVideo.API.execute('getVolume', parentElement);
	},
	setVolume: function (newVolume, parentElement) {
		return DrVideo.API.execute('setVolume', parentElement, newVolume);
	},
	mute: function (parentElement) {
		return DrVideo.API.execute('mute', parentElement);
	},
	unmute: function (parentElement) {
		return DrVideo.API.execute('unmute', parentElement);
	},
	toggleMute: function (parentElement) {
		return DrVideo.API.execute('toggleMute', parentElement);
	},
	isMuted: function (parentElement) {
		return DrVideo.API.execute('isMuted', parentElement);
	},
	getActive: function (parentElement) {
		return DrVideo.API.execute('getActive', parentElement);
	},
	getCurrentTime: function (parentElement) {
		return DrVideo.API.execute('getCurrentTime', parentElement);
	},
	destroy: function (parentElement) {
		return DrVideo.API.execute('destroy', parentElement);
	},
	next: function (parentElement) {
		return DrVideo.API.execute('next', parentElement);
	},
	previous: function (parentElement) {
		return DrVideo.API.execute('previous', parentElement);
	},
	isLoaded: function (id) {
		return DrVideo._tools.isLoaded(id);
	},
	getMeta: function (id) {
		if (DrVideo._tools.isLoaded(id)) {
			return DrVideo._tools.getMeta(id);
		}
		return false;
	},
	getIndexes: function (id) {
		if (DrVideo._tools.isLoaded(id)) {
			return DrVideo._tools.getIndexes(id);
		}
		return false;
	},
	getFormats: function (id) {
		return DrVideo._tools.getFormats(id);
	},
	addCallback: function (eventName, callbackFunction, parentElement) {
		var D = DrVideo, C = D._callbacks, position;
		if (!(typeof eventName === 'string' && eventName.length > 0 && typeof C.events[eventName] === 'object' && typeof callbackFunction === 'function')) {
			return false;
		}
		if (typeof parentElement === 'undefined') {
			return C.addGlobalCallback(eventName, callbackFunction);
		}
		position = D._tools.getPosition(parentElement);
		if (!position) {
			return false;
		}
		return C.addPositionCallback(eventName, callbackFunction, position);
	}
};
DrVideo._callbacks = {
	events: {
		error: {
			functions: []
		},
		videoLoaded: {
			globalOnly: true,
			functions: []
		},
		loadedMetadata: {
			functions: []
		},
		timeUpdate: {
			functions: []
		},
		volumeUpdate: {
			functions: []
		},
		play: {
			functions: []
		},
		noDecoderAvailable: {
			functions: []
		},
		ended: {
			functions: []
		},
		pause: {
			functions: []
		},
		resume: {
			functions: []
		}
	},
	fireEvent: function (eventName, callbackData, position) {
		var i, iMax, j, jMax;
		if (typeof position === 'object' && typeof position.callbacks[eventName] === 'object') {
			for (i = 0, iMax = position.callbacks[eventName].length; i < iMax; i++) {
				try {
					position.callbacks[eventName][i](callbackData);
				} catch (e1) {}
			}
		}
		for (j = 0, jMax = DrVideo._callbacks.events[eventName].functions.length; j < jMax; j++) {
			try {
				DrVideo._callbacks.events[eventName].functions[j](callbackData);
			} catch (e2) {}
		}
		return true;
	},
	addGlobalCallback: function (eventName, callbackFunction) {
		var C = DrVideo._callbacks, existing = false, i, iMax;
		for (i = 0, iMax = C.events[eventName].functions.length; i < iMax; i++) {
			if (C.events[eventName].functions[i] === callbackFunction) {
				existing = true;
				break;
			}
		}
		if (!existing) {
			C.events[eventName].functions.push(callbackFunction);
		}
		return true;
	},
	addPositionCallback: function (eventName, callbackFunction, position) {
		var PC = position.callbacks, i, iMax;
		if (!PC[eventName]) {
			PC[eventName] = [callbackFunction];
			return true;
		}
		for (i = 0, iMax = PC[eventName].length; i < iMax; i++) {
			if (PC[eventName][i] === callbackFunction) {
				return true;
			}
		}
		PC[eventName].push(callbackFunction);
		return true;
	}
};
DrVideo._loaders = {
	videosLoading: {},		
	loadVideo: function (id, position) {
		var L = DrVideo._loaders.videosLoading;
		if (typeof L['v' + id] !== 'object') {
			L['v' + id] = [];
			DrVideo._tools.request('videostatus/?id=' + id + '&callback=DrVideo._loaders.videoLoaded');
		}
		if (position) {
			L['v' + id][L['v' + id].length] = position.id;
		}
		return true;
	},
	videoLoaded: function (data) {
		if (!(typeof data === 'object' && data && typeof data.id === 'number')) {
			return;
		}
		var D = DrVideo, V = D._videos, VL, P, VP, i, iMax;
		if (!(typeof V['v' + data.id] === 'object' && V['v' + data.id] && typeof V['v' + data.id].formats === 'object')) {
			V['v' + data.id] = data;
		}
		try {
			D._callbacks.fireEvent('videoLoaded', {videoId: data.id, status: typeof data.status === 'number' ? data.status : null});
		} catch (e) {}
		VL = D._loaders.videosLoading;
		if (typeof VL['v' + data.id] === 'object') {
			P = D._positions;
			VP = VL['v' + data.id];
			for (i = 0, iMax = VP.length; i < iMax; i++) {
				if (typeof P[VP[i]] === 'object' && P[VP[i]].loadingId === data.id) {
					D._actions.play(P[VP[i]], {id: data.id});
				}
			}
		}
	},
	loadPlaylist: function (ids, position) {
		var playlistName = position.decoder.playlistFormat + '-' + position.format.protocol + '-' + position.format.mime, V = DrVideo._videos, WV, playlistsRequired = [], i, iMax;
		if (typeof ids === 'number') {
			ids = [ids];
		}
		for (i = 0, iMax = ids.length; i < iMax; i++) {
			if (!(typeof V['v' + ids[i]] === 'object' && V['v' + ids[i]])) {
				V['v' + ids[i]] = {};
			}
			WV = V['v' + ids[i]];
			if (typeof WV.playlistsLoading !== 'object') {
				WV.playlistsLoading = {};
			}
			if (typeof WV.playlistsLoading[playlistName] !== 'object') {
				WV.playlistsLoading[playlistName] = [];
			}
			WV.playlistsLoading[playlistName].push(position.id);
			playlistsRequired.push(ids[i]);
		}
		if (playlistsRequired.length > 0) {
			DrVideo._tools.request('playlist/' + position.decoder.playlistFormat + '/?id=' + playlistsRequired.toString() + '&protocol=' + position.format.protocol + '&mime=' + position.format.mime);
		}
		return true;
	},
	playlistLoaded: function (data) {
		if (!(typeof data === 'object' && data)) {
			return;
		}
		var V = null, playlistName = null, P = DrVideo._positions, PL = null, WP = null, positionsLoadingObject = {}, positionsLoading = [], i, iMax, j, jMax, k, kMax;
		for (i = 0, iMax = data.length; i < iMax; i++) {
			V = DrVideo._videos['v' + data[i].id];
			if (typeof V.playlists !== 'object') {
				V.playlists = {};
			}
			playlistName = data[i].format + '-' + data[i].protocol + '-' + data[i].mime;
			if (typeof V.playlists[playlistName] !== 'object') {
				V.playlists[playlistName] = data[i].playlist;
			}
			if (typeof V.playlistsLoading === 'object' && typeof V.playlistsLoading[playlistName] === 'object') {
				PL = V.playlistsLoading[playlistName];
				for (j = 0, jMax = PL.length; j < jMax; j++) {
					WP = P[PL[j]];
					if (typeof WP === 'object' && WP.loadingId === data[i].id && WP.decoder.playlistFormat === data[i].format && WP.format.protocol === data[i].protocol && WP.format.mime === data[i].mime) {
						if (!positionsLoadingObject[WP.id]) {
							positionsLoadingObject[WP.id] = true;
							positionsLoading.push(WP.id);
						}
					}
				}
			}
		}
		if (positionsLoading.length > 0) {
			for (k = 0, kMax = positionsLoading.length; k < kMax; k++) {
				DrVideo._actions.play(P[positionsLoading[k]]);
			}
		}
		return;
	},
	loadAds: function (id) {
		
	},
	adLoaded: function (data) {
		
	}
};
DrVideo._actions = {
	load: function (id) {
		id = DrVideo._tools.getInt(id);
		if (!id) {
			return false;
		}
		if (DrVideo._tools.isLoaded(id)) {
			return true;
		}
		return DrVideo._loaders.loadVideo(id);
	},
	play: function (position, parameters) {
		var id = null, settings = {}, O, C = DrVideo._callbacks, eventName, V = DrVideo._videos, LV, decoder, playlistName, dimensions;
		if (parameters) {
			id = DrVideo._tools.getInt(parameters.id);
			if (typeof parameters.optionsObject === 'object' && parameters.optionsObject) {
				O = parameters.optionsObject;
				for (eventName in C.events) {
					if (typeof O[eventName + 'Callback'] === 'function') {
						if (C.events[eventName].globalOnly) {
							C.addGlobalCallback(eventName, O[eventName + 'Callback']);
						} else {
							C.addPositionCallback(eventName, O[eventName + 'Callback'], position);
						}
					}
				}
				if (typeof O.desiredWidth === 'number' && O.desiredWidth > 0) {
					settings.desiredWidth = O.desiredWidth;
				}
				if (typeof O.startOffset === 'number') {
					O.startOffset = DrVideo._tools.getInt(O.startOffset);
					if (O.startOffset > 0) {
						position.startOffset = O.startOffset;
					}
				}
				if (typeof O.custom === 'object' && O.custom) {
					settings.custom = O.custom;
				}
				if (typeof O.autoplay === 'boolean' && !O.autoplay) {
					settings.autoplay = false;
				}
				position.settings = settings;
			}
		}
		if (!id) {
			if (typeof position.loadingId === 'number') {
				id = position.loadingId;
			} else {
				return false;
			}
		}
		if (position.loadingId !== id) {
			position.loadingId = id;
			position.loadingPlayQueue = [id];
			position.decoder = null;
			position.format = null;
		}
		if (!(typeof V['v' + id] === 'object' && V['v' + id] && typeof V['v' + id].formats === 'object')) {
			return DrVideo._loaders.loadVideo(id, position);
		}
		LV = V['v' + id];
		decoder = DrVideo._tools.getDecoder(LV.formats, position);
		if (!decoder) {
			DrVideo._callbacks.fireEvent('noDecoderAvailable', {}, position);
			return false;
		}
		position.decoder = decoder.decoder;
		position.format = {
			protocol: decoder.protocol,
			mime: decoder.mime,
			file: decoder.file
		};
		playlistName = position.decoder.playlistFormat + '-' + position.format.protocol + '-' + position.format.mime;
		dimensions = DrVideo._tools.getDimensions(position.dom.parentNode);
		if (!dimensions) {
			return false;
		}
		position.dom.width = dimensions.width;
		position.dom.height = dimensions.height;
		position.playQueueIndex = 0;
		position.playQueue = position.loadingPlayQueue;
		if (position.decoder.API.play(position)) {
			return true;
		}
		return false;
	},
	pause: function (position) {
		if (typeof position.decoder === 'object' && position.decoder && typeof position.decoder.API === 'object' && typeof position.decoder.API.pause === 'function') {
			return position.decoder.API.pause(position);
		}
		return false;
	},
	resume: function (position) {
		if (typeof position.decoder === 'object' && position.decoder && typeof position.decoder.API === 'object' && typeof position.decoder.API.resume === 'function') {
			return position.decoder.API.resume(position);
		}
		return false;
	},
	togglePause: function (position) {
		if (typeof position.decoder === 'object' && position.decoder && typeof position.decoder.API === 'object' && typeof position.decoder.API.togglePause === 'function') {
			return position.decoder.API.togglePause(position);
		}
		return false;
	},
	isPaused: function (position) {
		if (typeof position.decoder === 'object' && position.decoder && typeof position.decoder.API === 'object' && typeof position.decoder.API.isPaused === 'function') {
			return position.decoder.API.isPaused(position);
		}
		return false;
	},
	seek: function (position, milliseconds) {
		if (milliseconds !== 0) {
			milliseconds = DrVideo._tools.getInt(milliseconds);
			if (milliseconds === null) {
				return false;
			}
		}
		if (typeof position.decoder === 'object' && position.decoder && typeof position.decoder.API === 'object' && typeof position.decoder.API.seek === 'function') {
			return position.decoder.API.seek(position, milliseconds);
		}
		return false;
	},
	getVolume: function (position) {
		return position.volume;
	},
	setVolume: function (position, newVolume) {
		if (!(typeof newVolume === 'number' && !isNaN(newVolume))) {
			return false;
		}
		newVolume = parseInt(newVolume, 10);
		if (newVolume !== null && newVolume >= 0 && newVolume <= 100 && typeof position.decoder === 'object' && position.decoder && typeof position.decoder.API === 'object' && typeof position.decoder.API.setVolume === 'function') {
			return position.decoder.API.setVolume(position, newVolume);
		}
		return false;
	},
	mute: function (position) {
		if (typeof position.decoder === 'object' && position.decoder && typeof position.decoder.API === 'object' && typeof position.decoder.API.mute === 'function') {
			return position.decoder.API.mute(position);
		}
		return false;
	},
	unmute: function (position) {
		if (typeof position.decoder === 'object' && position.decoder && typeof position.decoder.API === 'object' && typeof position.decoder.API.unmute === 'function') {
			return position.decoder.API.unmute(position);
		}
		return false;
	},
	toggleMute: function (position) {
		if (typeof position.decoder === 'object' && position.decoder && typeof position.decoder.API === 'object' && typeof position.decoder.API.toggleMute === 'function') {
			return position.decoder.API.toggleMute(position);
		}
		return false;
	},
	isMuted: function (position) {
		if (typeof position.decoder === 'object' && position.decoder && typeof position.decoder.API === 'object' && typeof position.decoder.API.isMuted === 'function') {
			return position.decoder.API.isMuted(position);
		}
		return false;
	},
	getActive: function (position) {
		if (typeof position.playingId === 'number') {
			return position.playingId;
		}
		return null;
	},
	getCurrentTime: function (position) {
		if (typeof position.decoder === 'object' && position.decoder && typeof position.decoder.API === 'object' && typeof position.decoder.API.getCurrentTime === 'function') {
			return position.decoder.API.getCurrentTime(position);
		}
		return null;
	},
	destroy: function (position) {
		if (typeof position.decoder === 'object' && position.decoder && typeof position.decoder.API === 'object' && typeof position.decoder.API.destroy === 'function') {
			return position.decoder.API.destroy(position);
		}
		return false;
	}
},
DrVideo._tools = {
	path: null,
	getCompanions: function (position) {
		position.loadingCompanions = null;
		return DrVideo._actions.play(position);
	},
	getMeta: function (id) {
		id = DrVideo._tools.getInt(id);
		var V = DrVideo._videos, meta = {};
		if (!(id && typeof V['v' + id] === 'object')) {
			return null;
		}
		V = V['v' + id];
		if (typeof V.meta === 'object') {
			meta = V.meta;
		}
		if (typeof V.status === 'number') {
			meta.status = V.status;
		}
		return meta;
	},
	getIndexes: function (id) {
		id = DrVideo._tools.getInt(id);
		var V = DrVideo._videos;
		if (id && typeof V['v' + id] === 'object' && typeof V['v' + id].indexes === 'object') {
			return V['v' + id].indexes;
		}
		return null;
	},
	getFormats: function (id) {
		var V = DrVideo._videos, F = DrVideo._decoderFormats, D = DrVideo._decoders, formats, availableFormats = {}, WD = null, WP = null, WM = null, WF = null, i, iMax, j, jMax, k, kMax, l, lMax;
		id = DrVideo._tools.getInt(id);
		if (!(id && typeof V['v' + id] === 'object' && typeof V['v' + id].formats === 'object')) {
			return null;
		}
		formats = V['v' + id].formats;
		for (i = 0, iMax = F.length; i < iMax; i++) {
			if (!(typeof F[i].name === 'string' && F[i].name.length > 0 && typeof D[F[i].name] === 'object')) {
				continue;
			}
			WD = D[F[i].name];
			for (j = 0, jMax = F[i].protocols.length; j < jMax; j++) {
				WP = F[i].protocols[j];
				if (typeof formats[WP.name] !== 'object') {
					continue;
				}
				for (k = 0, kMax = WP.mimes.length; k < kMax; k++) {
					WM = WP.mimes[k];
					if (typeof formats[WP.name][WM] !== 'object') {
						continue;
					}
					WF = formats[WP.name][WM];
					for (l = 0, lMax = WF.length; l < lMax; l++) {
						if (!(typeof availableFormats['w' + WF[l].height] === 'object' && availableFormats['w' + WF[l].height].supported)) {
							availableFormats['w' + WF[l].height] = {
								width: WF[l].width,
								height: WF[l].height,
								supported: (WD.isSupported() && WD.supportsProtocol(WP.name) && WD.supportsMime(WM) && WD.supportsDimensions(WF[l].width, WF[l].height, WF[l].bitrate))
							};
						}
					}
				}
			}
		}
		return availableFormats;
	},
	isLoaded: function (id) {
		id = DrVideo._tools.getInt(id);
		if (id && typeof DrVideo._videos['v' + id] === 'object') {
			return true;
		}
		return false;
	},
	getInt: function (number) {
		if (typeof number === 'number' && !isNaN(number)) {
			number = parseInt(number, 10);
			if (number) {
				return number;
			}
		}
		return null;
	},
	request: function (path, parameters) {
		var script = document.createElement('script'), i, iMax;
		script.setAttribute('type', 'text/javascript');
		script.setAttribute('charset', 'utf-8');
		script.setAttribute('src', DrVideo._tools.path + '/actions/' + path);
		if (parameters) {
			for (i = 0, iMax = parameters.length; i < iMax; i++) {
				script.setAttribute(parameters[i][0], parameters[i][1]);
			}
		}
		document.getElementsByTagName('head')[0].appendChild(script);
		return true;
	},
	isDefaultMuted: function () {
		return false;
	},
	getDefaultVolume: function () {
		return 50;
	},
	getDimensions: function (parentNode) {
		var width = parentNode.clientWidth, height = parentNode.clientHeight;
		if (width === '') {
			width = 640;
		}
		if (height === '') {
			height = 360;
		}
		return {
			width: width,
			height: height
		};
	},
	createPosition: function (parentNode) {
		var dimensions = DrVideo._tools.getDimensions(parentNode), position = {
			id: parentNode.id,
			dom: {
				parentNode: parentNode,
				width: dimensions.width,
				height: dimensions.height
			},
			callbacks: {},
			settings: {},
			volume: DrVideo._tools.getDefaultVolume(),
			isMuted: DrVideo._tools.isDefaultMuted()
		};
		DrVideo._positions[parentNode.id] = position;
		if (typeof DrVideo._defaultPosition !== 'string') {
			DrVideo._defaultPosition = position.id;
		}
		return position;
	},
	generateId: function (parentNode) {
		var randomId = null, randomNode = null, i;
		for (i = 0; i < 1000; i++) {
			randomId = 'drvideo-' + Math.round(Math.random() * 100000);
			randomNode = document.getElementById(randomId);
			if (!randomNode) {
				parentNode.id = randomId;
				return randomId;
			}
		}
		return null;
	},
	getPosition: function (parentElement) {
		var P = DrVideo._positions, parentNode;
		if (parentElement === undefined) {
			if (typeof DrVideo._defaultPosition === 'string') {
				parentElement = DrVideo._defaultPosition;
			} else {
				parentElement = 'drvideo-video-parent';
			}
		} else if (typeof parentElement === 'object' && parentElement && parentElement.nodeType === 1) {
			if (typeof parentElement.id === 'string' && parentElement.id.length > 0) {
				parentElement = parentElement.id;
			} else {
				parentElement = DrVideo._tools.generateId(parentElement);
			}
		}
		if (typeof parentElement === 'string' && parentElement.length > 0) {
			if (typeof P[parentElement] === 'object') {
				return P[parentElement];
			}
			parentNode = document.getElementById(parentElement);
			if (parentNode) {
				return DrVideo._tools.createPosition(parentNode);
			}
		}
		return null;
	},
	isIphone: function () {
		if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)) {
			return true;
		}
		return false;
	},
	isAndroid: function () {
		if (navigator.userAgent.match(/Android/i)) {
			return true;
		}
		return false;
	},
	isIpad: function () {
		if (navigator.userAgent.match(/iPad/i)) {
			return true;
		}
		return false;
	},
	isAppleDevice: function () {
		return (DrVideo._tools.isIphone() || DrVideo._tools.isIpad());
	},
	addEventListener: function (node, eventName, callback) {
		if (!(typeof node === 'object' && node)) {
			return false;
		}
		if (typeof node.addEventListener === 'function') {
			node.addEventListener(eventName, callback, true);
		} else {
			node.attachEvent('on' + eventName, callback);
		}
	},
	removeEventListener: function (node, eventName, callback) {
		if (typeof node.removeEventListener === 'function') {
			node.removeEventListener(eventName, callback, true);
		} else {
			node.detachEvent('on' + eventName, callback);
		}
	},
	getDecoder: function (clipFormats, position) {
		if (!(typeof clipFormats === 'object' && clipFormats)) {
			return null;
		}
		var playerWidth = position.dom.width, F = DrVideo._decoderFormats, D = DrVideo._decoders, WF = null, WP = null, WM = null, WD = null, CF = null, bestFormat = null, i, iMax, j, jMax, k, kMax, l, lMax;
		if (typeof position.settings.desiredWidth === 'number') {
			playerWidth = position.settings.desiredWidth;
		}
		for (i = 0, iMax = F.length; i < iMax; i++) {
			WF = F[i];
			if (!(typeof WF.name === 'string' && typeof D[WF.name] === 'object' && D[WF.name])) {
				continue;
			}
			WD = D[WF.name];
			if (!(typeof WF.protocols === 'object' && WF.protocols && WF.protocols.constructor === Array && WF.protocols.length > 0 && typeof WD.isSupported === 'function' && typeof WD.supportsProtocol === 'function' && typeof WD.supportsMime === 'function' && WD.isSupported())) {
				continue;
			}
			for (j = 0, jMax = WF.protocols.length; j < jMax; j++) {
				WP = WF.protocols[j];
				if (!(WP && clipFormats[WP.name] && typeof WP.mimes === 'object' && WP.mimes && WP.mimes.constructor === Array && WP.mimes.length > 0 && WD.supportsProtocol(WP.name))) {
					continue;
				}
				for (k = 0, kMax = WP.mimes.length; k < kMax; k++) {
					WM = WP.mimes[k];
					if (WM && clipFormats[WP.name][WM] && WD.supportsMime(WM)) {
						CF = clipFormats[WP.name][WM];
						for (l = 0, lMax = CF.length; l < lMax; l++) {
							if ((!bestFormat && WD.supportsDimensions(CF[l].width, CF[l].height, CF[l].bitrate)) || (bestFormat && WD.supportsDimensions(CF[l].width, CF[l].height, CF[l].bitrate) && bestFormat.file.width <= playerWidth && CF[l].width <= playerWidth && CF[l].width > bestFormat.file.width) || (bestFormat && WD.supportsDimensions(CF[l].width, CF[l].height, CF[l].bitrate) && bestFormat.file.width > playerWidth && CF[l].width < bestFormat.file.width)) {
								bestFormat = {
									'decoder': WD,
									'protocol': WP.name,
									'mime': WM,
									'file': CF[l]
								};
							}
						}
					}
				}
			}
		}
		if (bestFormat) {
			return bestFormat;
		}
		return null;
	}
};
DrVideo._positions = {},
DrVideo._videos = {},
DrVideo._decoderFormats = [],
DrVideo._decoders = {}
if ('DrVideo' in window) {
	DrVideo._decoders.html5 = {
		name: 'html5',
		playlistFormat: 'json',
		isSupported: function () {
			var video = document.createElement('video');
			if (typeof video.canPlayType === 'function') {
				return true;
			}
			return false;
		},
		supportsProtocol: function (protocol) {
			if (protocol === 'http') {
				return true;
			} else if (protocol === 'rtsp' && DrVideo._tools.isAndroid()) {
				return true;
			}
			return false;
		},
		supportsMime: function (mime) {
			if (!(typeof mime === 'string' && mime.length > 0)) {
				return false;
			}
			if ((mime === 'mp4' || mime === 'm4v') && DrVideo._tools.isAndroid()) {
				return true;
			}
			if (mime === 'm3u8' && DrVideo._tools.isAppleDevice()) {
				return true;
			}
			var video = document.createElement('video');
			if (typeof video.canPlayType === 'function' && video.canPlayType('video/' + mime)) {
				return true;
			}
			return false;
		},
		supportsDimensions: function (width, height, bitrate) {
			if (DrVideo._tools.isIphone() && (width > 640 || height > 480 || bitrate > 1500)) {
				return false;
			}
			if (DrVideo._tools.isAndroid() && (width > 640)) {
				return false;
			}
			if (DrVideo._tools.isIpad() && (width > 1280 || height > 720 || bitrate > 2500)) {
				return false;
			}
			return true;
		},
		overload: {
			node: function () {}
		},
		loadPlaylist: function (ids, position) {
			return DrVideo._loaders.loadPlaylist(ids, position);
		},
		eventCallbacks: {
			error: function (event) {
				var position = DrVideo._tools.getPosition(event.target.parentNode);
				if (!position) {
					return false;
				}
				return DrVideo._callbacks.fireEvent('error', {id: position.id, videoId: position.playingId, decoder: 'html5', event: event}, position);
			},
			loadedMetadata: function (event) {
				var position = DrVideo._tools.getPosition(event.target.parentNode);
				if (!position) {
					return false;
				}
				if (typeof position.playingId === 'number' && typeof DrVideo._videos['v' + position.playingId] === 'object' && DrVideo._videos['v' + position.playingId] && typeof position.dom.node === 'object' && position.dom.node && typeof position.dom.node.duration === 'number') {
					DrVideo._videos['v' + position.playingId].fileDuration = Math.floor(position.dom.node.duration * 1000);
				}
				return DrVideo._callbacks.fireEvent('loadedMetadata', {id: position.id, videoId: position.playingId, duration: DrVideo._videos['v' + position.playingId].fileDuration, decoder: 'html5'}, position);
			},
			timeUpdate: function (event) {
				var position = DrVideo._tools.getPosition(event.target.parentNode);
				if (!position) {
					return false;
				}
				if (typeof position.startOffset === 'number') {
					position.dom.node.currentTime = position.startOffset / 1000;
					delete position.startOffset;
				}
				return DrVideo._callbacks.fireEvent('timeUpdate', {id: position.id, currentTime: Math.floor(position.dom.node.currentTime * 1000)}, position);
			},
			volumeChange: function (event) {
				var position = DrVideo._tools.getPosition(event.target.parentNode);
				if (!position) {
					return false;
				}
				return DrVideo._callbacks.fireEvent('volumeUpdate', {id: position.id, currentVolume: Math.floor(position.dom.node.volume * 100)}, position);
			},
			play: function (event) {
				var position = DrVideo._tools.getPosition(event.target.parentNode);
				if (!(position && typeof position.playingId === 'number')) {
					return false;
				}
				DrVideo._tools.removeEventListener(position.dom.node, 'play', position.decoder.eventCallbacks.play);
				var fileObject = {
                                        width: position.format.file.width,
                                        height: position.format.file.height,
                                        bitrate: position.format.file.bitrate
                                };
				return DrVideo._callbacks.fireEvent('play', {id: position.id, videoId: position.playingId, decoder: 'html5', file: fileObject}, position);
			},
			ended: function (event) {
				var position = DrVideo._tools.getPosition(event.target.parentNode);
				if (!(position && typeof position.playingId === 'number')) {
					return false;
				}
				return DrVideo._callbacks.fireEvent('ended', {id: position.id, videoId: position.playingId, decoder: 'html5'}, position);
			}
		},
		API: {
			play: function (position) {
				var node = document.createElement('video'), playlistName, loadingQueueValue, file;
				node.setAttribute('x-webkit-airplay', 'allow');
				playlistName = position.decoder.playlistFormat + '-' + position.format.protocol + '-' + position.format.mime;
				loadingQueueValue = position.playQueue[position.playQueueIndex];
				file = position.format.file.paths[Math.floor(Math.random() * position.format.file.paths.length)];
				DrVideo._tools.addEventListener(node, 'error', position.decoder.eventCallbacks.error);
				DrVideo._tools.addEventListener(node, 'loadedmetadata', position.decoder.eventCallbacks.loadedMetadata);
				DrVideo._tools.addEventListener(node, 'timeupdate', position.decoder.eventCallbacks.timeUpdate);
				DrVideo._tools.addEventListener(node, 'volumechange', position.decoder.eventCallbacks.volumeChange);
				DrVideo._tools.addEventListener(node, 'play', position.decoder.eventCallbacks.play);
				DrVideo._tools.addEventListener(node, 'ended', position.decoder.eventCallbacks.ended);
				node.setAttribute('src', position.format.protocol + '://' + file.address + ':' + file.port + '/' + file.path + '/' + file.filename);
				node.setAttribute('width', position.dom.width);
				node.setAttribute('height', position.dom.height);
				node.setAttribute('controls', 'true');
				node.setAttribute('autoplay', 'true');
				position.decoder.overload.node(node);
				position.dom.node = node;
				position.dom.parentNode.innerHTML = '';
				position.dom.parentNode.appendChild(node);
				position.playingId = position.loadingId;
				node.play();
				return true;
			},
			pause: function (position) {
				if (position.dom.node.paused) {
					return true;
				}
				position.dom.node.pause();
				return position.dom.node.paused;
			},
			resume: function (position) {
				if (!position.dom.node.paused) {
					return true;
				}
				position.dom.node.play();
				return !position.dom.node.paused;
			},
			togglePause: function (position) {
				if (position.dom.node.paused) {
					return position.decoder.API.resume(position);
				} else {
					return position.decoder.API.pause(position);
				}
			},
			isPaused: function (position) {
				if (position.dom.node.paused) {
					return true;
				}
				return false;
			},
			seek: function (position, milliseconds) {
				var seconds = milliseconds / 1000;
				if (seconds < 0 || seconds > position.dom.node.duration) {
					return false;
				}
				position.dom.node.currentTime = seconds;
				return true;
			},
			setVolume: function (position, newVolume) {
				if (newVolume === position.volume) {
					return true;
				}
				newVolume /= 100;
				position.dom.node.volume = newVolume;
				return true;
			},
			mute: function (position) {
				if (position.dom.node.muted) {
					return true;
				}
				position.dom.node.muted = true;
				return position.dom.node.muted;
			},
			unmute: function (position) {
				if (!position.dom.node.muted) {
					return true;
				}
				return !(position.dom.node.muted = false);
			},
			toggleMute: function (position) {
				if (position.dom.node.muted) {
					return position.decoder.API.unmute(position);
				} else {
					return position.decoder.API.mute(position);
				}
			},
			isMuted: function (position) {
				if (position.dom.node.muted) {
					return true;
				}
				return false;
			},
			destroy: function (position) {
				position.dom.parentNode.innerHTML = '';
				delete DrVideo._positions[position.id];
				return true;
			},
			getCurrentTime: function (position) {
				return position.dom.node.currentTime * 1000;
			}
		}
	};
}
if ('DrVideo' in window) {
	DrVideo._decoders.flash = {
		name: 'flash',
		playlistFormat: 'json',
		isSupported: function () {
			var version = null;
			try {
				version = new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?([0-9,]+),?$/)[1];
			} catch (e1) {
				try {
					if (navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin) {
						version = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?([0-9,]+),?$/)[1];
					}
				} catch (e2) {}
			}
			if (version) {
				version = version.split(',');
				if (version.length >= 3 && ((version[0] === 9 && ((version[1] === 0 && version[2] >= 115) || version[1] >= 1)) || version[0] >= 10)) {
					return true;
				}
			}
			return false;
		},
		supportsProtocol: function (protocol) {
			if (protocol === 'hds' || protocol === 'http' || protocol === 'rtmp' || protocol === 'rtmpt' || protocol === 'rtmpe' || protocol === 'rtmpte') {
				return true;
			}
			return false;
		},
		supportsMime: function (mime) {
			if (mime === 'mp4' || mime === 'flv') {
				return true;
			}
			return false;
		},
		supportsDimensions: function () {
			return true;
		},
		overload: {
			loadingObject: function () {}
		},
		loadPlaylist: function (ids, position) {
			return DrVideo._loaders.loadPlaylist(ids, position);
		},
		eventCallbacks: {
			onMetaData: function (data) {
				var D = DrVideo, V = D._videos, position = D._tools.getPosition(this.id());
				if (!position) {
					return false;
				}
				if (position.settings.metaDataLoaded) {
					return true;
				}
				position.settings.metaDataLoaded = true;
				if (typeof position.playingId === 'number' && typeof V['v' + position.playingId] === 'object' && V['v' + position.playingId] && typeof data === 'object' && data && typeof data.duration === 'number') {
					V['v' + position.playingId].fileDuration = Math.floor(data.duration * 1000);
				}
				if (position.settings.timeIntervalId) {
					clearInterval(position.settings.timeIntervalId);
				}
				position.settings.timeIntervalId = setInterval(function () { D._decoders.flash.eventCallbacks.timeUpdate(position.id); }, 500);
				return D._callbacks.fireEvent('loadedMetadata', {id: position.id, videoId: position.playingId, duration: V['v' + position.playingId].fileDuration, decoder: 'flash'}, position);
			},
			timeUpdate: function (positionId) {
				var position = DrVideo._tools.getPosition(positionId), time;
				if (!position) {
					return false;
				}
				time = $f(positionId).getTime();
				if (typeof time === 'number' && !isNaN(time)) {
					return DrVideo._callbacks.fireEvent('timeUpdate', {id: position.id, currentTime: Math.floor(time * 1000)}, position);
				}
				return false;
			},
			onStart: function () {
				var position = DrVideo._tools.getPosition(this.id());
				if (!(position && typeof position.playingId === 'number')) {
					return false;
				}
				if (typeof position.startOffset === 'number') {
					this.seek(Math.round(position.startOffset / 1000));
					delete position.startOffset;
				}
				var fileObject = {
					width: position.format.file.width,
					height: position.format.file.height,
					bitrate: position.format.file.bitrate
				};
				return DrVideo._callbacks.fireEvent('play', {id: position.id, videoId: position.playingId, decoder: 'flash', file: fileObject}, position);
			},
			onFinish: function () {
				var position = DrVideo._tools.getPosition(this.id());
				if (!(position && typeof position.playingId === 'number')) {
					return false;
				}
				return DrVideo._callbacks.fireEvent('ended', {id: position.id, videoId: position.playingId, decoder: 'flash'}, position);
			}
		},
		API: {
			play: function (position) {
				delete position.settings.metaDataLoaded;
				var file = position.format.file.paths[0], loadingObject;
				loadingObject = {
					key: [
							'4c03c817642744b2c42'
						],
					clip: {
						url: (position.format.protocol === 'http' ? ('http://' + file.address + ':' + file.port + '/') : '') + file.path + (file.path.length > 0 && file.filename.length > 0 ? '/' : '') + file.filename,
						scaling: 'fit',
						onMetaData: DrVideo._decoders.flash.eventCallbacks.onMetaData,
						onStart: DrVideo._decoders.flash.eventCallbacks.onStart,
						onFinish: DrVideo._decoders.flash.eventCallbacks.onFinish,
						start: 0,
						bufferLength: 2
					},
					canvas: {
						backgroundGradient: 'none'
					},
					plugins: {
						play: null,
						rtmp: {
							url: DrVideo._tools.path + '/js/flash/flowplayer.rtmp-3.2.3.swf'
						},						
					 	pseudostreaming: {
                                                        url: DrVideo._tools.path + '/js/flash/flowplayer.pseudostreaming-3.2.7.swf',
                                                        queryString: escape('start=${start}')
                                                },
						akamaihds: {
							url: DrVideo._tools.path + '/js/flash/AkamaiFlowPlugin.2.6.swf',
							akamaiMediaType: 'akamai-hdn-adobe-http',
							enableNetSessionDiscovery: true,
							netsessionMode: 'opportunistic'
						}  		
					},
					onMute: function (object) {
						DrVideo._positions[this.id()].isMuted = true;
					},
					onUnmute: function (object) {
						DrVideo._positions[this.id()].isMuted = false;
					},
					onVolume: function (newVolume) {
						DrVideo._positions[this.id()].volume = newVolume;
					},
					onLoad: function () {
						this.getPlugin('play').hide();
					}
				};
				position.decoder.overload.loadingObject(loadingObject, position);
				if (position.format.protocol === 'rtmp' || position.format.protocol === 'rtmpt' || position.format.protocol === 'rtmpe' || position.format.protocol === 'rtmpte') {
					loadingObject.clip.provider = 'rtmp';
					loadingObject.plugins.rtmp.netConnectionUrl = position.format.protocol + '://' + file.address + ':' + file.port + '/' + file.application;
				} else if (position.format.protocol === 'http') {
					loadingObject.clip.url = position.format.protocol + '://' + file.address + ':' + file.port + (file.path.length > 0 ? '/' + file.path : '') + (file.filename.length > 0 ? '/' + file.filename : '');
					if (file.address.match(/-f.akamaihd.net/)) {	// 2012-02-22 - Hack for HDS Akamai Live
						loadingObject.clip.provider = 'akamaihds';
					} else if (position.format.mime === 'mp4') {
						loadingObject.clip.provider = 'pseudostreaming';
					}
				} else if (position.format.protocol === 'hds') {
					if (position.format.mime === 'mp4') {
						loadingObject.clip.provider = 'akamaihds';
						loadingObject.clip.url = 'http://' + file.address + ':' + file.port + '/' + (file.path.length > 0 ? file.path + '/' : '') + ',';
						if (typeof position.settings.desiredWidth === 'number') {
							loadingObject.clip.url += file.filename.split('.')[0] + ',';
						} else {
							var f = DrVideo._videos['v' + position.loadingId].formats[position.format.protocol][position.format.mime];
							for (var i = 0, iMax = f.length; i < iMax; i++) {
								loadingObject.clip.url += f[i].paths[0].filename.split('.')[0] + ',';
							}
						}
						loadingObject.clip.url += '.mp4.csmil/manifest.f4m';
                                        }
				}
				document.getElementById(position.id).innerHTML = '';										
				$f(position.id, {src: DrVideo._tools.path + '/js/flash/flowplayer.unlimited-3.2.7.swf', wmode: 'opaque', cachebusting: false}, loadingObject);
				position.playingId = position.loadingId;
				if (typeof position.settings.timeIntervalId === 'number') {
					clearInterval(position.settings.timeIntervalId);
				}
				return true;
			},
			pause: function (position) {
				return $f(position.id).pause();
			},
			resume: function (position) {
				return $f(position.id).resume();
			},
			togglePause: function (position) {
				if ($f(position.id).isPaused()) {
					return position.decoder.API.resume(position);
				} else {
					return position.decoder.API.pause(position);
				}
			},
			isPaused: function (position) {
				return $f(position.id).isPaused();
			},
			seek: function (position, milliseconds) {
				var seconds = milliseconds / 1000;
				if (seconds < 0) {
					return false;
				}
				return $f(position.id).seek(seconds);
			},
			setVolume: function (position, newVolume) {
				if (newVolume === position.volume) {
					return true;
				}
				return $f(position.id).setVolume(newVolume);
			},
			mute: function (position) {
				return $f(position.id).mute();
			},
			unmute: function (position) {
				return $f(position.id).unmute();
			},
			toggleMute: function (position) {
				if (position.isMuted) {
					return position.decoder.API.unmute(position);
				} else {
					return position.decoder.API.mute(position);
				}
			},
			destroy: function (position) {
				// @todo: This is retarded. Updated, less retarded now. Updated again, now IE working?
				$f(position.id).close();
				position.dom.parentNode.innerHTML = '';
				delete DrVideo._positions[position.id];
			},
			getCurrentTime: function (position) {
				return $f(position.id).getTime() * 1000;
			}
		}
	};
}
if ('DrVideo' in window) {
	DrVideo._decoderFormats = [
		{
			name: 'flash',
			protocols: [
      				{
                                        name: 'http',
                                        mimes: [
                                                'mp4',
                                                'flv'
                                        ]
                                },
				{
					name: 'rtmp',
					mimes: [
						'mp4',
						'flv'
					]
				},
				{
					name: 'rtmpt',
					mimes: [
						'mp4',
						'flv'
					]
				},
				{
					name: 'rtmpe',
					mimes: [
						'mp4',
						'flv'
					]
				},
				{
					name: 'rtmpte',
					mimes: [
						'mp4',
						'flv'
					]
				}
			]
		},
		{
			name: 'html5',
			protocols: [
				{
					name: 'http',
					mimes: [
						'mp4',
						'm3u8',
						'webm',
						'ogg'
					]
				}
			]
		}
	];
}
if ('DrVideo' in window) {
	if ('_decoders' in DrVideo) {
		if ('flash' in DrVideo._decoders) {
			DrVideo._decoders.flash.overload.loadingObject = function (loadingObject, position) {
				var V = DrVideo._videos['v' + position.loadingId];
				if (typeof V.meta === 'object') {
					// Enable live stream subscription
					if (V.meta.dateLive && typeof V.meta.dateLive === 'number') {
						loadingObject.clip.live = true;
					}
				}
			};
		}
	}
}
var NettTv = {
	parentElement: '',
	loadedId: null,
	shimVideoLoaded : function(data) {
		if (!(typeof data === 'object' && data && typeof data.videoId === 'number')) {
			return false;
		}
		if ('videoLoaded' in window) {
			if (data.videoId < 0) {
				videoLoaded(data.videoId*-1);
			} else {
				videoLoaded(data.videoId);
			}
		}
	},
	API: {
		play : function(videoId, parentElement, pageType) {
			if (typeof pageType === 'string' && pageType.length > 0) {
				DrVideo._drklikk.pageType = pageType;
			}
			if (typeof parentElement === 'string' && parentElement.length > 0) {
				NettTv.parentElement = parentElement;
			}
			NettTv.loadedId = videoId;
			var optionsObject = {};
			optionsObject.desiredWidth = 832;
			if (typeof DrVideo._tools.multiplay === 'object' && DrVideo._tools.multiplay && typeof NettTvAds === 'object' && NettTvAds) {
				if (NettTvAds.preAds && typeof NettTvAds.preAds === 'object') {
					var currentElement = {};
					if (typeof NettTvAds.preAds.id === 'number' && (NettTvAds.preAds.id > 0 || NettTvAds.preAds.id < 0)) {
						currentElement.id = NettTvAds.preAds.id;
						currentElement.isSeekable = false;
					}
					if (typeof NettTvAds.preAds.url === 'string' && NettTvAds.preAds.url.length > 0) {
						currentElement.clickUrl = NettTvAds.preAds.url;
					}
					optionsObject.videosBefore = [];
					optionsObject.videosBefore.push(currentElement);
				}
			}
			if (typeof DrVideo._tools.multiplay === 'object' && DrVideo._tools.multiplay && typeof NettTvAds === 'object' && NettTvAds) {
				if (NettTvAds.postAds && typeof NettTvAds.postAds === 'object') {
					var currentElement = {};
					if (NettTvAds.postAds && (NettTvAds.postAds.id > 0 || NettTvAds.postAds.id < 0)) {
						currentElement.id = NettTvAds.postAds.id;
						currentElement.isSeekable = false;
					}
					if (typeof NettTvAds.postAds.url === 'string' && NettTvAds.postAds.url.length > 0) {
						currentElement.clickUrl = NettTvAds.postAds.url;
					}
					optionsObject.videosAfter = [];
					optionsObject.videosAfter.push(currentElement);
				}
			}
			DrVideo.API.play(videoId, NettTv.parentElement, optionsObject);
		},
		load : function(videoId, callback) {
			if (typeof callback === 'function' ) {
				DrVideo.API.addCallback('videoLoaded', NettTv.shimVideoLoaded);
			}
			DrVideo.API.load(videoId);
			return true;
		},
		stop : function() {
			DrVideo.API.pause();
			return false;
		},
		addHook : function(eventName, callback) {
			if (!(typeof eventName === 'string' && (eventName === 'play' || eventName === 'next') && typeof callback === 'function')) {
				return false;
			}
			DrVideo.API.addCallback(eventName, function(e) {
				if (e.videoId < 0) {
					return false;
				}
				callback(e.videoId);
			});
			return true;
		},
		getImage : function(videoId, width) {
			var meta = DrVideo.API.getMeta(videoId);
			if (!(typeof meta['x-imageWidths'] === 'object' && meta['x-imageWidths'] && typeof meta['x-image'] === 'number' && meta['x-image'] > 0)) {
				return false;
			}
			for (var i in meta['x-imageWidths']) {
				if (meta['x-imageWidths'][i] <= width) {
					var url = DrVideo._tools.path + '/../' + '/out/img/' + meta['x-image'] + '_' + meta['x-imageWidths'][i] + 'px.jpg';
					return url;
				}
			}
			return false;
		},
		getTitle : function(videoId) {
			var meta = DrVideo.API.getMeta(videoId);
			if (!(typeof meta.title === 'string' && meta.title.length > 0)) {
				return false;
			}
			return meta.title;
		},
		getPreamble : function(videoId) {
			var meta = DrVideo.API.getMeta(videoId);
			if (!(typeof meta.preamble === 'string' && meta.preamble.length > 0)) {
				return '';
			}
			return meta.preamble;
		},
		getActive : function () {
			var active = DrVideo.API.getActive();
			if (active === null) {
				return false;
			}
			return active;
		},
		setVideoParent : function(elm) {
			if (typeof elm === 'string' && elm.length > 0) {
				NettTv.parentElement = elm;
				return true;
			}
			return false;
		}
	}
};

if ('DrVideo' in window) {
	DrVideo._tools.path = 'http://edda-laagendalsposten.netttv.aptoma.no/data';
}
/* 
 * flowplayer.js 3.2.6. The Flowplayer API
 * 
 * Copyright 2009-2011 Flowplayer Oy
 * 
 * This file is part of Flowplayer.
 * 
 * Flowplayer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Flowplayer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Flowplayer.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Date: 2011-02-04 05:45:28 -0500 (Fri, 04 Feb 2011)
 * Revision: 614 
 */
(function(){function g(o){console.log("$f.fireEvent",[].slice.call(o))}function k(q){if(!q||typeof q!="object"){return q}var o=new q.constructor();for(var p in q){if(q.hasOwnProperty(p)){o[p]=k(q[p])}}return o}function m(t,q){if(!t){return}var o,p=0,r=t.length;if(r===undefined){for(o in t){if(q.call(t[o],o,t[o])===false){break}}}else{for(var s=t[0];p<r&&q.call(s,p,s)!==false;s=t[++p]){}}return t}function c(o){return document.getElementById(o)}function i(q,p,o){if(typeof p!="object"){return q}if(q&&p){m(p,function(r,s){if(!o||typeof s!="function"){q[r]=s}})}return q}function n(s){var q=s.indexOf(".");if(q!=-1){var p=s.slice(0,q)||"*";var o=s.slice(q+1,s.length);var r=[];m(document.getElementsByTagName(p),function(){if(this.className&&this.className.indexOf(o)!=-1){r.push(this)}});return r}}function f(o){o=o||window.event;if(o.preventDefault){o.stopPropagation();o.preventDefault()}else{o.returnValue=false;o.cancelBubble=true}return false}function j(q,o,p){q[o]=q[o]||[];q[o].push(p)}function e(){return"_"+(""+Math.random()).slice(2,10)}var h=function(t,r,s){var q=this,p={},u={};q.index=r;if(typeof t=="string"){t={url:t}}i(this,t,true);m(("Begin*,Start,Pause*,Resume*,Seek*,Stop*,Finish*,LastSecond,Update,BufferFull,BufferEmpty,BufferStop").split(","),function(){var v="on"+this;if(v.indexOf("*")!=-1){v=v.slice(0,v.length-1);var w="onBefore"+v.slice(2);q[w]=function(x){j(u,w,x);return q}}q[v]=function(x){j(u,v,x);return q};if(r==-1){if(q[w]){s[w]=q[w]}if(q[v]){s[v]=q[v]}}});i(this,{onCuepoint:function(x,w){if(arguments.length==1){p.embedded=[null,x];return q}if(typeof x=="number"){x=[x]}var v=e();p[v]=[x,w];if(s.isLoaded()){s._api().fp_addCuepoints(x,r,v)}return q},update:function(w){i(q,w);if(s.isLoaded()){s._api().fp_updateClip(w,r)}var v=s.getConfig();var x=(r==-1)?v.clip:v.playlist[r];i(x,w,true)},_fireEvent:function(v,y,w,A){if(v=="onLoad"){m(p,function(B,C){if(C[0]){s._api().fp_addCuepoints(C[0],r,B)}});return false}A=A||q;if(v=="onCuepoint"){var z=p[y];if(z){return z[1].call(s,A,w)}}if(y&&"onBeforeBegin,onMetaData,onStart,onUpdate,onResume".indexOf(v)!=-1){i(A,y);if(y.metaData){if(!A.duration){A.duration=y.metaData.duration}else{A.fullDuration=y.metaData.duration}}}var x=true;m(u[v],function(){x=this.call(s,A,y,w)});return x}});if(t.onCuepoint){var o=t.onCuepoint;q.onCuepoint.apply(q,typeof o=="function"?[o]:o);delete t.onCuepoint}m(t,function(v,w){if(typeof w=="function"){j(u,v,w);delete t[v]}});if(r==-1){s.onCuepoint=this.onCuepoint}};var l=function(p,r,q,t){var o=this,s={},u=false;if(t){i(s,t)}m(r,function(v,w){if(typeof w=="function"){s[v]=w;delete r[v]}});i(this,{animate:function(y,z,x){if(!y){return o}if(typeof z=="function"){x=z;z=500}if(typeof y=="string"){var w=y;y={};y[w]=z;z=500}if(x){var v=e();s[v]=x}if(z===undefined){z=500}r=q._api().fp_animate(p,y,z,v);return o},css:function(w,x){if(x!==undefined){var v={};v[w]=x;w=v}r=q._api().fp_css(p,w);i(o,r);return o},show:function(){this.display="block";q._api().fp_showPlugin(p);return o},hide:function(){this.display="none";q._api().fp_hidePlugin(p);return o},toggle:function(){this.display=q._api().fp_togglePlugin(p);return o},fadeTo:function(y,x,w){if(typeof x=="function"){w=x;x=500}if(w){var v=e();s[v]=w}this.display=q._api().fp_fadeTo(p,y,x,v);this.opacity=y;return o},fadeIn:function(w,v){return o.fadeTo(1,w,v)},fadeOut:function(w,v){return o.fadeTo(0,w,v)},getName:function(){return p},getPlayer:function(){return q},_fireEvent:function(w,v,x){if(w=="onUpdate"){var z=q._api().fp_getPlugin(p);if(!z){return}i(o,z);delete o.methods;if(!u){m(z.methods,function(){var B=""+this;o[B]=function(){var C=[].slice.call(arguments);var D=q._api().fp_invoke(p,B,C);return D==="undefined"||D===undefined?o:D}});u=true}}var A=s[w];if(A){var y=A.apply(o,v);if(w.slice(0,1)=="_"){delete s[w]}return y}return o}})};function b(q,G,t){var w=this,v=null,D=false,u,s,F=[],y={},x={},E,r,p,C,o,A;i(w,{id:function(){return E},isLoaded:function(){return(v!==null&&v.fp_play!==undefined&&!D)},getParent:function(){return q},hide:function(H){if(H){q.style.height="0px"}if(w.isLoaded()){v.style.height="0px"}return w},show:function(){q.style.height=A+"px";if(w.isLoaded()){v.style.height=o+"px"}return w},isHidden:function(){return w.isLoaded()&&parseInt(v.style.height,10)===0},load:function(J){if(!w.isLoaded()&&w._fireEvent("onBeforeLoad")!==false){var H=function(){u=q.innerHTML;if(u&&!flashembed.isSupported(G.version)){q.innerHTML=""}if(J){J.cached=true;j(x,"onLoad",J)}flashembed(q,G,{config:t})};var I=0;m(a,function(){this.unload(function(K){if(++I==a.length){H()}})})}return w},unload:function(J){if(this.isFullscreen()&&/WebKit/i.test(navigator.userAgent)){if(J){J(false)}return w}if(u.replace(/\s/g,"")!==""){if(w._fireEvent("onBeforeUnload")===false){if(J){J(false)}return w}D=true;try{if(v){v.fp_close();w._fireEvent("onUnload")}}catch(H){}var I=function(){v=null;q.innerHTML=u;D=false;if(J){J(true)}};setTimeout(I,50)}else{if(J){J(false)}}return w},getClip:function(H){if(H===undefined){H=C}return F[H]},getCommonClip:function(){return s},getPlaylist:function(){return F},getPlugin:function(H){var J=y[H];if(!J&&w.isLoaded()){var I=w._api().fp_getPlugin(H);if(I){J=new l(H,I,w);y[H]=J}}return J},getScreen:function(){return w.getPlugin("screen")},getControls:function(){return w.getPlugin("controls")._fireEvent("onUpdate")},getLogo:function(){try{return w.getPlugin("logo")._fireEvent("onUpdate")}catch(H){}},getPlay:function(){return w.getPlugin("play")._fireEvent("onUpdate")},getConfig:function(H){return H?k(t):t},getFlashParams:function(){return G},loadPlugin:function(K,J,M,L){if(typeof M=="function"){L=M;M={}}var I=L?e():"_";w._api().fp_loadPlugin(K,J,M,I);var H={};H[I]=L;var N=new l(K,null,w,H);y[K]=N;return N},getState:function(){return w.isLoaded()?v.fp_getState():-1},play:function(I,H){var J=function(){if(I!==undefined){w._api().fp_play(I,H)}else{w._api().fp_play()}};if(w.isLoaded()){J()}else{if(D){setTimeout(function(){w.play(I,H)},50)}else{w.load(function(){J()})}}return w},getVersion:function(){var I="flowplayer.js 3.2.6";if(w.isLoaded()){var H=v.fp_getVersion();H.push(I);return H}return I},_api:function(){if(!w.isLoaded()){throw"Flowplayer "+w.id()+" not loaded when calling an API method"}return v},setClip:function(H){w.setPlaylist([H]);return w},getIndex:function(){return p},_swfHeight:function(){return v.clientHeight}});m(("Click*,Load*,Unload*,Keypress*,Volume*,Mute*,Unmute*,PlaylistReplace,ClipAdd,Fullscreen*,FullscreenExit,Error,MouseOver,MouseOut").split(","),function(){var H="on"+this;if(H.indexOf("*")!=-1){H=H.slice(0,H.length-1);var I="onBefore"+H.slice(2);w[I]=function(J){j(x,I,J);return w}}w[H]=function(J){j(x,H,J);return w}});m(("pause,resume,mute,unmute,stop,toggle,seek,getStatus,getVolume,setVolume,getTime,isPaused,isPlaying,startBuffering,stopBuffering,isFullscreen,toggleFullscreen,reset,close,setPlaylist,addClip,playFeed,setKeyboardShortcutsEnabled,isKeyboardShortcutsEnabled").split(","),function(){var H=this;w[H]=function(J,I){if(!w.isLoaded()){return w}var K=null;if(J!==undefined&&I!==undefined){K=v["fp_"+H](J,I)}else{K=(J===undefined)?v["fp_"+H]():v["fp_"+H](J)}return K==="undefined"||K===undefined?w:K}});w._fireEvent=function(Q){if(typeof Q=="string"){Q=[Q]}var R=Q[0],O=Q[1],M=Q[2],L=Q[3],K=0;if(t.debug){g(Q)}if(!w.isLoaded()&&R=="onLoad"&&O=="player"){v=v||c(r);o=w._swfHeight();m(F,function(){this._fireEvent("onLoad")});m(y,function(S,T){T._fireEvent("onUpdate")});s._fireEvent("onLoad")}if(R=="onLoad"&&O!="player"){return}if(R=="onError"){if(typeof O=="string"||(typeof O=="number"&&typeof M=="number")){O=M;M=L}}if(R=="onContextMenu"){m(t.contextMenu[O],function(S,T){T.call(w)});return}if(R=="onPluginEvent"||R=="onBeforePluginEvent"){var H=O.name||O;var I=y[H];if(I){I._fireEvent("onUpdate",O);return I._fireEvent(M,Q.slice(3))}return}if(R=="onPlaylistReplace"){F=[];var N=0;m(O,function(){F.push(new h(this,N++,w))})}if(R=="onClipAdd"){if(O.isInStream){return}O=new h(O,M,w);F.splice(M,0,O);for(K=M+1;K<F.length;K++){F[K].index++}}var P=true;if(typeof O=="number"&&O<F.length){C=O;var J=F[O];if(J){P=J._fireEvent(R,M,L)}if(!J||P!==false){P=s._fireEvent(R,M,L,J)}}m(x[R],function(){P=this.call(w,O,M);if(this.cached){x[R].splice(K,1)}if(P===false){return false}K++});return P};function B(){if($f(q)){$f(q).getParent().innerHTML="";p=$f(q).getIndex();a[p]=w}else{a.push(w);p=a.length-1}A=parseInt(q.style.height,10)||q.clientHeight;E=q.id||"fp"+e();r=G.id||E+"_api";G.id=r;t.playerId=E;if(typeof t=="string"){t={clip:{url:t}}}if(typeof t.clip=="string"){t.clip={url:t.clip}}t.clip=t.clip||{};if(q.getAttribute("href",2)&&!t.clip.url){t.clip.url=q.getAttribute("href",2)}s=new h(t.clip,-1,w);t.playlist=t.playlist||[t.clip];var I=0;m(t.playlist,function(){var K=this;if(typeof K=="object"&&K.length){K={url:""+K}}m(t.clip,function(L,M){if(M!==undefined&&K[L]===undefined&&typeof M!="function"){K[L]=M}});t.playlist[I]=K;K=new h(K,I,w);F.push(K);I++});m(t,function(K,L){if(typeof L=="function"){if(s[K]){s[K](L)}else{j(x,K,L)}delete t[K]}});m(t.plugins,function(K,L){if(L){y[K]=new l(K,L,w)}});if(!t.plugins||t.plugins.controls===undefined){y.controls=new l("controls",null,w)}y.canvas=new l("canvas",null,w);u=q.innerHTML;function J(L){var K=w.hasiPadSupport&&w.hasiPadSupport();if(/iPad|iPhone|iPod/i.test(navigator.userAgent)&&!/.flv$/i.test(F[0].url)&&!K){return true}if(!w.isLoaded()&&w._fireEvent("onBeforeClick")!==false){w.load()}return f(L)}function H(){if(u.replace(/\s/g,"")!==""){if(q.addEventListener){q.addEventListener("click",J,false)}else{if(q.attachEvent){q.attachEvent("onclick",J)}}}else{if(q.addEventListener){q.addEventListener("click",f,false)}w.load()}}setTimeout(H,0)}if(typeof q=="string"){var z=c(q);if(!z){throw"Flowplayer cannot access element: "+q}q=z;B()}else{B()}}var a=[];function d(o){this.length=o.length;this.each=function(p){m(o,p)};this.size=function(){return o.length}}window.flowplayer=window.$f=function(){var p=null;var o=arguments[0];if(!arguments.length){m(a,function(){if(this.isLoaded()){p=this;return false}});return p||a[0]}if(arguments.length==1){if(typeof o=="number"){return a[o]}else{if(o=="*"){return new d(a)}m(a,function(){if(this.id()==o.id||this.id()==o||this.getParent()==o){p=this;return false}});return p}}if(arguments.length>1){var t=arguments[1],q=(arguments.length==3)?arguments[2]:{};if(typeof t=="string"){t={src:t}}t=i({bgcolor:"#000000",version:[9,0],expressInstall:"http://static.flowplayer.org/swf/expressinstall.swf",cachebusting:false},t);if(typeof o=="string"){if(o.indexOf(".")!=-1){var s=[];m(n(o),function(){s.push(new b(this,k(t),k(q)))});return new d(s)}else{var r=c(o);return new b(r!==null?r:o,t,q)}}else{if(o){return new b(o,t,q)}}}return null};i(window.$f,{fireEvent:function(){var o=[].slice.call(arguments);var q=$f(o[0]);return q?q._fireEvent(o.slice(1)):null},addPlugin:function(o,p){b.prototype[o]=p;return $f},each:m,extend:i});if(typeof jQuery=="function"){jQuery.fn.flowplayer=function(q,p){if(!arguments.length||typeof arguments[0]=="number"){var o=[];this.each(function(){var r=$f(this);if(r){o.push(r)}});return arguments.length?o[arguments[0]]:new d(o)}return this.each(function(){$f(this,k(q),p?k(p):{})})}}})();(function(){var e=typeof jQuery=="function";var i={width:"100%",height:"100%",allowfullscreen:true,allowscriptaccess:"always",quality:"high",version:null,onFail:null,expressInstall:null,w3c:false,cachebusting:false};if(e){jQuery.tools=jQuery.tools||{};jQuery.tools.flashembed={version:"1.0.4",conf:i}}function j(){if(c.done){return false}var l=document;if(l&&l.getElementsByTagName&&l.getElementById&&l.body){clearInterval(c.timer);c.timer=null;for(var k=0;k<c.ready.length;k++){c.ready[k].call()}c.ready=null;c.done=true}}var c=e?jQuery:function(k){if(c.done){return k()}if(c.timer){c.ready.push(k)}else{c.ready=[k];c.timer=setInterval(j,13)}};function f(l,k){if(k){for(key in k){if(k.hasOwnProperty(key)){l[key]=k[key]}}}return l}function g(k){switch(h(k)){case"string":k=k.replace(new RegExp('(["\\\\])',"g"),"\\$1");k=k.replace(/^\s?(\d+)%/,"$1pct");return'"'+k+'"';case"array":return"["+b(k,function(n){return g(n)}).join(",")+"]";case"function":return'"function()"';case"object":var l=[];for(var m in k){if(k.hasOwnProperty(m)){l.push('"'+m+'":'+g(k[m]))}}return"{"+l.join(",")+"}"}return String(k).replace(/\s/g," ").replace(/\'/g,'"')}function h(l){if(l===null||l===undefined){return false}var k=typeof l;return(k=="object"&&l.push)?"array":k}if(window.attachEvent){window.attachEvent("onbeforeunload",function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){}})}function b(k,n){var m=[];for(var l in k){if(k.hasOwnProperty(l)){m[l]=n(k[l])}}return m}function a(r,t){var q=f({},r);var s=document.all;var n='<object width="'+q.width+'" height="'+q.height+'"';if(s&&!q.id){q.id="_"+(""+Math.random()).substring(9)}if(q.id){n+=' id="'+q.id+'"'}if(q.cachebusting){q.src+=((q.src.indexOf("?")!=-1?"&":"?")+Math.random())}if(q.w3c||!s){n+=' data="'+q.src+'" type="application/x-shockwave-flash"'}else{n+=' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'}n+=">";if(q.w3c||s){n+='<param name="movie" value="'+q.src+'" />'}q.width=q.height=q.id=q.w3c=q.src=null;for(var l in q){if(q[l]!==null){n+='<param name="'+l+'" value="'+q[l]+'" />'}}var o="";if(t){for(var m in t){if(t[m]!==null){o+=m+"="+(typeof t[m]=="object"?g(t[m]):t[m])+"&"}}o=o.substring(0,o.length-1);n+='<param name="flashvars" value=\''+o+"' />"}n+="</object>";return n}function d(m,p,l){var k=flashembed.getVersion();f(this,{getContainer:function(){return m},getConf:function(){return p},getVersion:function(){return k},getFlashvars:function(){return l},getApi:function(){return m.firstChild},getHTML:function(){return a(p,l)}});var q=p.version;var r=p.expressInstall;var o=!q||flashembed.isSupported(q);if(o){p.onFail=p.version=p.expressInstall=null;m.innerHTML=a(p,l)}else{if(q&&r&&flashembed.isSupported([6,65])){f(p,{src:r});l={MMredirectURL:location.href,MMplayerType:"PlugIn",MMdoctitle:document.title};m.innerHTML=a(p,l)}else{if(m.innerHTML.replace(/\s/g,"")!==""){}else{m.innerHTML="<h2>Flash version "+q+" or greater is required</h2><h3>"+(k[0]>0?"Your version is "+k:"You have no flash plugin installed")+"</h3>"+(m.tagName=="A"?"<p>Click here to download latest version</p>":"<p>Download latest version from <a href='http://www.adobe.com/go/getflashplayer'>here</a></p>");if(m.tagName=="A"){m.onclick=function(){location.href="http://www.adobe.com/go/getflashplayer"}}}}}if(!o&&p.onFail){var n=p.onFail.call(this);if(typeof n=="string"){m.innerHTML=n}}if(document.all){window[p.id]=document.getElementById(p.id)}}window.flashembed=function(l,m,k){if(typeof l=="string"){var n=document.getElementById(l);if(n){l=n}else{c(function(){flashembed(l,m,k)});return}}if(!l){return}if(typeof m=="string"){m={src:m}}var o=f({},i);f(o,m);return new d(l,o,k)};f(window.flashembed,{getVersion:function(){var m=[0,0];if(navigator.plugins&&typeof navigator.plugins["Shockwave Flash"]=="object"){var l=navigator.plugins["Shockwave Flash"].description;if(typeof l!="undefined"){l=l.replace(/^.*\s+(\S+\s+\S+$)/,"$1");var n=parseInt(l.replace(/^(.*)\..*$/,"$1"),10);var r=/r/.test(l)?parseInt(l.replace(/^.*r(.*)$/,"$1"),10):0;m=[n,r]}}else{if(window.ActiveXObject){try{var p=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7")}catch(q){try{p=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");m=[6,0];p.AllowScriptAccess="always"}catch(k){if(m[0]==6){return m}}try{p=new ActiveXObject("ShockwaveFlash.ShockwaveFlash")}catch(o){}}if(typeof p=="object"){l=p.GetVariable("$version");if(typeof l!="undefined"){l=l.replace(/^\S+\s+(.*)$/,"$1").split(",");m=[parseInt(l[0],10),parseInt(l[2],10)]}}}}return m},isSupported:function(k){var m=flashembed.getVersion();var l=(m[0]>k[0])||(m[0]==k[0]&&m[1]>=k[1]);return l},domReady:c,asString:g,getHTML:a});if(e){jQuery.fn.flashembed=function(l,k){var m=null;this.each(function(){m=flashembed(this,l,k)});return l.api===false?this:m}}})();if ('DrVideo' in window) {
	DrVideo._tools.adplay = {
		queue: [],
		mainId: null,
		callbacks: {
			finished: function(data) {
				if (DrVideo._tools.adplay.queue[0].id === data.videoId) {
					DrVideo._tools.adplay.queue.shift();
					if (DrVideo._tools.adplay.queue.length > 0) {
						DrVideo.API.execute('play', data.id, {id: DrVideo._tools.adplay.queue[0].id});
					} else {
						DrVideo._callbacks.fireEvent('queueEnded', data);
					}
				}
			}
		}
	};
	DrVideo._callbacks.events.queueEnded = {
		functions: []
	};
	DrVideo.API.play = function(id, parentElement, optionsObject) {		
		D = DrVideo, position = D._tools.getPosition(parentElement);
		if (!position) {
			return false;
		}
		if (!(typeof optionsObject === 'object' && optionsObject)) {
			var optionsObject = {};
		}
		if (!(typeof DrVideoAds === 'object') && 'NettTvAds' in window) {
			DrVideoAds = NettTvAds;
		}
		// If DrVideoAds object exists, overwrite content for ads in optionsObject.
		if (typeof DrVideoAds === 'object' && DrVideoAds && !(typeof optionsObject.videosBefore === undefined)) {
			if (DrVideoAds.preAds && typeof DrVideoAds.preAds === 'object') {
				var currentElement = {};
				if (typeof DrVideoAds.preAds.id === 'number' && (DrVideoAds.preAds.id > 0 || DrVideoAds.preAds.id < 0)) {
					currentElement.id = DrVideoAds.preAds.id;
					currentElement.isSeekable = false;
				}
				if (typeof DrVideoAds.preAds.url === 'string' && DrVideoAds.preAds.url.length > 0) {
					currentElement.clickUrl = DrVideoAds.preAds.url;
				}
				optionsObject.videosBefore = [];
				optionsObject.videosBefore.push(currentElement);
			}
		}
		if (typeof DrVideo._tools.adplay === 'object' && DrVideo._tools.adplay && typeof DrVideoAds === 'object' && DrVideoAds && !(typeof optionsObject.videosAfter === undefined)) {
			if (DrVideoAds.postAds && typeof DrVideoAds.postAds === 'object') {
				var currentElement = {};
				if (DrVideoAds.postAds && (DrVideoAds.postAds.id > 0 || DrVideoAds.postAds.id < 0)) {
					currentElement.id = DrVideoAds.postAds.id;
					currentElement.isSeekable = false;
				}
				if (typeof DrVideoAds.postAds.url === 'string' && DrVideoAds.postAds.url.length > 0) {
					currentElement.clickUrl = DrVideoAds.postAds.url;
				}
				optionsObject.videosAfter = [];
				optionsObject.videosAfter.push(currentElement);
			}
		}
		var queue = [];
		if (typeof optionsObject === 'object' && optionsObject && typeof optionsObject.videosBefore === 'object' && optionsObject.videosBefore.constructor === Array) {
			for (i = 0, iMax = optionsObject.videosBefore.length; i < iMax; i++) {
				var currentElement = {};
				if (typeof optionsObject.videosBefore[i].id === 'number' && (optionsObject.videosBefore[i].id = D._tools.getInt(optionsObject.videosBefore[i].id)) !== null) {
					currentElement.id = optionsObject.videosBefore[i].id;
				}
				if (typeof optionsObject.videosBefore[i].clickUrl === 'string' && optionsObject.videosBefore[i].clickUrl.length > 0) {
					currentElement.clickUrl = optionsObject.videosBefore[i].clickUrl;
				}
				if (typeof optionsObject.videosBefore[i].isSeekable === 'boolean') {
					currentElement.isSeekable = optionsObject.videosBefore[i].isSeekable;
				}
				queue.push(currentElement);
			}
		}
		queue.push({id: id});
		if (typeof optionsObject === 'object' && optionsObject && typeof optionsObject.videosAfter === 'object' && optionsObject.videosAfter.constructor === Array) {
			for (i = 0, iMax = optionsObject.videosAfter.length; i < iMax; i++) {
				var currentElement = {};
				if (typeof optionsObject.videosAfter[i].id === 'number' && (optionsObject.videosAfter[i].id = D._tools.getInt(optionsObject.videosAfter[i].id)) !== null) {
					currentElement.id = optionsObject.videosAfter[i].id;
				}
				if (typeof optionsObject.videosAfter[i].clickUrl === 'string' && optionsObject.videosAfter[i].clickUrl.length > 0) {
					currentElement.clickUrl = optionsObject.videosAfter[i].clickUrl;
				}
				if (typeof optionsObject.videosAfter[i].seekable === 'boolean') {
					currentElement.isSeekable = optionsObject.videosAfter[i].seekable;
				}
				queue.push(currentElement);
			}
		}
		// do clickUrl and isSeekable handling
		if ('_decoders' in DrVideo && 'flash' in DrVideo._decoders) {
			DrVideo._decoders.flash.overload.loadingObject = function (loadingObject, position) {
				if (D._tools.adplay.queue[0] && typeof D._tools.adplay.queue[0].clickUrl === 'string' && D._tools.adplay.queue[0].clickUrl.length > 0) {
					loadingObject.clip.linkUrl = D._tools.adplay.queue[0].clickUrl;
					loadingObject.clip.linkWindow = '_blank';
				}
				if (D._tools.adplay.queue[0] && typeof D._tools.adplay.queue[0].isSeekable === 'boolean' && D._tools.adplay.queue[0].isSeekable === false && position.loadingId !== D._tools.adplay.mainId) {
					loadingObject.clip.onBeforeSeek = function() {return false;};
				}
		                var V = DrVideo._videos['v' + position.loadingId];
                		if (typeof V.meta === 'object') {
		                    // Enable live stream subscription
		                    if (V.meta.dateLive && typeof V.meta.dateLive === 'number') {
                		        loadingObject.clip.live = true;
		                    }
                		}
			};
		}
		// mainId is used for DrKlikk
		if (!(typeof D._tools.adplay.mainId === 'number' && D._tools.adplay.mainId > 0)) {
			D._tools.adplay.mainId = id;
		}
		DrVideo.API.addCallback('play', DrVideo._drklikk.callback);
		DrVideo.API.addCallback('ended', D._tools.adplay.callbacks.finished, parentElement);
		DrVideo.API.addCallback('noDecoderAvailable', D._tools.adplay.callbacks.finished, parentElement);
		D._tools.adplay.queue = queue;
		if (queue.length < 2) {
			if (queue.length === 1) {
				return DrVideo.API.execute('play', parentElement, {id: id, optionsObject: optionsObject});
			}
		}
		return DrVideo.API.execute('play', parentElement, {id: D._tools.adplay.queue[0].id, optionsObject: optionsObject});
	};
	DrVideo._drklikk = {
		pageType: 'api',
		text1Base: '', 
		callback: function(data) {
			if (data.videoId === D._tools.adplay.mainId && DrVideo._drklikk.text1Base != undefined && DrVideo._drklikk.text1Base.length > 0) {
				var img = document.createElement('img');
				img.style.display = 'none';
				var src = 'http://drklikk.drvideo.aptoma.no/register/betalive.php?nocache=' + new Date().getTime() + '&event=videoplay&identification=' + data.videoId + '&text1=' + DrVideo._drklikk.text1Base + '-' + DrVideo._drklikk.pageType;
				if (typeof data.meta === 'object' && data.meta && typeof data.meta.categoryId === 'number') {
						src += '&text2=' + data.meta.categoryId;
				}
				img.setAttribute('src', src);
				document.getElementsByTagName('HEAD')[0].appendChild(img);
			}
		}
	}
}
var Edda = {
	related: {
		index: -1,
		videos: null,
		timeout: null,
		activeVideoId: null,
		previous: function()
		{
			if (!Edda.related.videos) {
				return;
			}
			if (Edda.related.index < 1) {
				Edda.related.index = Edda.related.videos.length - 1;
			} else {
				Edda.related.index--;
			}
			Edda.related.render();
		},
		next: function()
		{
			if (!Edda.related.videos) {
				return;
			}
			if (Edda.related.index === (Edda.related.videos.length - 1)) {
				Edda.related.index = 0;
			} else {
				Edda.related.index++;
			}
			Edda.related.render();
		},
		render: function()
		{
			clearTimeout(Edda.related.timeout);
			var relatedContainer = document.getElementById('related-container');
			if (!relatedContainer) {
				return;
			}
			var videos = Edda.related.videos[Edda.related.index];
			var wrapper = document.createElement('ul');
			wrapper.style.width = '400px';
			wrapper.style.margin = '0 auto';
			wrapper.style.float = 'none';
			if (!(typeof NettTv.parentElement === 'string' && NettTv.parentElement.length > 0)) {
				return;
			}
			for (var i = 0, iMax = videos.length; i < iMax; i++) {
				var listItem = document.createElement('li');
				listItem.style.backgroundColor = '#111';
				listItem.style.cssFloat = 'left';
				listItem.style.styleFloat = 'left';
				listItem.style.listStyleType = 'none';
				listItem.style.margin = '10% 2% 0% 2%';
				listItem.style.width = '184px';
				listItem.style.height = '164px';
				var anchorTag = document.createElement('a');
				anchorTag.setAttribute('Title', 'Klikk for å spille av "' + videos[i].title + '"');
				anchorTag.setAttribute('href', '?id=' + videos[i].id);
				anchorTag.setAttribute('onclick', 'NettTv.API.play(' + videos[i].id + ', ' + '\'' + NettTv.parentElement + '\'); return false;');
				anchorTag.setAttribute('class', 'endscreen-video-preview-elm');
				anchorTag.style.padding = '12px';
				anchorTag.style.width = '160px';
				anchorTag.style.height = '140px';
				anchorTag.style.display = 'block';
				anchorTag.style.margin = '3px';
				anchorTag.style.textDecoration = 'none';
				anchorTag.style.color = '#ccc';
				anchorTag.onmouseover = function() {
					this.style.color = 'white';
					this.style.backgroundColor = '#232323';
				}
				anchorTag.onmouseout = function() {
					this.style.color = '#ccc';
					this.style.backgroundColor = '#101010';
				}
				var imageDiv = document.createElement('div');
				if (typeof videos[i]['x-imageId'] === 'number' && videos[i]['x-imageId'] > 0) {
					imageDiv.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../out/img/' + videos[i]['x-imageId'] + '_160px.jpg)';
				}
				imageDiv.style.width = '100%';
				imageDiv.style.height = '90px';
				imageDiv.style.cssFloat = 'left';
				imageDiv.style.styleFloat = 'left';
				imageDiv.style.overflow = 'hidden';
				imageDiv.setAttribute('class', 'endscreen-video-preview-elm');
				var title = document.createElement('span');
				title.innerHTML = videos[i].title;
				title.style.margin = '5px auto';
				title.style.cssFloat = 'left';
				title.style.styleFloat = 'left';
				title.style.height = '35px';
				title.style.overflow = 'hidden';
				title.style.display = 'block';
				title.style.fontWeight = 'bold';
				title.setAttribute('class', 'endscreen-video-preview-elm');
				anchorTag.appendChild(imageDiv);
				anchorTag.appendChild(title);
				listItem.appendChild(anchorTag);
				wrapper.appendChild(listItem);
			}
			relatedContainer.innerHTML = '';
			relatedContainer.appendChild(wrapper);
			Edda.related.timeout = setTimeout(Edda.related.next, 5000);
		}
	},
	clipEnded: function (data){
		if ('console' in window) {
			console.log("queueEnded");
		}
		if (!(DrVideo._tools.multiplay.queue && DrVideo._tools.multiplay.queue.length && DrVideo._tools.multiplay.queue.length > 0) && (NettTv.loadedId)) {
			// @todo load related from cache
			return DrVideo._tools.request('related/?id=' + NettTv.loadedId + '&callback=Edda.endscreen&limit=8');
		}
	},
	fillEmbedCode: function (data) {
		var embedCodeLinkContainer = document.getElementById('related-container-embedcode-link');
		if (!(typeof data === 'object' && data && typeof data.videos === 'object' && data.videos && embedCodeLinkContainer != 'undefined')) {
			return;
		}
		for (var i in data.videos) {
			if (typeof data.videos[i].embedCode === 'string' && data.videos[i].embedCode.length > 0) {
				embedCodeLinkContainer.value = data.videos[i].embedCode;
				// @todo put embedCode in cache
				return true;
			}
		}
		return true;
	},
	toggleSharingMenu: function (data) {
		var sharingMenu = document.getElementById('sharingmenu');
		var relatedContainer = document.getElementById('related-container');
		if (sharingMenu === 'undefined' || relatedContainer === 'undefined') {
			return false;
		}
		if (sharingMenu.style.display === 'block' && relatedContainer.style.display === 'none') {
			sharingMenu.style.display = 'none';
			relatedContainer.style.display = 'block';
		} else if (sharingMenu.style.display === 'none' && relatedContainer.style.display === 'block') {
			sharingMenu.style.display = 'block';
			relatedContainer.style.display = 'none';
			// @todo load embedCode from cache
			var script = document.createElement('script');
			script.setAttribute('type', 'text/javascript');
			script.setAttribute('charset', 'utf-8');
			script.setAttribute('src', DrVideo._tools.path + '/../api/?do=feed&action=id&value=' + Edda.related.activeVideoId + '&returntype=json&callback=Edda.fillEmbedCode');
			document.getElementsByTagName('head')[0].appendChild(script);
		}
		return false;
	},
	endscreen: function (data)
	{
		if (!(typeof data === 'object' && data && typeof data.status === 'number' && data.status === 200)) {
			return;
		}
		DrVideo.API.pause();
		// @todo load related from cache
		Edda.related.videos = [];
		Edda.related.activeVideoId = data.videoId;
		Edda.isEdda = true;
		if (typeof DrVideo._tools.path === 'string' && (DrVideo._tools.path === 'http://budstikka.netttv.aptoma.no/data' || DrVideo._tools.path === 'http://hm-media.netttv.aptoma.no/data')) {
			Edda.isEdda = false;
		}
		var iMax = 8;
		if (data.videos.length < 8) {
			iMax = data.videos.length;
		}
		for (var i = 0; i < iMax; i++) {
			var index = Math.floor(i / 2);
			if (!Edda.related.videos[index]) {
				Edda.related.videos[index] = [];
			}
			Edda.related.videos[index].push(data.videos[i]);
		}
		if (!(typeof NettTv.parentElement === 'string' && NettTv.parentElement.length > 0)) {
			return;
		}
		var videoParent = document.getElementById(NettTv.parentElement);
		var height = videoParent.clientHeight + 'px';
		var relatedVideos = document.createElement('div');
		var fragment = document.createDocumentFragment();
		var videoUrl = document.location.protocol + '//' + document.location.host + (document.location.port !== '' ? ':' + document.location.port : '') + document.location.pathname + '?videoId=' + data.videoId;
		var share = document.createElement('a');
		share.setAttribute('title', 'Klikk for å dele');
		share.setAttribute('href', '#');
		share.setAttribute('onclick', 'Edda.toggleSharingMenu();return false;');
		share.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../gfx/related_button_share.png)';
		share.style.margin = '3% 4% 0px 4%';
		share.style.cssFloat = 'left';
		share.style.styleFloat = 'left';
		share.style.width = '146px';
		share.style.height = '90px';
		if (Edda.isEdda === false) {
			share.style.display = 'none';
		} else {
			share.style.display = 'block';
		}
		share.onmouseover = function() {
			share.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../gfx/related_button_share_hover.png)';
		}
		share.onmouseout = function() {
			share.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../gfx/related_button_share.png)';
		}
		var recommend = document.createElement('a');
		recommend.setAttribute('title', 'Klikk for å anbefale denne videoen');
		recommend.setAttribute('href', '#');
		if (typeof rateVideo === 'function') {
			recommend.setAttribute('onclick', 'rateVideo(' + data.videoId + '); return false;');
		}
		recommend.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../gfx/related_button_recommend.png)';
		recommend.style.margin = '3% 4% 0px 5%';
		recommend.style.cssFloat = 'left';
		recommend.style.styleFloat = 'left';
		recommend.style.width = '146px';
		recommend.style.height = ' 90px';
		if (Edda.isEdda === false) {
			recommend.style.display = 'none';
		} else {
			recommend.style.display = 'block';
		}
		recommend.onmouseover = function() {
			recommend.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../gfx/related_button_recommend_hover.png)';
		}
		recommend.onmouseout = function() {
			recommend.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../gfx/related_button_recommend.png)';
		}
		var replay = document.createElement('a');
		replay.setAttribute('title', 'Klikk for å spille av dette klippet igjen');
		replay.setAttribute('href', '?id=' + data.videoId);
		if (typeof NettTv.parentElement === 'string' && NettTv.parentElement.length > 0) {
			replay.setAttribute('onclick', 'DrVideo.API.play(' + data.videoId + ', ' + '\'' + NettTv.parentElement + '\'); return false;');
		}
		replay.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../gfx/related_button_replay.png)';
		replay.style.cssFloat = 'left';
		replay.style.styleFloat = 'left';
		replay.style.width = '146px';
		replay.style.height = ' 90px';
		if (Edda.isEdda === false) {
			replay.style.margin = '3% 0% 0px 38%';
		} else {
			replay.style.margin = '3% 3% 0px 5%';
		}
		replay.onmouseover = function() {
			replay.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../gfx/related_button_replay_hover.png)';
		}
		replay.onmouseout = function() {
			replay.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../gfx/related_button_replay.png)';
		}
		var midContainer = document.createElement('div');
		midContainer.style.marginTop = '8%';
		midContainer.style.clear = 'both';
		var navPrev = document.createElement('a');
		navPrev.setAttribute('id', 'related-videos-previous');
		var navNext = document.createElement('a');
		navNext.setAttribute('id', 'related-videos-next');
		navPrev.setAttribute('href', '#');
		navNext.setAttribute('href', '#');
		navPrev.setAttribute('onclick', 'Edda.related.previous(); return false;');
		navNext.setAttribute('onclick', 'Edda.related.next(); return false;');
		navPrev.setAttribute('title', 'Klikk for å navigere til forrige sett relaterte videoer');
		navNext.setAttribute('title', 'Klikk for å navigere til neste sett relaterte videoer');
		navPrev.style.display = 'block';
		navPrev.style.width = '44px';
		navPrev.style.height = '93px';
		navPrev.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../gfx/related_navigation_prev.png)';
		navPrev.style.backgroundRepeat = 'no-repeat';
		navPrev.style.cssFloat = 'left';
		navPrev.style.styleFloat = 'left';
		navPrev.style.margin = '10% 0px 0px 0px';
		navPrev.onmouseover = function() {
			navPrev.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../gfx/related_navigation_prev_hover.png)';
		}
		navPrev.onmouseout = function() {
			navPrev.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../gfx/related_navigation_prev.png)';
		}
		navNext.style.display = 'block';
		navNext.style.width = '44px';
		navNext.style.height = '93px';
		navNext.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../gfx/related_navigation_next.png)';
		navNext.style.backgroundRepeat = 'no-repeat';
		navNext.style.cssFloat = 'right';
		navNext.style.styleFloat = 'right';
		navNext.style.margin = '10% 0px 0px 0px';
		navNext.onmouseover = function() {
			navNext.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../gfx/related_navigation_next_hover.png)';
		}
		navNext.onmouseout = function() {
			navNext.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../gfx/related_navigation_next.png)';
		}
		var sharingContainer = document.createElement('div');
		sharingContainer.style.color = '#eee';
		sharingContainer.style.fontWeight = 'bold';
		sharingContainer.setAttribute('id', 'sharingmenu');
		var sharingHeader = document.createElement('p');
		sharingHeader.innerHTML = 'Del videoen på nettet';
		sharingHeader.style.padding = '0px 0px 10px 0px';
		sharingHeader.style.margin = '0px';
		sharingHeader.style.fontSize = '16px';
		sharingHeader.style.fontWeight = 'bold';
		var sharingCloser = document.createElement('a');
		sharingCloser.setAttribute('href', '#');
		sharingCloser.setAttribute('onclick', 'return Edda.toggleSharingMenu();');
		sharingCloser.setAttribute('title', 'Lukk delingsmeny');
		sharingCloser.innerHTML = 'Lukk';
		sharingCloser.style.cssFloat = 'right';
		sharingCloser.style.styleFloat = 'right';
		sharingCloser.style.color = '#ccc';
		sharingCloser.style.fontSize = '10px';
		sharingContainer.appendChild(sharingCloser);
		sharingContainer.appendChild(sharingHeader);
		sharingContainer.style.width = '390px';
		sharingContainer.style.margin = '12% auto 0 auto';
		sharingContainer.style.display = 'block';
		sharingContainer.style.backgroundColor = '#323232';
		sharingContainer.style.padding = '10px';
		sharingElements = [];
		if (typeof shareVideo === 'function') {
			sharingElements.push({'name': 'Facebook', 'site': 'facebook'});
			sharingElements.push({'name': 'Twitter', 'site': 'twitter'});
			sharingElements.push({'name': 'del.ici.ous', 'site': 'delicious'});
			sharingElements.push({'name': 'MySpace', 'site': 'myspace'});
			sharingElements.push({'name': 'LinkedIn', 'site': 'linkedIn'});
			sharingElements.push({'name': 'Epost', 'site': 'email'});
		}
		var sharingUl = document.createElement('ul');
		sharingUl.style.listStyle = 'none';
		sharingUl.style.width = '100%';
		sharingUl.style.padding = '0';
		for (var i in sharingElements) {
			if (!(typeof sharingElements[i].site === 'string' && sharingElements[i].site.length > 0 && sharingElements[i].site != 'undefined')) {
				continue;
			}
			var sharingLi = document.createElement('li');
			var sharingA = document.createElement('a');
			sharingA.setAttribute('href', '#');
			sharingA.setAttribute('onclick', 'shareVideo(\'' + sharingElements[i].site + '\', ' + data.videoId + ');return false;');
			sharingA.setAttribute('title', 'Del på ' + sharingElements[i].name);
			sharingA.innerHTML = sharingElements[i].name;
			sharingA.style.textDecoration = 'none';
			sharingA.style.fontWeight = 'bold';
			sharingA.style.color = '#eee';
			sharingA.style.backgroundImage = 'url(' + DrVideo._tools.path + '/../gfx/' + sharingElements[i].site + '.png)';
			sharingA.style.backgroundPosition = '0px 50%';
			sharingA.style.backgroundRepeat = 'no-repeat';
			sharingA.style.display = 'block';
			sharingA.style.width = '24px';
			sharingLi.style.width = '100px';
			sharingA.style.padding = '3px 0px 3px 19px';
			sharingLi.style.cssFloat = 'left';
			sharingLi.style.styleFloat = 'left';
			sharingLi.style.paddingLeft = '0px';
			sharingLi.appendChild(sharingA);
			sharingUl.appendChild(sharingLi);
		}
		sharingContainer.appendChild(sharingUl);
		var sharingLinkBlock = document.createElement('div');
		sharingLinkBlock.style.padding = '0px';
		sharingLinkBlock.style.clear = 'both';
		sharingLinkBlock.innerHTML = 'Kopier linken til denne siden:';
		var sharingLink = document.createElement('input');
		sharingLink.value = videoUrl;
		sharingLink.style.borderWidth = '1px';
		sharingLink.style.borderColor = '#ccc';
		sharingLink.style.color = '#eee';
		sharingLink.style.fontSize = '10px';
		sharingLink.style.width = '160px';
		sharingLink.style.backgroundColor = 'black';
		sharingLink.style.cssFloat = 'right';
		sharingLink.style.styleFloat = 'right';
		sharingLink.setAttribute('onclick', 'this.select()');
		sharingLinkBlock.appendChild(sharingLink);
		sharingContainer.appendChild(sharingLinkBlock);
		var sharingEmbedBlock = document.createElement('div');
		sharingEmbedBlock.style.padding = '5px 0px';
		sharingEmbedBlock.style.clear = 'both';
		sharingEmbedBlock.innerHTML = 'Kopier embed-kode:';
		var sharingLinkEmbed = document.createElement('input');
		sharingLinkEmbed.value = videoUrl;
		sharingLinkEmbed.style.borderWidth = '1px';
		sharingLinkEmbed.style.borderColor = '#ccc';
		sharingLinkEmbed.style.color = '#eee';
		sharingLinkEmbed.style.fontSize = '10px';
		sharingLinkEmbed.style.width = '160px';
		sharingLinkEmbed.style.backgroundColor = 'black';
		sharingLinkEmbed.style.cssFloat = 'right';
		sharingLinkEmbed.style.styleFloat = 'right';
		sharingLinkEmbed.setAttribute('onclick', 'this.select()');
		sharingLinkEmbed.setAttribute('id', 'related-container-embedcode-link');
		sharingEmbedBlock.appendChild(sharingLinkEmbed);
		sharingContainer.appendChild(sharingEmbedBlock);
		sharingContainer.style.display = 'none';
		var relatedContainer = document.createElement('div');
		relatedContainer.setAttribute('id', 'related-container');
		var fragmentContainer = document.createElement('div');
		fragmentContainer.style.width = '600px';
		fragmentContainer.style.margin = '0 auto';
		fragmentContainer.appendChild(share);
		fragmentContainer.appendChild(recommend);
		fragmentContainer.appendChild(replay);
		fragment.appendChild(fragmentContainer);
		midContainer.appendChild(navNext);
		midContainer.appendChild(navPrev);
		midContainer.appendChild(relatedContainer);
		fragment.appendChild(midContainer);
		relatedVideos.innerHTML = '';
		relatedVideos.setAttribute('id', 'related-videos');
		relatedVideos.style.height = height;
		relatedVideos.style.marginTop = '-' + (videoParent.clientHeight + 4) + 'px';
		relatedVideos.appendChild(fragment);
		relatedContainer.style.height = height;
		relatedContainer.style.width = '75%';
		relatedContainer.style.margin = '0 auto';
		relatedVideos.style.width = '100%';
		relatedVideos.style.position = 'relative';
		relatedVideos.style.overflow = 'hidden';
		relatedVideos.style.backgroundColor = '#000';
		relatedVideos.style.fontFamily = 'Tahoma,sans-serif';
		relatedVideos.style.fontSize = '13px';
		relatedVideos.style.display = 'block';
		relatedContainer.style.display = 'block';
		relatedVideos.appendChild(sharingContainer);
		videoParent.appendChild(relatedVideos);
		Edda.related.next();
	}
}
if ('DrVideo' in window) {
	if (typeof DrVideo._tools.multiplay === 'object' && DrVideo._tools.multiplay) {
		DrVideo.API.addCallback('queueEnded', Edda.clipEnded);
	} else {
		DrVideo.API.addCallback('ended', Edda.clipEnded);
	}
}
if (DrVideo._drklikk) {
	            DrVideo._drklikk.text1Base = 'edda-laagendalsposten';
}
if ('DrVideo' in window) {
	if (!('_edda' in DrVideo)) {
		DrVideo._edda = {};
	}
	// Rewrite to allow negative numbers
	DrVideo._tools.getInt = function (number) {
		if (typeof number === 'number' && !isNaN(number)) {
			number = parseInt(number, 10);
			if (number !== 0) {
				return number;
			}
		}
		return null;
	};
	// Copy reference original loadVideo function
	DrVideo._edda.loadVideoOriginal = DrVideo._loaders.loadVideo;
	// Overwrite original loadVideo function with special handling of negative ids
	DrVideo._loaders.loadVideo = function (id, position) {
		if (id > 0) {
			return DrVideo._edda.loadVideoOriginal(id, position);
		}
		var L = DrVideo._loaders.videosLoading;
		if (typeof L['v' + id] !== 'object') {
			L['v' + id] = [];
			DrVideo._tools.request('TEMP', [['src', 'http://edda-annonser.netttv.aptoma.no/data/actions/videostatus/?id=' + (id * -1) + '&callback=DrVideo._edda.globalAds.videoLoaded']]);
		}
		if (position) {
			L['v' + id][L['v' + id].length] = position.id;
		}
		return true;
	};
	// Custom videoLoaded function that makes incoming global ads report negative ids
	DrVideo._edda.globalAds = {
		videoLoaded: function (data) {
			if (!(typeof data === 'object' && data && typeof data.id === 'number')) {
				return;
			}
			data.id *= -1;
			DrVideo._loaders.videoLoaded(data);
		}
	};
}

