//var param = [];
var bVideo = null;
var bWasBuffering = false;
var autoPlayFeatured = true;
var playerType = "wmp";
/*
 * could be wmp:windows media player flash:flash video player swf : flash swf
 * player
 */
var wmpTimer;


var div = "tableDiv";
var pageNavTopDiv = "navCtlHeader";
var pageNavDownDiv = "navCtlFooter";
var maxRows = 30;
var maxCols = 1;

var param = {
	callID :'DEF_VID',
	renderStyle :5,
	imageIndex :0,
	div :div,
	pageNavTopDiv :pageNavTopDiv,
	pageNavDownDiv :pageNavDownDiv,
	pageTitleDiv :"navCtlTitle",
	imageWidth :200,
	imageHeight :30,
	maxRows :maxRows,
	maxCols :maxCols,
	thumbnailWidth :55,
	thumbnailHeight :45
};

var controlParam = {
	videoDiv :'videoSection',
	videoCtlDiv :'controlDiv',
	navCtlDiv :'navCtlDiv',
	featuredDiv :'featuredControlDiv',
	navCtlWidth :311,
	videoWidth :628,
	videoHeight :272
};

function initializePlayerVar() {

	setCookie("mode", "featured", null, null, null, null);

	setCookie('VideoCtlPageType', 'index', null, null, null, null); // tell of
																	// the page
																	// in which
																	// video is
																	// embeded

	// -- ----Alternate Between View Modes For First Time visites--------------
	var isFirstTime = getCookie("FirstTime");
	if (isFirstTime == null || isFirstTime == "") {
		var rnd = Math.random() * 100 % 4;
		if (rnd > 2) {
			setCookie("VideoNavCtlMode", "enlarged", null, null, null, null);

			reportUserAction("play_nav_resize_max::", null);

			if (rnd >= 2) {
				param.renderStyle = 6;
			}
		}// else do nothing, b'cos by default it is minimized

		setCookie('MediaTypeFilter', 'P', null, null, null, null); // show only
																	// videos
																	// first
	}
	setCookie("FirstTime", "false", null, null, null, null);

	// --------------------------------------------------------------------------

}
function PlayPlayer() {
	try {
		switch (playerType) {
		case "flash":
			playFlashMovie(currentURL);
			break;
		case "wmp":
			thisMovie("wmpocx").controls.play();
			break;
		default:

		}
	} catch (e) {
	}
	reportUserAction("play_resumed::", null);
}

function PausePlayer() {
	try {
		switch (playerType) {
		case "flash":
			thisMovie("flashplayer").pauseFlashMovie();
			break;
		case "wmp":
			if (thisMovie("wmpocx").controls.isAvailable('Pause'))
				thisMovie("wmpocx").controls.pause();
			break;
		default:

		}
	} catch (e) {
	}
}

function StopPlayer() {
	try {

		switch (playerType) {
		case "flash":
			stopFlashMovie();
			break;
		case "swf":
			// same html element is used for swf player and flv player
			clearInnerHTML(_elem("flashDiv"));
			// createPlayers();
			break;
		case "wmp":
			clearInterval(wmpTimer);
			thisMovie("wmpocx").controls.stop();
			break;
		default:
		}

		_elem("featuredControlDiv").style.zIndex = 30;

		currentURL = null;
		setTimeout("displayAdsInPlayer()", 15000);

	} catch (e) {
	}

	bWasBufferring = false;
	renderFeaturedCtl();
}

function PlayStateChange(NewState) {
	/*
	 * 0 Undefined Windows Media Player is in an undefined state. 1 Stopped
	 * Playback of the current media item is stopped. 2 Paused Playback of the
	 * current media item is paused. When a media item is paused, resuming
	 * playback begins from the same location. 3 Playing The current media item
	 * is playing. 4 ScanForward The current media item is fast forwarding. 5
	 * ScanReverse The current media item is fast rewinding. 6 Buffering The
	 * current media item is getting additional data from the server. 7 Waiting
	 * Connection is established, but the server is not sending data. Waiting
	 * for session to begin. 8 MediaEnded Media item has completed playback. 9
	 * Transitioning Preparing new media item. 10 Ready Ready to begin playing.
	 * 11 Reconnecting Reconnecting to stream
	 * 
	 * 
	 */
	switch (NewState) {
	case 1: // stopped
		currentURL = null;
		if (bWasBuffering) {
			bWasBufferring = false;

		}
		break;

	case 6: // buffering

		bWasBufferring = true;

		break;
	case 8:// Playback complete
		currentURL = null;

		StopPlayer();
		setTimeout("autoPlay()", 10000);

		break;

	case 9: // transitioning
	case 11: // reconnecting

		bWasBufferring = false;
		break;

	case 3: // playing

		if (bWasBufferring) {

			if (bVideo) {
				thisMovie("wmpocx").fullScreen = false;
			}
		}
		break;

	default:
	}
}
function fullScreen() {
	if (playerType == "wmp") {
		if (bVideo) {
			thisMovie("wmpocx").fullScreen = true;
		}
	} else if (playerType == "flv" || playerType == "swf") {
		fullScreenFlashMovie();
	}

}

var playVideoDelayedUrl = null;

function playVideoDelayedBy(url, delay) {
	if (playVideoDelayedUrl == url) { // avoid repeating this process
		// setTimeout("playVideo('"+playVideoDelayedUrl+"')",delay);
		return;
	} else {
		playVideoDelayedUrl = url;

	}
	/*
	 * playVideoDelayed is usually called from backing bean display appropriate
	 * videos in navigation
	 */
	playAfterAjaxCall = true;
	/*
	 * To be sure all of this media security has been met, pass the url back to
	 * ther server and play the first record since the server will return
	 * records pertaining to this media
	 */
	loadNavigation('notification',
			'notificationType=findRelated&url=' + encodeURIComponent(url),
			param);

}
function playVideoDelayed(url) {
	playVideoDelayedBy(url, 5500);
}

var playAfterAjaxCall = false;
function prePlaySelectedVideo(collectionId, index) {
	var collection = findCollection(collectionId);
	if (collection != null && collection.images[index] != null) {
		playSelectedVideo(collectionId, index);
	} else {
		// access to content might have been denied
		loadNavigation('notification', 'notificationType=findRelated',
				getParamFromList(collectionId));// display other video
	}

}

var currentURL = null;
var MAX_ALLOWED_FREE_VIEW = 10;

function playVideo(url) {
	// ------------------------------------------------------------
	// force all users to signin after watching a number of times dictated by

	var contentViewCount = (getCookie("contentViewCount") == null ? 0
			: parseInt(getCookie("contentViewCount")));

	if (!hasSignedIn() && contentViewCount > MAX_ALLOWED_FREE_VIEW) {
		setCookie("scriptAfterLogin", "playVideo('" + url + "');", null, null,
				null, null);
		signin();
		return;
	}

	setCookie("contentViewCount", 1 + contentViewCount);

	// ---------------------------------------------------------

	if (url == null) {
		return;
	}

	// stop current play if any
	StopPlayer();

	try {
		_elem("featuredControlDiv").style.display = 'none';
	} catch (e) {
	}
	try {
		_elem("adsDiv").style.display = 'none';
	} catch (e) {
	}

	// file type determines the player used
	var ext = url.substr(url.lastIndexOf(".") + 1);
	ext = ext.toLowerCase();

	switch (ext) {

	case "flv":
		playerType = "flash";
		break;

	case "swf":// flash video player does not support swf files -find another
		// way round this
		playerType = "swf";

		break;
	case "dcr":
		playerType = "swf";
		break;
	case "mp3":
		/* playerType = "wmp"; */
		if (isIE()) {// is ie
			playerType = "wmp";
		} else {
			playerType = "quicktime";
		}
		break;

	case "mov":
		playerType = "quicktime";
		break;

	case "avi":
		playerType = "flash";
		break;
	case "mp4":
		playerType = "quicktime";
		break;
	case "m4v":
		playerType = "quicktime";
		break;
	case "jpg":
	case "gif":
	case "png":
	case "bmp":
	case "tif":
		playerType = "image";
		break;
	default:
		playerType = "wmp";
		// playerType="flash";
	}

	enablePlayer(playerType);// this will create player put it in the highest
	// z-order when necessary

	switch (playerType) {
	case "flash":
		playFlashMovie(url);
		break;
	case "wmp":
		playWmp(url, true);
		break;
	case "swf":
		embedSWF(url);
		break;
	case "quicktime":
		playQuicktime(url);
		break;
	case "image":
		playImage(url);
		break;
	default:
		playFlashMovie(url);
	}

	// update play statistics
	if (currentURL != url) {// avoid unneccessary counts
		invoke("notification", "notificationType=play&url="
				+ encodeURIComponent(url));
	}
	currentURL = url;
	// halt autoplay
	setCookie('autoPlayFeatured', 'false', null, null, null, null);
}
function playImage(url) {
	clearInnerHTML(_elem("flashDiv")); /*
										 * var
										 * img=document.createElement("img");
										 * img.style.height=getPlayerHeight();
										 * img.src=url;
										 * _elem("flashDiv").appendChild(img);
										 */

	// load in the new image
	this.loading = true;
	var newImage = null;
	newImage = new Image();
	newImage.src = url;
	newImage.style.height = getPlayerHeight();

	_elem("flashDiv").appendChild(newImage);
	// image is in cache (IE6 & IE7 ... Firefox can handle the onload well even
	// file was in cache);
	if (newImage.complete) {
		this.element.src = newImage.src;
		this.loaded = true;

		// image not in cache
	} else {
		newImage.onload = function() {
			this.element.src = newImage.src;
			this.loaded = true;
		}.bind(this);
	}

}
function playQuicktime(url) {
	clearInnerHTML(_elem("flashDiv"));

	var htmlStr = QT_GetOBJECT(url, getPlayerWidth(), getPlayerHeight(),
			"activeXVersion");
	_elem("flashDiv").innerHTML = htmlStr;
}
function playWmp(url, video) {
	try {

		if (thisMovie("wmpocx").playState == 3 && bVideo != null
				&& bVideo != video) {
			return;
		}

		bVideo = video;

		if (thisMovie("wmpocx").playState == 3) {
			StopPlayer();
		} else {

			thisMovie("wmpocx").URL = url;
			wmpTimer = window.setInterval(updateMPPlayProgress, 1000);
		}
	} catch (e) {
		// incase control was not created
		if (isFirstMovie) {
			setTimeout("playVideo('" + url + "')", 1500);
		}

	}
}
function displayAdsInPlayer() {
	if (currentURL != null)
		return;
	_elem("featuredControlDiv").style.zIndex = 29;
	_elem("adsDiv").style.zIndex = 30;
	_elem("adsDiv").style.display = "block";
}
function updateMPPlayProgress() {
	try {
		playProgress(thisMovie("wmpocx").controls.currentPosition,
				thisMovie("wmpocx").controls.currentPosition
						/ thisMovie("wmpocx").currentMedia.duration * 100);
		//
		/*
		 * if(Math.floor(thisMovie("wmpocx").currentMedia.duration- TimeNow)<=0){//play
		 * completed clearInterval(wmpTimer); }
		 */
	} catch (e) {

	}
}

function fwdPlayer() {
	try {
		switch (playerType) {
		case "flash":
			thisMovie("flashplayer").fwdFlashMovie();
			break;
		case "wmp":
			thisMovie("wmpocx").controls.fastForward();
			break;
		}
	} catch (e) {
	}
	reportUserAction("play_forwarded::", null);
}

function revPlayer() {
	try {
		switch (playerType) {
		case "flash":
			thisMovie("flashplayer").revFlashMovie();
			break;
		case "wmp":
			thisMovie("wmpocx").controls.fastReverse();
			break;
		}
	} catch (e) {
	}
	reportUserAction("play_reversed::", null);

}
function OnDSScriptCommandEvt(bstrType, bstrParam) {
	if (bstrType.toLowerCase() == "caption") {
		var sCommand;

		sCommand = "document.contentNav.document.writeln(\"<SPAN ID=content>"
		sCommand = sCommand + bstrParam;
		sCommand = sCommand + "\");document.contentNav.document.close(); ";
		timerID = setTimeout(sCommand, 0);
	}
}
function loadingProgress(percentage) {
	window.setTimeout("indicateBufferingProgess(" + (percentage) + ")", 10);
}

function indicateBufferingProgess(percentage) {
	_elem("progressIndicator").innerHTML = "<div id=prog style='z-index:1000;width:106px;'><div style=\"float:left;background-color:#666666;height:10px;width:"
			+ percentage * 106 / 100 + "px;\"></div></div>";

}

function formatNumber(num) {
	if (num < 1)
		return "00";
	else if (num < 10) {
		return "0" + num;
	}
	return num;
}
function ClipPlayState(numState) {
	PlayStateChange(numState);
}

function playProgress(playheadTime, percentage) {

	// indicatePlayProgess(playheadTime,percentage);
	window.setTimeout("indicatePlayProgess(" + (playheadTime) + ","
			+ percentage + ")", 10);

	var playDuration = formatNumber(Math.floor(playheadTime / (60 * 60))) + ":"
			+ formatNumber(Math.floor(playheadTime / 60)) + ":"
			+ formatNumber(Math.floor(playheadTime % 60));
	setCookie("playheadTimeValue", playDuration, null, null, null, null);

}

function indicatePlayProgess(playheadTime, percentage) {

	var playheadTimeValue = formatNumber(Math.floor(playheadTime / 60)) + ":"
			+ formatNumber(Math.floor(playheadTime % 60));
	// setCookie("playheadTimeValue",playheadTimeValue,null,null,null,null);
	_elem("timeIndicator").innerHTML = "<table   height=10px  cellSpacing=0 cellPadding=0 border=0 ><tr><td  STYLE='text-align:center;font-size: 9px;font-weight: bold;'>"
			+ playheadTimeValue + "</td></tr></table>";
	var htmlStr;// ="<div id=progValue STYLE='text-align:center;font-size:
	// 9px;font-weight:
	// bold;position:absolute;left:35%;z-index:100'>"+Math.ceil(percentage)+"%</div>";
	htmlStr = "<div id=progI align=left STYLE='position:relative;z-index:5000'><img  id='prgImg' src='video_images/progress.png' align=absbottom height=12px width="
			+ percentage + "% /></div>";

	_elem("progressIndicator").innerHTML = htmlStr;

}
function volumeLevel(percentage) {
	try {
		var maxWidth = 40;
		var maxHeight = 20;
		var htmlStr = "<table align=center STYLE=' background-position:bottom center' width="
				+ maxWidth
				+ " height="
				+ maxHeight
				+ "  cellSpacing=0 cellPadding=0 border=0 ><tr>";
		for (i = 1; i <= percentage / 10; i++) {
			htmlStr += "<td valign='bottom'> <a href=# OnClick='volumeLevel("
					+ i
					* 10
					+ ");return false;'><img  id='volume"
					+ i
					+ "' src='video_images/volumeActive.png' align=absbottom width="
					+ maxWidth / 10 + " height="
					+ ((2 / 3) * maxHeight / 10 * i + (1 / 3 * maxHeight))
					+ " /></a></td>";
		}

		for (i = percentage / 10 + 1; i <= 10; i++) {
			htmlStr += "<td valign='bottom'> <a href=# OnClick='volumeLevel("
					+ i
					* 10
					+ ");return false;'><img  id='volume"
					+ i
					+ "' src='video_images/volumeInactive.png'  align=absbottom width="
					+ maxWidth / 10 + " height="
					+ ((2 / 3) * maxHeight / 10 * i + (1 / 3 * maxHeight))
					+ " /></a></td>";
		}
		htmlStr += "</tr><table>";
		_elem("volumnDiv").innerHTML = htmlStr;

		// perform actual volume control operation

		switch (playerType) {
		case "flash":
			thisMovie("flashplayer").volumeFlashMovie(percentage);
			break;
		case "wmp":
			var ocx = thisMovie("wmpocx");
			if (ocx != null) {
				ocx.settings.volume = percentage;
			}
			break;

		}

	} catch (e) {
	}

}
function playComplete(playheadTime) {
	PlayStateChange(8);
}

function PositionChange(oldPosition, newPosition) {
	// playProgress(playheadTime,percentage);
}
function isIE() {
	return (navigator.appName.indexOf("Microsoft") != -1);
}
function thisMovie(movieName) {
	return (isIE()) ? window[movieName] : document[movieName];

}

var isFirstMovie = true;
// defined within flash
function playFlashMovie(url) {
	try {

		thisMovie("flashplayer").playFlashMovie(url);
		isFirstMovie = false;
	} catch (e) {
		// probably flash player has not finish initialization
		if (isFirstMovie) {
			isFirstMovie = false;
		} else {
			clearInnerHTML($("flashDiv"));
			createPlayer("flash");
		}
		setTimeout("playVideo('" + url + "')", 1500);

	}
	;

}
function hideAllPlayers() {
	clearInnerHTML($("flashDiv"));
	clearInnerHTML($("wmpDiv"));
}
function stopFlashMovie() {
	thisMovie("flashplayer").stopFlashMovie();
	_elem("flashDiv").style.zIndex = -20;
}
function fullScreenFlashMovie() {
	thisMovie("flashplayer").goFullScreen();
}

/*
 * //defined within flash function pauseFlashMovie(){ }
 */

/*
 * //defined within flash function setVolumeFlashMovie(%){ }
 */
/*******************************************************************************
 * Slide show functions
 */
var isFirstSlide = true;

function initSlideShow() {
	enablePlayer("flash");
	isFirstSlide = true;
}
function initSlideShow(id, url, title, desc) {
	enablePlayer("flash");
	var htmlStr = "<table class='video_nav_table_style'   align='left' ><tr><td class='video_thumbnail'>";
	htmlStr += "<a href=# OnClick=\"setCookie('autoPlayFeatured','false',null,null,null,null);showSlides('"
			+ id
			+ "');return false;\"><img  id=SlideImg src='"
			+ url
			+ "' width=55 height=45 /></a>";
	htmlStr += "</td><td ><table ><tr><td>";
	htmlStr += "<a  class='video_title_style' href=# OnClick=\"setCookie('autoPlayFeatured','false',null,null,null,null);showSlides('"
			+ id + "');return false;\">" + title + " </a>";
	htmlStr += "</td></tr><tr><td class='video_output_txt'>";
	htmlStr += "&nbsp;";
	+(desc == null || desc == 'null' ? '' : desc);
	htmlStr += "</td><tr></table></td><tr></table>";
	_elem("slideDiv").innerHTML += htmlStr;

	isFirstSlide = false;

}

function addToSlideShow(id, url, desc, index, canSave, canPrint) {
	try {
		thisMovie("flashplayer").addToSlideShow(id, url, desc, index, canSave,
				canPrint);
	} catch (e) {
	}
	try {
		if (isFirstSlide) {
			var htmlStr = "<table class='video_nav_table_style'   align='left' ><tr><td class='video_thumbnail'>";
			htmlStr += "<a href=# OnClick=\"showSlides('" + id
					+ "');return false;\"><img  id=SlideImg src='" + url
					+ "' width=55 height=45 /></a>";
			htmlStr += "</td><td class='video_output_txt'>";
			htmlStr += "&nbsp;";
			+(desc == null || desc == 'null' ? '' : desc);
			htmlStr += "</td><tr></table>";
			_elem("slideDiv").innerHTML += htmlStr;

			isFirstSlide = false;
		}
	} catch (e) {
	}
}

function showSlides(id) {
	autoPlayFeatured = false;
	StopPlayer();
	enablePlayer("flash");
	thisMovie("flashplayer").playSlideShow(id);
}

/*******************************************************************************
 * End of Slide show functions
 */
var previousPlayer = null;
function createPlayer(playerType) {
	// flash player
	if (playerType == "flash") {
		var flashPlayerDiv = _elem("flashDiv");
		// flashPlayerDiv.style.zIndex=10;

		if (previousPlayer == "image" || flashPlayerDiv == null
				|| flashPlayerDiv == undefined
				|| flashPlayerDiv.innerHTML == null
				|| flashPlayerDiv.innerHTML == ""/*
													 * ||
													 * flashPlayerDiv.firstChild==null ||
													 * flashPlayerDiv.firstChild==undefined
													 */) {
			var so = new SWFObject("flashPlayer.swf", "flashplayer",
					getPlayerWidth(), getPlayerHeight(), "8", "#000000", true);
			so.addParam("wmode", "window");
			so.addParam("allowFullScreen", "true");
			so.setAttribute('xiRedirectUrl', 'http://www.multimediaQuest.com');
			so.write("flashDiv");
		}
		// _elem("flashplayer").style.zIndex=10;
	}
	// quicktime
	if (playerType == "quicktime") {

	}
	// wmp
	if (playerType == "wmp") {
		if (_elem("wmpocx") == null || _elem("wmpocx") == undefined) {
			try {
				var oElement = document.createElement("object");
				oElement.id = "wmpocx";
				if (-1 != navigator.userAgent.indexOf("MSIE")) {
					oElement.classid = "CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6";
				} else if (-1 != navigator.userAgent.indexOf("Firefox")) {
					oElement.type = "application/x-ms-wmp";
				}
				oElement.width = getPlayerWidth();
				oElement.height = getPlayerHeight();
				_elem("wmpDiv").appendChild(oElement);
				_elem("wmpocx").uiMode = "none";

				// ----------- events
				var htmlStr = '&lt;script for="wmpocx" event="PositionChange(oldPosition, newPosition)" language="JScript"&gt;PositionChange(oldPosition, newPosition);&lt;/script&gt;'
						+ '&lt;script for="wmpocx" event="PlayStateChange(NewState)" language="JScript"&gt;PlayStateChange(NewState);&lt;/script&gt;'
						+ '&lt;script for="wmpocx" event="Error()" language="JScript"&gt;StopPlayer();&lt;/script&gt;'
						+ '&lt;SCRIPT FOR="wmpocx" EVENT="ScriptCommand(bstrType, bstrParam)" LANGUAGE="Jscript"&gt;'
						+ ' if (bstrType.toLowerCase() == "caption") {  document.all.contentIE.innerHTML = bstrParam; } '
						+ '&lt;/SCRIPT&gt;';

				_elem("wmpDiv").innerHtml = _elem("wmpDiv").innerHtml + htmlStr;

				registerWMPEventObservers();
			} catch (e) {
			}
		}
	}

}

function resizePlayer() {
	try {
		var width = getPlayerWidth(), height = getPlayerHeight();
		var player = _elem("flashplayer");
		if (player != null || player != undefined) {
			player.style.width = width;
			player.style.height = height;
		}
		player = _elem("flashDiv");
		if (player != null || player != undefined) {
			player.style.width = width;
			player.style.height = height;
		}
		player = _elem("wmpocx");
		if (player != null || player != undefined) {
			player.style.width = width;
			player.style.height = height;
		}

	} catch (e) {

	}
}
function init() {
	try {
		initializePlayerVar();
		initNavigation(param);
		if (getCookie('ContentSource') == null)
			setCookie('ContentSource', 'A', null, null, null, null);// default

		renderVideoResizeCtl();
		renderFeaturedCtl();
		volumeLevel(50);// set initial volume level
		setTimeout(autoPlay, 100000);
		hideVideoControlIfPossible();
		setCookie('navInitialised', 'false', null, null, null, null);
	} catch (e) {
	}
}
function minPlayer() {
	setCookie('VideoMode', 'M', null, null, null, null);
	renderVideoResizeCtl();
	reportUserAction('play_resize_min::', null);
}
function maxPlayer() {
	setCookie('VideoMode', 'N', null, null, null, null);
	renderVideoResizeCtl();
	reportUserAction('play_resize_max::', null);
}
function renderVideoResizeCtl() {
	try {
		resize(controlParam);
		var div = _elem("resizeCtlDiv");
		var videoMode = getCookie("VideoMode");
		var htmlStr = null;
		if (videoMode == 'M') {
			htmlStr = "<a href=#   title='"
					+ getLocaleStr('player_min', 'Min Player')
					+ "'  onClick=\"maxPlayer(); return false;\" ><img src='video_images/min.png' alt='Min Video'></a>";
		} else {
			htmlStr = "<a href=# title='"
					+ getLocaleStr('player_max', 'Max Player')
					+ "'  onClick=\"minPlayer();return false;\" ><img src='video_images/max.png' alt=''></a>";

		}
		div.innerHTML = htmlStr;
		// fullscreen control
		_elem("fullScrCtlDiv").innerHTML = "<a href=#   title='"
				+ getLocaleStr('player_full_screen', 'Full Screen')
				+ "' onClick=\" fullScreen();reportUserAction('play_resize_fullscreen::',null);return false;\" ><img src='video_images/full.png' alt=''></a>";

		// show video section
		_elem("wholeVideoSection").style.visibility = "visible";

	} catch (e) {
	}
}

function renderFeaturedCtl() {
	if (getCookie("mode") == "featured") {

		_elem("featuredControlDiv").style.display = 'block';

		clearInnerHTML(_elem("featuredControlDiv"));

		var width = _elem("videoSection").offsetWidth;

		var so = new SWFObject("featuredVideo.swf", "featuredVideoplayer",
				width, "125", "8", "#336699", true);
		so.setAttribute('xiRedirectUrl', 'http://www.multimediaQuest.com'); // must
		// be
		// the
		// absolute
		// URL
		// to
		// your
		// site
		so.addParam("wmode", "transparent");
		so.addParam("allowScriptAccess", "sameDomain");
		so.addParam("enableJSURL", "true");
		so.addParam("enableHREF", "true");
		so.addParam("saveEmbedTags", "true");
		so.write("featuredControlDiv");

		// _elem("featuredControlDiv").style.zIndex=-1;

	} else {

		_elem("featuredControlDiv").style.display = 'none';
	}
}
function embedSWF(url) {
	clearInnerHTML(_elem("flashDiv"));
	if (url.indexOf(".dcr") == -1) {
		var so = new SWFObject(url, "flashplayer", getPlayerWidth(),
				getPlayerHeight(), "8", "#000000", true);
		so.addParam("wmode", "window");
		so.addParam("allowFullScreen", "true");
		so.setAttribute('xiRedirectUrl', 'http://www.multimediaquest.com');
		so.write("flashDiv");
	} else {

		var htmlStr = '<object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0" width="'
				+ getPlayerWidth() + '" height="' + getPlayerHeight() + '">';
		htmlStr += '<param name="swRemote" value="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\'">';
		htmlStr += '<param name="swStretchStyle" value="meet">';
		htmlStr += '<param name="bgColor" value="#000000">';
		htmlStr += '<param name="src" value="' + url + '">';
		htmlStr += '<embed src="'
				+ url
				+ '" width="'
				+ getPlayerWidth()
				+ '" height="'
				+ getPlayerHeight()
				+ '" bgColor="#000000" swRemote="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\'" swStretchStyle="meet" type="application/x-director" pluginspage="http://www.macromedia.com/shockwave/download/"></embed>';
		htmlStr += '</object>';
		_elem("flashDiv").innerHTML = htmlStr;
	}
}

function enablePlayer(playerType) {
	try {
		createPlayer(playerType);

		switch (playerType) {
		case "image":
		case "quicktime":// Note: Quictime uses flash player div
		case "flash":

			// first disable all players
			_elem("wmpDiv").style.zIndex = -10;
			_elem("flashDiv").style.zIndex = 20;

			_elem("wmpDiv").style.display = 'none';
			_elem("flashDiv").style.display = 'block';
			break;

		case "wmp":

			// first disable all players
			_elem("wmpDiv").style.zIndex = 20;
			_elem("flashDiv").style.zIndex = -10;
			_elem("flashDiv").style.display = 'none';
			_elem("wmpDiv").style.display = 'block';
			break;

		case "swf":
			// first disable all players
			_elem("wmpDiv").style.zIndex = 1;
			_elem("flashDiv").style.zIndex = 2;

			_elem("wmpDiv").style.display = 'none';
			_elem("flashDiv").style.display = 'block';
			break;

		default:
			_elem("wmpDiv").style.zIndex = 1;
			_elem("flashDiv").style.zIndex = 2;
			_elem("wmpDiv").style.display = 'none';
			_elem("flashDiv").style.display = 'block';
		}
		previousPlayer = playerType;
		_elem("featuredControlDiv").style.zIndex = -30;

	} catch (e) {
	}
}

function autoPlay() {
	if (getCookie("autoPlayFeatured") != "false") {
		playNextFeaturedMovie();
	}
}

function registerWMPEventObservers() {
	if (navigator.appName == "Netscape") {
		try {
			// This helper function is required to register event
			// observers with the Java proxy. Registration MUST be
			// done before desired events will be sent.
			var plugin = document.wmpocx;

			// Here are event observers to be activated in the plug-in.
			appObs.setByProxyDSScriptCommandObserver(plugin, true);
			appObs.setByProxyDSPlayStateChangeObserver(plugin, true);
			appObs.setByProxyDSReadyStateChangeObserver(plugin, true);

			// You can activate other event observers similarly.
		} catch (e) {
		}
	}
}

function OnDSPlayStateChangeEvt(OldPlayState, NewPlayState) {
	ClipPlayState(NewPlayState);
}

function OnDSReadyStateChangeEvt(ReadyState) {

}

// ----------------------Auto Play ------------------------------------------
// -- auto play featured

function playNextFeaturedMovie() {
	try {
		thisMovie("featuredVideoplayer").playNextFeaturedMovie();
	} catch (e) {
	}
}
function getPlayerWidth() {
	if (!isIE()) {
		var videoDiv = _elem(controlParam.videoDiv);
		if (videoDiv != null)
			return videoDiv.style.width;
	}
	return "100%";
}
function getPlayerHeight() {
	if (!isIE()) {
		var videoDiv = _elem(controlParam.videoDiv);
		return videoDiv.style.height;
	}
	return "100%";
}
function maxPlayerNav() {
	setCookie("VideoMode", "M");
	resize(controlParam);
}
function minPlayerNav() {
	setCookie("VideoMode", "N");
	resize(controlParam);
}
function resize(controlParam) {

	try {
		var videoDiv = _elem(controlParam.videoDiv);
		var videoCtlDiv = _elem(controlParam.videoCtlDiv);// the play,stop ...
		// ctl div
		var ctlDiv = _elem(controlParam.navCtlDiv);
		var featuredDiv = _elem(controlParam.featuredDiv);

		var navCtlWidth = controlParam.navCtlWidth;
		var videoWidth = controlParam.videoWidth;
		var videoHeight = controlParam.videoHeight;

		// -------------------------------------------------------------------------------
		// this is hard wired to detect whether a video player is in use
		var noVideoPlayerExist = _elem("videoSection") == null ? true : false;
		// -----------------------------------------------------------------------------

		var videoMode = getCookie("VideoMode");// either N -normal,M -
		// maximized ,F - fullscreen
		if (videoMode == 'M') {
			reportUserAction('play_nav_resize_max::', null);
			videoDiv.style.height = (125 + videoHeight) + 'px';
			clearInnerHTML(featuredDiv);
			setCookie("VideoNavCtlMode", "enlarged", null, null, null, null);
		} else if (videoMode == null || videoMode == 'N') {
			reportUserAction('play_nav_resize_min::', null);
			videoDiv.style.height = videoHeight + 'px';

		}

		var navCtlMode = getCookie("VideoNavCtlMode");

		if (navCtlMode != null && navCtlMode == "enlarged") {
			// enlarge video section
			if (noVideoPlayerExist) {
				_elem('outerNavCtlDiv').style.width = '660px';
			} else {
				// _elem('outerNavCtlDiv').style.width=(videoWidth+navCtlWidth)+'px';
				_elem('outerNavCtlDiv').style.width = '710px';

			}

			_elem('outerNavCtlDiv').style.height = '555px';
			_elem('outerNavCtlDiv').style.overflowY = 'auto';
			_elem('outerNavCtlDiv').style.overflowX = 'hidden';

			// enlarge control
			if (noVideoPlayerExist) {
				ctlDiv.style.position = "relative";
				ctlDiv.style.width = '100%';
				ctlDiv.style.left = '0px';
			} else {
				videoDiv.style.width = (videoWidth + navCtlWidth) + 'px';
				ctlDiv.style.position = "absolute";
				// ctlDiv.style.width = videoDiv.offsetWidth + 'px';
				ctlDiv.style.width = '712px';
				// ctlDiv.style.left = ((_elem('PRIMARY').offsetWidth -
				// videoDiv.offsetWidth) / 2) + 'px';
				ctlDiv.style.left = ((_elem('BODYCONTENT').offsetWidth - 712)) + 'px';
				ctlDiv.style.top = (_elem("player-container").offsetHeight + _elem("player-container").offsetTop) + 2 + 'px';
			}
			ctlDiv.style.overflow = "hidden";

			ctlDiv.style.zIndex = 1000;

			if (noVideoPlayerExist) {
				ctlDiv.style.top = '0px';

			}

			ctlDiv.style.height = '660px';

			// ctlDiv.className="content-sel-thumb";

			ctlDiv.style.borderColor = '#363636';
			ctlDiv.style.borderWidth = '1px';
			ctlDiv.style.borderBottomWidth = '3px';
			ctlDiv.style.borderStyle = 'solid';
			ctlDiv.style.backgroundRepeat = 'no-repeat';
			ctlDiv.style.backgroundImage = 'url(images/dot.gif)';
			ctlDiv.style.backgroundColor = "#000";
			ctlDiv.style.styleFloat = "left";
			ctlDiv.style.opacity = 0.98;

			if (noVideoPlayerExist) {
				_elem('tableDiv').style.width = (ctlDiv.offsetWidth - 20) + 'px';
			} else {
				// _elem('tableDiv').style.width=(videoDiv.offsetWidth-20)+'px';
				_elem('tableDiv').style.width = '712px';

			}

			_elem('navCtlHeader').style.display = 'block';
			_elem('navCtlTitle').style.display = 'block';
			_elem('navCtlEnlargeDiv').style.display = 'none';
			// setCookie("VideoNavCtlMode","minimized",null,null,null,null);
		} else {
			// restore

			param.renderStyle = 5;// the only rendering mode currently
			// accepted in minimized state
			try {
				_elem('mainBodyDivCol').style.visibility = 'visible';
				_elem('featuredCollectionDiv').style.visibility = 'visible';
			} catch (e) {

			}

			_elem('outerNavCtlDiv').style.height = '236px';
			_elem('outerNavCtlDiv').style.overflowY = 'auto';
			_elem('outerNavCtlDiv').style.overflowX = 'hidden';

			if (!noVideoPlayerExist) {
				videoDiv.style.width = (videoWidth) + 'px';

			} else {
				_elem('outerNavCtlDiv').style.width = '100%';
			}

			ctlDiv.style.height = videoHeight + 10 + 'px';
			ctlDiv.style.position = "relative";
			ctlDiv.style.left = 0 + 'px';
			ctlDiv.style.top = 0 + 'px';
			ctlDiv.style.width = navCtlWidth + 'px';
			ctlDiv.style.backgroundRepeat = 'no-repeat';
			ctlDiv.style.borderWidth = '0px';
			ctlDiv.style.borderLeftWidth = '1px';
			ctlDiv.style.borderLeftStyle = 'dotted';
			ctlDiv.style.borderColor = '#363636';
			ctlDiv.style.opacity = 1;
			ctlDiv.style.backgroundColor = "#000";
			ctlDiv.style.styleFloat = "right";

			// if its collection page
			if (location.href.indexOf("collectionPage.html") > 0) {
				ctlDiv.style.backgroundImage = 'url(images/dot.gif)';
			}

			// ctlDiv.className="navCtlMin";

			_elem('navCtlHeader').style.display = 'none';
			_elem('navCtlEnlargeDiv').style.display = 'block';
			_elem('navCtlEnlargeDiv').innerHTML = "<a href='#'   title='"
					+ getLocaleStr('play_nav_resize_max', 'Enlarge')
					+ "' onClick=\"setCookie('VideoNavCtlMode','enlarged',null,null,null,null);resize(controlParam);return false;\"><img src='video_images/navMax.png' alt='"
					+ getLocaleStr('player_nav_enlarge', 'Enlarge')
					+ "'>&nbsp;";

			if (noVideoPlayerExist) {
				_elem('tableDiv').style.width = '100%';
			} else {
				_elem('tableDiv').style.width = videoDiv.offsetWidth + 'px';
			}

			_elem('navCtlTitle').style.display = 'none';
			// setCookie("VideoNavCtlMode","enlarged",null,null,null,null);

			// replay the currently playing movie
			if (currentURL != null) {
				playVideo(currentURL);
			}

		}
		resizePlayer();
		renderFeaturedCtl();
		renderAssociatedDivs();

		// render content
		var collection = findCollection(currentCollectionId);
		if (collection != null) {
			renderCollectionMedia(collection, param);
		}

	} catch (e) {
	}
	;
}

function showVideoControl(bShow) {
	var vCtl = _elem("controlDiv");
	if (bShow) {
		vCtl.style.display = "block";
		vCtl.style.zIndex = /* _elem('outerNavCtlDiv').style.zIndex+ */1010;

	} else {
		vCtl.style.display = "none";
	}
}
var bMouseStillOverVideo = false;
function mouseOutVideoSection() {
	bMouseStillOverVideo = false;

}
function mouseOverVideoSection() {

	showVideoControl(true);
	// hide control after a while if not in use
	setTimeout(hideVideoControlIfPossible, 3000);

	bMouseStillOverVideo = true;
}

function hideVideoControlIfPossible() {
	if (!bMouseStillOverVideo) {
		showVideoControl(false);
	} else {
		// try hidding control again
		setTimeout(hideVideoControlIfPossible, 3000);
	}
}

function getMore(url, action, parameter, param) {
	location.href = url;
	setTimeout("loadNavigation(action,parameter,param)", 4000);
}
var paramList = [];
function addToParamList(param) {
	for (i = 0; i < paramList.length; i++) {
		if (paramList[i].callID == param.callID) {
			paramList[i] = param;
			return;
		}
	}
	paramList.push(param);
}
function getParamFromList(callID) {
	for (i = 0; i < paramList.length; i++) {
		if (paramList[i].callID == callID) {
			return paramList[i];
		}
	}
	return null;
}
function removeParamFromList(callID) {
	for (i = 0; i < paramList.length; i++) {
		if (paramList[i].callID == callID) {
			paramList.splice(i, 1);
		}
	}

}
function initNavigation(param) {
	if (getCookie('navInitialised') == null
			|| getCookie('navInitialised') == 'false') {
		var action = getCookie('action');
		action = ((action == null || action == 'null') ? 'notification'
				: action);
		var parameter = getCookie('parameter');
		parameter = ((parameter == null || parameter == 'null') ? 'notificationType=findRelated&sort=date&filterOpt=' + getCookie('MediaTypeFilter')
				: parameter);
		if (currentURL == null) {// there is a need to populatethe navigation
			// section
			loadNavigation(action, parameter, param);
		}
		setCookie('action', null, null, null, null, null);

		if (getCookie('VideoCtlPageType') != 'collectionPage') {
			setCookie('parameter', null, null, null, null, null);
		}

	}
	setCookie('navInitialised', 'true', null, null, null, null);
};

function Collection(id) {
	this.id = id;
	this.images = [];
}
function CollectionImage(url, thumbnail, comp_id, date, tags, title, desc,
		view_count, video_id, name, logo_link, web_link, access_restrict,
		priced) {
	this.url = url;
	this.desc = desc;
	this.title = title;
	this.thumbnail = thumbnail;
	this.comp_id = comp_id;
	this.date = date;
	this.tags = tags;
	this.view_count = view_count;
	this.video_id = video_id;
	this.name = name;
	this.logo_link = logo_link;
	this.web_link = web_link;
	this.access_restrict = access_restrict;
	this.priced = (priced == "Y" ? true : false);
}

function getHostname() {
	var host = location.href.substr(0, location.href.indexOf("/", 8));
	return host;
}
var req = null;
function initRequest(url) {
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {

		var ver = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0",
				"MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp" ];
		for ( var i = 0; i < ver.length; i++) {
			try {
				req = new window.ActiveXObject(ver[i]);
				break;
			} catch (e) {
			}
		}

	}
	req.open("GET", url, true);
}
function loadNavigation(action, urlParameter, parameter) {
	// param=parameter;
	addToParamList(parameter);
	invoke(action, urlParameter + "&callID=" + parameter.callID);
}

function postLoadNavigation(action, urlParameter, parameter) {
	param = parameter;
	addToParamList(parameter);

	setCookie('action', action, null, null, null, null);
	setCookie('parameter', urlParameter, null, null, null, null);
}
function invoke(action, parameter) {
	var host = getHostname();
	var path = 'action=' + action + '&' + parameter;
	var url = 'service?' + path;
	dojo.xhrGet( {
		url :url,
		handleAs :"xml",
		load : function(data, evt) {
			processAjaxRequest(data);
		},
		error : function(data, evt) {
			reportAjaxCallError(data);
		}
	});

}
function reportAjaxCallError(data) {
	showAjaxCallProggress(false);
}

function processAjaxRequest(data) {

	try {

		collection = null;

		// for collections
		var collections = data.getElementsByTagName("collection");
		for ( var col = 0; col < collections.length; col++) {
			var imageCol = collections[col];
			var colId = imageCol.getAttribute("id");
			collection = new Collection(colId);

			for ( var childIndex = 0; childIndex < collections[col].childNodes.length; childIndex++) {

				var nodeVal = collections[col].childNodes[childIndex];
				for ( var childIndex2 = 0; childIndex2 < nodeVal.childNodes.length; childIndex2++) {
					var nodeVal2 = nodeVal.childNodes[childIndex2];
					var title = nodeVal2.getElementsByTagName("title")[0].firstChild.nodeValue;
					var url = nodeVal2.getElementsByTagName("url")[0].firstChild.nodeValue;
					var desc = nodeVal2.getElementsByTagName("desc")[0].firstChild.nodeValue;

					var date = nodeVal2.getElementsByTagName("date")[0].firstChild.nodeValue;
					var thumbnail = nodeVal2.getElementsByTagName("thumbnail")[0].firstChild.nodeValue;
					var comp_id = nodeVal2.getElementsByTagName("comp_id")[0].firstChild.nodeValue;

					var video_id = nodeVal2.getElementsByTagName("video_id")[0].firstChild.nodeValue;

					var tags = nodeVal2.getElementsByTagName("tags")[0].firstChild.nodeValue;
					var view_count = nodeVal2
							.getElementsByTagName("view_count")[0].firstChild.nodeValue;
					var name = nodeVal2.getElementsByTagName("name")[0].firstChild.nodeValue;
					var logo_link = nodeVal2.getElementsByTagName("logo_link")[0].firstChild.nodeValue;
					var web_link = nodeVal2.getElementsByTagName("web_link")[0].firstChild.nodeValue;
					var access_restrict = nodeVal2
							.getElementsByTagName("access_restrict")[0].firstChild.nodeValue;
					var priced = nodeVal2.getElementsByTagName("priced")[0].firstChild.nodeValue;

					collection.images.push(new CollectionImage(url, thumbnail,
							comp_id, date, tags, title, desc, view_count,
							video_id, name, logo_link, web_link,
							access_restrict, priced));

				}

			}

		}

		storeCollection(collection);
		var paramInfo = getParamFromList(colId);

		paramInfo.imageIndex = 0; // reset current page number
		renderCollectionMedia(collection, paramInfo);

		if (playAfterAjaxCall) {
			prePlaySelectedVideo(colId, 0);
			playAfterAjaxCall = false;
		}

	} catch (e) {
		// alert(e);
	}
}

var collectionStore = [];
var poolingForStorage = false;
function storeCollection(collection) {
	if (collection == null)
		return;
	// alert("within storeCollection:"+collection);
	try {
		if (dojoIsLoaded /* && !isIE() */) {// dojo has already been loaded

			dojox.storage.put(collection.id, collection, function(status, key,
					message) {
				if (status == dojox.storage.FAILED) {
					console
							.debug("Unable to save collection data : "
									+ message);
				}
			});
			if (findCollection(collection.id) != null) {
				collection = null;// release memory
				poolingForStorage = false;
				collectionStore = null;// if succeeded free memory of
				// previously stored collections
				return;
			}

		}
	} catch (e) {
	}
	try {
		// shouldn't have reached this point if storage was successful
		// dojo storage not yet ready
		poolingForStorage = true;
		// alert("calling collectionMemStore- collection:"+collection);
		collectionMemStore(collection);

	} catch (e) {
	}
}
function collectionMemStore(collection) {
	// use memory intensive storage
	// alert("Within collectionMemStore collectionStore:"+collectionStore);
	if (collectionStore)
		for ( var c = 0; c < collectionStore.length; c++) {
			if (collectionStore[c].id == collection.id) {
				collectionStore[c] = null;
				collectionStore[c] = new Array();
				/*
				 * for (i = 0; i < collection.images.length; i++) {
				 * collectionStore[c].images[i] = collection.images[i]; } //
				 * alert("about to return //
				 * collectionMemStore:"+collectionStore[c]); return;
				 */
			}
		}
	// alert("About pushing collectionStore:"+collectionStore);
	collectionStore.push(collection);
	// alert("final return collectionMemStore collection:"+collection);

}
function findCollection(id) {
	try {
		// --------------- work around for dojo delayed storage -----------
		if (/* poolingForStorage */collectionStore != null
				&& collectionStore.length > 0) {
			for ( var c = 0; c < collectionStore.length; c++) {
				if (collectionStore[c].id == id) {
					return collectionStore[c];
				}
			}
		}
		// ---------------- work around for dojo delayed storage
	} catch (e) {
	}
	try {
		var data = null;
		try {
			data = dojox.storage.get(id);
		} catch (e) {
		}
		return data;
	} catch (e) {
	}
	return null;
}

var paramStore = [];
function storeParam(param) {
	for ( var c = 0; c < paramStore.length; c++) {
		if (paramStore[c].collectionId == param.collectionId) {
			paramStore[c] = param;
			return;
		}
	}
	paramStore[paramStore.length] = param;
}
function findParam(collectionId) {
	for ( var c = 0; c < paramStore.length; c++) {
		if (paramStore[c].collectionId == collectionId) {
			return paramStore[c];
		}
	}
	return null;
}

// rendering

var currentIndex = -1;// the index of the current selected collection
var currentSortOrder = 'random';
var currentViewStyle = 'list';
var currentCollectionId = null;
var currentPage = 0;
var currentTimeFactor = 'all_time';

function ago(date) {
	// avoid display ago for different date format eg 1/03/2007
	date.replace(" ", "");
	var lastChar = date.substr(date.length - 1);
	if (isNaN(parseInt(lastChar, 10))) {
		return getLocaleStr('ago', 'ago');
	} else {
		return "";
	}
}

function randomizeCollectionMedia(collection) {
	try {
		if (collection == null || collection.images == null) {
			return;
		}
		for ( var i = 0; i < collection.images.length / 2; i++) {
			var p1 = Math.floor(Math.random() * collection.images.length);
			var p2 = Math.floor(Math.random() * collection.images.length);

			var tempStore = collection.images[p1];
			collection.images[p1] = collection.images[p2];

			collection.images[p2] = tempStore;

		}
	} catch (e) {
		console.debug(e.message);
	}

}

function beginTranslation(startIndex) {
	for ( var i = startIndex; i < 100 + startIndex; i++) {
		var tDiv = _elem("videoTitle" + i);
		if (tDiv) {
			translateText("videoTitle" + i, _elem("videoTitle" + i).innerHTML);
			if (_elem("videoDesc" + i)) {
				translateText("videoDesc" + i, _elem("videoDesc" + i).innerHTML);
			}
		} else
			break;
	}
}
function renderCollectionMedia(collection, param) {
	try {

		showAjaxCallProggress(false);
		renderStyle = param.renderStyle;
		div = param.div;
		pageNavTopDiv = param.pageNavTopDiv;
		pageNavDownDiv = param.pageNavDownDiv;
		pageTitleDiv = param.pageTitleDiv;
		imageHeight = param.imageHeight;
		imageWidth = param.imageWidth;
		maxRows = param.maxRows;
		maxCols = param.maxCols;
		imageIndex = (param.imageIndex == null ? 0 : param.imageIndex);

		var navCtlMode = getCookie("VideoNavCtlMode");
		if (renderStyle == 7 || renderStyle == 8) {
			navCtlMode = "enlarged";
		}

		if (navCtlMode == "enlarged") {// not equal because of the toggling of
			// navCtlMode
			if (param.renderStyle == 6 || param.renderStyle == 5) {
				thumbnailHeight = 75;
				thumbnailWidth = 100;
			} else {
				thumbnailHeight = param.thumbnailHeight;
				thumbnailWidth = param.thumbnailWidth;
			}

			imageWidth = '100%';
			if (renderStyle != 7 && renderStyle != 8) {
				maxRows = 4;// (isIE()? 3:4);
				param.maxRows = maxRows;
			} else {
				maxCols = param.maxCols;
			}

			if (param.renderStyle == 6) {
				imageWidth = '100%';
				maxCols = 5;
			} else if (param.renderStyle == 5) {
				maxCols = 1;
			}

		} else { // for small size style 6 view
			thumbnailWidth = 55;
			thumbnailHeight = 45;
			maxRows = 9;
			maxCols = 1;
		}

		param.imageWidth = imageWidth;
		param.maxCols = maxCols;
		param.maxRows = maxRows;
		param.thumbnailHeight = thumbnailHeight;
		param.thumbnailWidth = thumbnailWidth;

		previewMode = false;
		previewModeNoText = false;
		switch (renderStyle) {
		case 8:
			renderStyle = 6;
			previewMode = true;
			previewModeNoText = true;
			break;
		case 7:
			renderStyle = 6;
			previewMode = true;
			break;
		default:
			previewMode = false;
			previewModeNoText = false;
		}

		restoreValuesAfterAjaxCall();

		if (collection == null || collection.images == null
				|| collection.images.length == 0) {
			if (currentMediaInfo != null
					&& currentMediaInfo.video_id != undefined)
				collection.images[0] = currentMediaInfo;
			else
				return;
		}
		;
		currentCollectionId = collection.id;
		if (currentSortOrder == 'random') {
			randomizeCollectionMedia(collection);
		}
		if (renderStyle == 5) {// this style create a list view
			try {
				var idiv = _elem(div);
				// empty div

				var htmlStrFull = "<div align='center'>";
				var htmlStr = "";
				var htmlStrPart = "";
				var index = imageIndex - 1;

				for ( var rowCount = 0; rowCount < maxRows; rowCount++) {
					for ( var colCount = 0; colCount < maxCols; colCount++) {
						index += 1;
						if (index >= collection.images.length) {
							break;
						}

						htmlStr += "<div id='videoNavSection"
								+ index
								+ "' style='padding:10px;padding-bottom:5px;clear: both;'   align='center'>";

						if (collection != null
								&& collection.images[index] != null) {

							// * ******** left most section - representing the
							// thumbnail section
							// *********************************

							htmlStr += "<div id='videoThumbnailSection"
									+ index
									+ "' align='left' class='videoNavThumbnailLostFocused' style='float:left' onmouseover='mouseOnThumbnail(\""
									+ collection.id
									+ "\",\"videoThumbnailSection"
									+ index
									+ "\");' onmouseout='mouseOffThumbnail(\"videoThumbnailSection"
									+ index + "\");'>";

							htmlStr += navCtlMode == "enlarged" ? "<div class='navCtlThumbnail' align='center'>"
									: "<div class='video_thumbnail' align='center'>";

							htmlStr += "<a href=# OnClick=\"playSelectedVideo('"
									+ collection.id
									+ "',"
									+ index
									+ ");reportUserAction('play::','"
									+ collection.images[index].video_id
									+ "');return false;\"><img  id=ThumbnailImg src='"
									+ decodeURIComponent(collection.images[index].thumbnail)
									+ "'  width='"
									+ thumbnailWidth
									+ "' height='"
									+ thumbnailHeight
									+ "' /></a>";
							htmlStr += "</div>";
							htmlStr += "</div>";

							// * ***** end of thumbnail section
							// *****************************************************************************
							//

							htmlStr += "<div id='videoDescSection"
									+ index
									+ "'  align='left' style='float:left;margin-left:5px;"
									+ (navCtlMode == 'enlarged' ? 'width:450px;'
											: 'width:200px;') + "' >";

							// video title
							htmlStr += "<div><a class='video_title_style' href=# id='videoTitle"
									+ index
									+ "'   OnClick=\"playSelectedVideo('"
									+ collection.id
									+ "',"
									+ index
									+ ");reportUserAction('play::','"
									+ collection.images[index].video_id
									+ "'); return false;\">"
									+ collection.images[index].title
									+ "</a></div>";

							// video description
							htmlStr += "<div valign='top'  align='left' style='padding-bottom:5px;padding-right:2px;'> ";
							htmlStr += "<div  class='imageLabel' style='padding:0px;width:"
									+ imageWidth
									+ ";' id='videoDesc"
									+ index
									+ "'>"
									+ enableLinksInText(collection.images[index].desc)
									+ "</div>";
							htmlStr += "</div>";

							// video tags and date submitted section
							if (navCtlMode == "enlarged") {
								var tags = collection.images[index].tags;
								if (tags != null) {
									tags = tags.split(",");
									if (tags.length > 0) {
										htmlStr += "<div><span class='navCtlLabelTxt'>"
												+ getLocaleStr('tags', 'Tags')
												+ ":&nbsp;</span>";
									}
									for (kount = 0; kount < tags.length; kount++) {
										htmlStr += "<a href=# onClick=\"findContentByTags('"
												+ tags[kount]
												+ "','');reportUserAction('search_content_tag::','"
												+ tags[kount]
												+ "');return false;\" ><span class='navCtlTags'>"
												+ tags[kount]
												+ "</span></a>&nbsp;";
									}
									if (tags.length > 0) {
										htmlStr += "</div>";
									}

								}

								// from user
								htmlStr += "<div style='clear:both;'><span class='navCtlLabelTxt'>"
										+ getLocaleStr('from', 'From')
										+ ": </span><a href='profile.html?pageId="
										+ collection.images[index].comp_id
										+ "&ownerId="
										+ collection.images[index].comp_id
										+ "' class='navCtlTxt'>"
										+ collection.images[index].name
										+ "</a></div>";

								// date submitted

								htmlStr += "<div><span class='navCtlLabelTxt'>"
										+ getLocaleStr('submitted', 'Submitted')
										+ ": </span><span class='navCtlTxt'>"
										+ collection.images[index].date
										+ "</span>&nbsp;"
										+ ago(collection.images[index].date)
										+ "</div><br>";

							}
							htmlStr += "<div id='videoControlPanel'  align='left'>";
							// Download link

							htmlStr += "<div   style='padding-right:5px;float:left;' ><a "
									+ (hasAccessTo(
											"D",
											collection.images[index].access_restrict) ? "href=# class='video_links_style'  OnClick=\"download("
											+ collection.images[index].video_id
											+ ");reportUserAction('download::','"
											+ collection.images[index].video_id
											+ "');\""
											: " class='video_links_style_disabled'  ")
									+ " >"
									+ getLocaleStr('video_download', 'Download')
									+ "</a></div> ";

							// video embed & link
							if (navCtlMode == "enlarged") {
								htmlStr += "<div  style='padding-right:5px;float:left;' ><a "
										+ (hasAccessTo(
												"E",
												collection.images[index].access_restrict) ? "class='video_links_style'  href=#  OnClick=\"embedVideo('ComSec"
												+ collection.images[index].video_id
												+ "','"
												+ decodeURIComponent(collection.images[index].url)
												+ "','"
												+ decodeURIComponent(collection.images[index].thumbnail)
												+ "');reportUserAction('share_embed::','"
												+ collection.images[index].video_id
												+ "');return false;\""
												: "  class='video_links_style_disabled'   ")
										+ ">"
										+ getLocaleStr('featured_embed',
												'Embed') + "</a></div> ";
								htmlStr += "<div  style='padding-right:5px;float:left;' ><a "
										+ (hasAccessTo(
												"S",
												collection.images[index].access_restrict) ? "class='video_links_style' href=#   OnClick=\"linkToVideo('ComSec"
												+ collection.images[index].video_id
												+ "','"
												+ collection.images[index].web_link
												+ "');reportUserAction('share_link::','"
												+ collection.images[index].video_id
												+ "');return false;\""
												: "  class='video_links_style_disabled'   ")
										+ ">"
										+ getLocaleStr('link', 'Link')
										+ "</a></div> ";
							}
							htmlStr += "<div  style='padding-right:5px;float:left;' ><a "
									+ (hasAccessTo(
											"S",
											collection.images[index].access_restrict) ? "class='video_links_style' href=#   OnClick=\"emailContent('"
											+ encodeURIComponent(collection.images[index].desc)
											+ "','"
											+ collection.images[index].thumbnail
											+ "','"
											+ decodeURIComponent(collection.images[index].url)
											+ "','"
											+ encodeURIComponent(collection.images[index].title)
											+ "','"
											+ collection.images[index].video_id
											+ "');return false;\""
											: "  class='video_links_style_disabled'   ")
									+ ">"
									+ getLocaleStr('video_url_link', 'Email')
									+ "</a></div> ";

							htmlStr += "<div  style='padding-right:5px;float:left;' ><a class='video_links_style' href=# onClick=\"favourite("
									+ collection.images[index].video_id
									+ ");reportUserAction('favourite_content::','"
									+ collection.images[index].video_id
									+ "');return false;\" >"
									+ getLocaleStr('favourite', 'Favourite')
									+ "</a></div>";

							if (navCtlMode == "enlarged") {

								// htmlStr+="<div
								// style='padding-right:5px;float:left;' ><a
								// class='video_links_style' href=#
								// onClick=\"getMore('?compId="+collection.images[index].comp_id+"','notification','notificationType=findRelated&comp_id="+collection.images[index].comp_id
								// +"',param);\"
								// >"+getLocaleStr('featured_more','More')+"</a></div>";

								// comment
								htmlStr += "<div  style='margin-right:5px;float:left;' ><a class='video_links_style' href=# onClick=\"showComments("
										+ collection.images[index].video_id
										+ ",'ComSec"
										+ collection.images[index].video_id
										+ "');reportUserAction('comment_content_view::','"
										+ collection.images[index].video_id
										+ "');;return false;\" >"
										+ getLocaleStr('comment', 'Comment')
										+ "</a><a  id='aComSec"
										+ collection.images[index].video_id
										+ "'></a></div>";
								getCommentCount(
										collection.images[index].video_id,
										'aComSec' + collection.images[index].video_id);

								// web links
								htmlStr += "<div  style='margin-left:25px;float:left;"
										+ (hasAccessTo(
												"S",
												collection.images[index].access_restrict) ? "visibility:visible"
												: "visibility:hidden")
										+ "' >"
										+ getWebLinksHtml(
												collection.images[index].title,
												collection.images[index].web_link,
												collection.images[index].logo_link,
												encodeURIComponent(collection.images[index].desc),
												collection.images[index].tags)
										+ "</div>";

							}
							htmlStr += "</div>";

							// create separater
							if (navCtlMode == "enlarged") {
								htmlStr += "<div class='navCtlSep' ></div>";
							}
							htmlStr += "</div>";
						}

						htmlStr += "</div>";

						// for video comments
						htmlStr += "<div class='mediaComment' id='ComSec"
								+ collection.images[index].video_id
								+ "'></div>";

						if (collection != null
								&& index > collection.images.length) {
							break;
						}

					 	 
						// ------ display the currently selected on top
						// highlighted ----

						if (currentMediaInfo != null
								&& currentMediaInfo.video_id != undefined
								&& currentMediaInfo.video_id == collection.images[index].video_id) {

							htmlStrFull += "<div class='videoNavThumbnailFocused'>"
									+ htmlStr + "</div>";

						} else {
							htmlStrPart += htmlStr;
						}
						// avoid rendering the last video without showing the
						// selected video on top of the first page
						try {
							if (currentMediaInfo != null
									&& currentMediaInfo != undefined
									&& (index - imageIndex + 2 == maxCols
											* maxRows - 1)) {
								// swap the next row with the currently playing
								// in the collection
								var collection_new = swapMediaContent(
										collection,
										collection.images[index].video_id,
										currentMediaInfo.video_id);
								collection = null;
								collection = collection_new;
							}
							htmlStr = "";
						} catch (e) {
						}
  
						// -----------------------------------------------

					}
				}
				htmlStrFull += htmlStrPart + "</div>";

			} catch (e) {
			}
			// clear div
			try {
				while (idiv.firstChild)
					idiv.removeChild(idiv.firstChild);
			} catch (e) {
			}

			idiv.innerHTML = htmlStrFull;// htmlStr ;

			setTimeout(showVideoNavSelected, 2000);
		}

		if (renderStyle == 6) {
			try {
				var idiv = _elem(div);
				// empty div

				var htmlStr = "";
				var index = imageIndex;

				for ( var rowCount = 0; rowCount < maxRows; rowCount++) {
					htmlStr += "<div style=\"padding-bottom:5px;clear:both;\">";
					for ( var colCount = 0; colCount < maxCols; colCount++) {

						if (collection != null
								&& collection.images[index] != null) {
							htmlStr += "<div  "
									+ (!previewModeNoText && !previewMode ? " style='padding:2px;padding-left:5px;padding-right:5px;float:left;'"
											: " style='float:left;'") + ">";
							htmlStr += "<div id='videoThumbnailSection"
									+ index
									+ "'"
									+ (previewModeNoText ? ""
											: ("  align='left' class='videoNavThumbnailLostFocused'   onmouseover='mouseOnThumbnail(\""
													+ collection.id
													+ "\",\"videoThumbnailSection"
													+ index
													+ "\");' onmouseout='mouseOffThumbnail(\"videoThumbnailSection"
													+ index + "\");'")) + ">";
							htmlStr += (navCtlMode == "enlarged" ? (previewModeNoText ? "<div align='center'>"
									: "<div class='navCtlThumbnail' align='center'>")
									: "<div class='video_thumbnail' align='center'>");
							htmlStr += "<a href=# OnClick=\"playSelectedVideo('"
									+ collection.id
									+ "',"
									+ index
									+ ");reportUserAction('play::','"
									+ collection.images[index].video_id
									+ "');return false;\"><img  id=ThumbnailImg src='"
									+ decodeURIComponent(collection.images[index].thumbnail)
									+ "'  width='"
									+ thumbnailWidth
									+ "' height='"
									+ thumbnailHeight
									+ "'  "
									+ (previewModeNoText ? "title =\""
											+ collection.images[index].title
											+ "\"" : "") + "/></a>";
							htmlStr += "</div>";
							htmlStr += "</div>";

							if (!previewModeNoText) {
								htmlStr += " <div style=\"width:"
										+ thumbnailWidth
										+ "px\" ><table cellpadding='0' cellspacing='0' border='0'><tr><td   width='"
										+ thumbnailWidth
										+ "'><a class='video_title_style' href=# id='videoTitle"
										+ index
										+ "'  OnClick=\"playSelectedVideo('"
										+ collection.id + "'," + index
										+ ");reportUserAction('play::','"
										+ collection.images[index].video_id
										+ "');return false;\">"
										+ collection.images[index].title
										+ "</a></td></tr>";
								htmlStr += "</table></div>";
							}
							if (!previewMode) {
								htmlStr += "<div style=\"width:"
										+ thumbnailWidth
										+ "px\"><span class='navCtlLabelTxt'>"
										+ getLocaleStr('from', 'From')
										+ ": </span><a href='profile.html?pageId="
										+ collection.images[index].comp_id
										+ "&ownerId="
										+ collection.images[index].comp_id
										+ "' class='navCtlTxt'>"
										+ collection.images[index].name
										+ "</a></div>";
							}
							if (navCtlMode == "enlarged") {
								/*
								 * htmlStr+="<tr><td><span
								 * class='navCtlLabelTxt'>"+getLocaleStr('submitted','Submitted')+":
								 * </span><span
								 * class='navCtlTxt'>"+collection.images[index].date+"</span>&nbsp;"+ago(collection.images[index].date)+"<br></td></tr>";
								 */
							}

							htmlStr += "</div>";

							index += 1;

						}
					}

					htmlStr += "</div>";
					if (collection != null && index > collection.images.length) {
						break;
					}

				}

			} catch (e) {
			}
			// clear div
			try {
				while (idiv.firstChild)
					idiv.removeChild(idiv.firstChild);
			} catch (e) {
			}

			idiv.innerHTML = htmlStr;

		}
		htmlStr = null;
		setTimeout("beginTranslation(" + imageIndex + ")", 2000);

	} catch (e) {

	}
	renderPageNavigation(collection, index);

}
var previewMode = false, previewModeNoText = false;
function signinBeforePlayingVideo(contentId, scriptToRunOnSuccess) {
	if (!hasSignedIn()) {// code to allow user to perform the
		// necessary action to obtain access
		alert(getLocaleStr("signin_msg", "Please sign in"));
		setCookie("scriptAfterLogin", scriptToRunOnSuccess, null, null, null,
				null);
		signin();
		return true;
	}
	return false;
}
function accessSecuredContent(contentId, functionToCall,
		scriptToRunOnSigninSuccess) {
	/*
	 * Call functionToCall on success @Param info.*
	 */
	if (signinBeforePlayingVideo(contentId, scriptToRunOnSigninSuccess))
		return;

	UploadDownload.getSecureContentInfo(contentId, function(info) {
		if (info) {
			try {
				eval(functionToCall);
				return;
			} catch (e) {
			}
		} else {
			purchaseContent(contentId, functionToCall);
		}
	});

}
function playVideoById(videoId) {
	location.href = "http://multimq.com/cid/" + videoId;
}
function playSelectedVideo(collectionId, index) {

	var collection = findCollection(collectionId);

	if (collection == null) {
		alert(getLocaleStr("error", "Opps, something bad happened!!"));
		return;
	}
	try {
		// chech for viewing permission
		if (!hasAccessTo("W", collection.images[index].access_restrict)) {
			if (signinBeforePlayingVideo(collection.images[index].video_id))
				return;
		}

		// if video player is not found in this current page, redirect to
		// homepage and play video

		if (_elem("videoSection") != null) {
			if (collection.images[index].priced) {
				accessSecuredContent(collection.images[index].video_id,
						"playVideo(decodeURIComponent(info.contentUrl));",
						"location.href='index.jsp?cid="
								+ collection.images[index].video_id + "';");
				return;
			}
			playVideo(decodeURIComponent(collection.images[index].url));
			document.title = collection.images[index].title;

			// since ajax call is going to repopulate video info data array,
			// store all information pertaining to the video currently playing
			if (collection && collection.images[index]) {
				currentMediaInfo = collection.images[index];
			}

			// restrain from querying for related until the user says so
			var searchMode = getCookie("searchMode");

			if (searchMode == null || searchMode == undefined) {
				setCookie("searchMode", "", null, null, null, null);// setting
				// this
				// value to
				// anything
				// except
				// for null
				// will
				// cause the
				// Search
				// options
				// to be
				// displayed
			}

			renderSearchModes();

		} else {
			location.href = collection.images[index].web_link;
		}
	} catch (e) {
	} finally {
		collection = null;
	}
	return false;
}

function emailContent(desc, thumbnail, url, title, contentId) {
	invoke('notification', 'notificationType=initSession&ResourceDesc=' + desc
			+ '&ResourceLinkThumbnailURL=' + thumbnail
			+ '&ResourceLink=http://multimq.com/cid/' + contentId
			+ '&ResourceTitle=' + title);
	_adfspu('video:frmEmail', 0, 0, 'video:cmdEmail');
	reportUserAction('share_email::', contentId);

}

function getWebLinksHtml(linkTitle, linkUrl, linkThumbnail, linkDesc, linktags) {
	var linkStr = "";
	try {
		var diggLinkUrl = "http://multimediaquest.com";// multimq has been
		// deactivated by digg
		diggLinkUrl = linkUrl.replace("http://multiMQ.com", diggLinkUrl);
		var tag = "";
		try {
			/*
			 * var tagList=linktags.split(",");
			 * 
			 * for(var i=0;i<tagList.length;i++){ if(tagList[i]!=null &&
			 * tagList[i]!="" && tagList[i]!=" "){ tags+=tagList[i]+" "; } }
			 */
			tag = linktags.replaceAll(/,*/, " ");
		} catch (e) {
		}

		linkStr += '<a target="_blank" class="weblink-image-link windowOpener" title="Share this video on Facebook" href="http://www.facebook.com/sharer.php?u='
				+ linkUrl + '&amp;t=' + linkTitle + '" id="facebook"></a> ';
		linkStr += '<a target="_blank" class="weblink-image-link" title="Del.icio.us" href="http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url='
				+ linkUrl
				+ '&amp;title='
				+ linkTitle
				+ '&amp;tags='
				+ tag
				+ '&amp;notes=' + linkDesc + '" id="delicious"></a> ';
		linkStr += '<a target="_blank" class="weblink-image-link" title="Digg it!" href="http://digg.com/submit?phase=2&amp;url='
				+ diggLinkUrl
				+ '&amp;title='
				+ linkTitle
				+ '&amp;bodytext='
				+ linkDesc
				+ '&amp;thumbnail='
				+ linkThumbnail
				+ '" id="digg"></a> ';
		linkStr += '<a target="_blank" class="weblink-image-link" title="Stumbleupon" href="http://www.stumbleupon.com/submit?url=' + linkUrl + '" id="stumble"></a>';
		linkStr += '<a target="_blank" class="weblink-image-link" title="Reddit" href="http://reddit.com/submit?url='
				+ linkUrl + '&amp;title=' + linkTitle + '" id="reddit"></a>';
		/*
		 * linkStr += '<a target="_blank" class="weblink-image-link"
		 * title="Propeller" href="http://www.netscape.com/submit/?U=' + linkUrl +
		 * '&amp;T=' + linkTitle + '&amp;C=' + linkDesc + '" id="netscape"></a>';
		 */
		linkStr += '<a target="_blank" class="weblink-image-link" title="Twitter" href="http://twitter.com/home?status='
				+ linkTitle.replace(/\s+/g, "+")
				+ '+'
				+ linkUrl
				+ '" id="netscape"></a>';

	} catch (e) {
	}
	return linkStr;
}

function hasAccessTo(accessFlag, access_restrict) {
	return ((access_restrict == null || access_restrict == undefined
			|| access_restrict == "_" || access_restrict.indexOf(accessFlag)) >= 0 ? true
			: false);
}

function renderAssociatedDivs() {

	if (!(param.renderStyle == 5 || param.renderStyle == 6))
		return;

	renderStyle = param.renderStyle;
	div = param.div;
	pageNavTopDiv = param.pageNavTopDiv;
	pageNavDownDiv = param.pageNavDownDiv;
	pageTitleDiv = param.pageTitleDiv;
	imageHeight = param.imageHeight;
	imageWidth = param.imageWidth;
	maxRows = param.maxRows;
	maxCols = param.maxCols;

	var navCtlMode = getCookie("VideoNavCtlMode");

	var htmlStr = "";
	var ipagediv = _elem(pageNavTopDiv);

	// topmost level
	htmlStr = '<div class="navCtlTitle"><div id="navCtlHeaderTop">';
	// content source
	htmlStr += '<div id="navCtlSourceDiv"><label for="sourceList" class="navCtlLabel">' + getLocaleStr(
			'download_source', 'Source') + '&nbsp;<select name="sourceList" id="sourceList"  onchange="contentSourceChanged();" class="NavCtlComboStyle"></select></label></div>';

	// search
	htmlStr += "<div id='navCtlSearchDiv'><form onSubmit='return searchForContent();' method='GET'><label for='navCtlSearchInput' accesskey='2' id='navCtlSearchLabel'  class='navCtlSearchLabel' >"
			+ getLocaleStr('search', 'Search')
			+ "</label><input id='navCtlSearchInput' class='NavCtlSearch' type='text' value='' maxlength='100' size='20' onfocus='_elem(\"navCtlSearchLabel\").style.visibility=\"hidden\"' onmouseout='if(_elem(\"navCtlSearchInput\").value==\"\")_elem(\"navCtlSearchLabel\").style.visibility=\"visible\";'><input id='navCtlSearchSubmit'  onclick='searchForContent();reportUserAction(\"search_content_entered_text::\",null);return false;' src=\"images/search.gif\" alt=\"Search\" type=\"image\"></form></div>";

	// Search options
	htmlStr += "<div id='navCtlSearchOpt'></div>";

	// view Style
	htmlStr += "<div id='navCtlToggleView'></div>";

	// Minimize bottom
	if (!(_elem("videoSection") == null ? true : false)) {
		htmlStr += " <div id='navCtlHeaderMax'><a  href=# onClick=\"setCookie('VideoNavCtlMode','minimized',null,null,null,null);resize(controlParam);return false;\"><img src='video_images/navMin.png' title='"
				+ getLocaleStr('minimize', 'Minimize')
				+ "' alt='"
				+ getLocaleStr('minimize', 'Minimize') + "'></a> </div> ";
	}
	// # end minimize bottom

	htmlStr += "</div>";
	// ##### End of topmost

	// render page title
	htmlStr += "<div id='navCtlHeaderBottom'>";
	htmlStr += " <div id='contentNavSortOrderDiv'></div>";
	htmlStr += " <div id='contentNavAgeOrderDiv'></div>";

	// reset
	try {
		htmlStr += "<div id='resetDiv'><a href=# onClick=\"resetQuery();reportUserAction('search_reset::',null);return false;\" class='navCtlHeader'>("
				+ getLocaleStr('reset', 'Reset') + ")</a> </div>";
	} catch (e) {
	}
	// media type filter
	htmlStr += "  <div id='nav_ctl_media_type' style='width:180px'></div>";

	htmlStr += "<div style='clear:both;'></div></div></div>";

	_elem(pageTitleDiv).display = 'block';
	ipagediv = _elem(pageTitleDiv);
	ipagediv.innerHTML = htmlStr;

	// allow for a little time for the browser to convert the html to objects in
	// the dom
	setTimeout(refreshContentCtlHeader, 800);
}

function searchForContent() {

	var tags = _elem("navCtlSearchInput").value;
	// tags=tags.replace(/\s+/g,",");
	findContentByTags(tags, "matchAllSearchTerms=true");
	return false;
}

function refreshContentCtlHeader() {
	initContentSourceSelection();
	renderSearchModes();
	renderContentNavAgeOrder();
	renderContentNavSortOrder();
	renderNavToggler();
	renderMediaType();// called after html elements have been created in the
	// DOM to show the selected media type

}
function renderNavToggler() {
	try {
		var htmlStr = "<!--<span class='navCtlHeader'>"
				+ getLocaleStr('view_as', 'View As') + ":&nbsp;</span>-->";
		if (param.renderStyle == 6) {
			htmlStr += "<a href=# onClick=\"switchNavViewMode('thumbnail');reportUserAction('play_nav_switch_view_mode::','thumbnail');return false;\"><img src='video_images/list_button.png' title='"
					+ getLocaleStr('thumbnail', 'Thumbnail')
					+ "' alt='"
					+ getLocaleStr('thumbnail', 'Thumbnail')
					+ "'></a>&nbsp;&nbsp;";
		} else {
			htmlStr += "<a href=# onClick=\"switchNavViewMode('list');reportUserAction('play_nav_switch_view_mode::','list');return false;\"><img src='video_images/thumb_button.png' title='"
					+ getLocaleStr('list', 'List')
					+ "' alt='"
					+ getLocaleStr('list', 'List') + "'></a>&nbsp;&nbsp;";
		}

		_elem("navCtlToggleView").innerHTML = htmlStr;
	} catch (e) {
	}
}
function contentNavAgeOrderChanged(timeFactor) {
	currentTimeFactor = timeFactor;
	currentPage = 0;
	renderContentNavAgeOrder();
	queryForContent();

	reportUserAction('play_nav_sort-order_age::', timeFactor);
}
function hideExtraContentNavAgeOrder(flag) {
	contentNavAgeOrderShouldBeHidden = flag;
	if (flag) {
		contentNavAgeOrderTimerId = setTimeout("dynaContentNavAgeOrder(false)",
				6000);
	} else {
		dynaContentNavAgeOrder(true);
	}
}
var contentNavAgeOrderTimerId = 0;
var contentNavAgeOrderShouldBeHidden = true;
function dynaContentNavAgeOrder(flag) {
	try {
		var htmlStr = "";

		var styleUnsel = "navCtlTitleUnSelected";
		var styleSel = "navCtlTitleSelected2";
		if (flag) {

		} else {
			if (!contentNavAgeOrderShouldBeHidden) {
				clearTimeout(contentNavAgeOrderTimerId);
				return;
			}
			styleUnsel = "navCtlTitleUnSelectedAndHidden";
		}

		var timeFactor = [ 'today', 'week', 'month', 'year', 'all_time' ];
		var timeStr = [ 'today', 'weekly', 'monthly', 'yearly', 'all_time' ];
		for (fCount = 0; fCount < timeFactor.length; fCount++) {
			if (currentTimeFactor == timeFactor[fCount]) {
				htmlStr += "<a class='"
						+ styleSel
						+ "' onmouseover=\'hideExtraContentNavAgeOrder(false);\' onmouseleave=\'hideExtraContentNavAgeOrder(true);\' onmouseout=\'hideExtraContentNavAgeOrder(true);\'>"
						+ getLocaleStr(timeStr[fCount], timeStr[fCount])
						+ "</a>&nbsp;&nbsp;";
			} else {
				htmlStr += "<a  class='" + styleUnsel
						+ "' href=# onClick=\"contentNavAgeOrderChanged('"
						+ timeFactor[fCount]
						+ "');return false;\"><span class='" + styleUnsel
						+ "'>" + getLocaleStr(timeStr[fCount], timeStr[fCount])
						+ "</span></a>&nbsp;&nbsp;";
			}

		}

		_elem("contentNavAgeOrderDiv").innerHTML = htmlStr;
	} catch (e) {
	}
}

function renderContentNavAgeOrder() {
	dynaContentNavAgeOrder(false);

}

function renderSearchModes() {
	try {
		var canQuery = false;
		var sOpt = _elem("navCtlSearchOpt");
		var searchMode = getCookie("searchMode");// could enther be R - for
		// related content, U for
		// more from this user or C
		// from collection
		if (searchMode == null || searchMode == undefined) {
			sOpt.style.visibility = "hidden";
			return;
		} else {
			sOpt.style.visibility = "visible";
		}
		var htmlStr = "";
		var modes = [];
		if (_elem("videoSection") != null) {
			modes
					.push(new Array("R", "search_mode_related", "Recommended",
							"search_mode_related_detail",
							"Search for content related to the current content being played"));
			modes
					.push(new Array("U", "search_mode_user", "This User",
							"search_mode_user_detail",
							"Search for content belonging to the owner of the current content being played"));
			modes
					.push(new Array(
							"C",
							"search_mode_collection",
							"Collection",
							"search_mode_collection_detail",
							"Retrieve only content contained in the collection the current content belongs to"));
		} else {
			modes.push(new Array("F", "favourite", "Favourite"));

		}

		for ( var m = 0; m < modes.length; m++) {
			if (searchMode.indexOf(modes[m][0]) != -1) {
				htmlStr += '<div id="navCtlSearchModeSel" title=\"'
						+ getLocaleStr(modes[m][3], modes[m][4])
						+ '\" onmouseover=\"this.style.cursor=\'pointer\'\" onclick="SearchModesChanged(\''
						+ modes[m][0] + '\');">'
						+ getLocaleStr(modes[m][1], modes[m][2]) + '</div>';
			} else {
				htmlStr += '<div id="navCtlSearchModeUnSel" title=\"'
						+ getLocaleStr(modes[m][3], modes[m][4])
						+ '\" onmouseover=\"this.style.cursor=\'pointer\'\" onclick="SearchModesChanged(\''
						+ modes[m][0] + '\');">'
						+ getLocaleStr(modes[m][1], modes[m][2]) + '</div>';
			}
		}
		_elem("navCtlSearchOpt").innerHTML = htmlStr;

		if (currentMediaInfo != null && searchMode != null && searchMode != "") {
			var extraParam = "";
			var tags = "";

			if (searchMode.indexOf("R") != -1) {
				// tags formating is done at the server's end
				// tags=currentMediaInfo.tags.replace(/\s+/g,",");
				tags = currentMediaInfo.tags;
				canQuery = true;
			}
			if (searchMode.indexOf("U") != -1) {
				extraParam += "&compId=" + currentMediaInfo.comp_id;
				canQuery = true;
			}
			if (searchMode.indexOf("C") != -1) {
				extraParam += "&getContentInCollection=true&contentId="
						+ currentMediaInfo.video_id;
				canQuery = true;
			}

		}

		if (searchMode.indexOf("F") != -1) {
			extraParam += "&compId=" + getCookie("compIdForFavourite")
					+ "&getOnlyFavourite=true";
			canQuery = true;
		}
		if (canQuery) {
			findContentByTags(tags, extraParam);
		}

	} catch (e) {
	}
}
function SearchModesChanged(newMode) {

	try {
		var searchMode = getCookie("searchMode");
		if (searchMode == null || searchMode == undefined)
			searchMode = "_";// some dummy value either than null
		// add to mode, note: newMode might contain more than one mode
		for ( var i = 0; i < newMode.length; i++) {
			if (searchMode.indexOf(newMode) == -1) {
				searchMode += newMode;
			} else {
				// remove from mode
				searchMode = searchMode.replace(newMode, "");
			}
		}

		setCookie("searchMode", searchMode, null, null, null, null);
		renderSearchModes();

	} catch (e) {
	}
	reportUserAction('play_nav_search_mode::', newMode);
}
function renderContentNavSortOrder() {
	try {
		var htmlStr = "";
		if (currentSortOrder == 'date') {
			htmlStr += "<span class='navCtlTitleSelected'>"
					+ getLocaleStr('most_recent', 'Most Recent')
					+ "</span>&nbsp;&nbsp;";
		} else {
			htmlStr += "<a href=# onClick=\"contentNavSortChanged('date');return false;\"><span class='navCtlTitleUnSelected'>"
					+ getLocaleStr('most_recent', 'Most Recent')
					+ "</span></a>&nbsp;&nbsp;";
		}

		if (currentSortOrder == 'popularity') {
			htmlStr += "<span class='navCtlTitleSelected'>"
					+ getLocaleStr('most_popular', 'Most Popular')
					+ "</span>&nbsp;&nbsp;";
		} else {
			htmlStr += "<a href=# onClick=\"contentNavSortChanged('popularity');return false;\"><span class='navCtlTitleUnSelected'>"
					+ getLocaleStr('most_popular', 'Most Popular')
					+ "</span></a>&nbsp;&nbsp;";
		}
		_elem("contentNavSortOrderDiv").innerHTML = htmlStr;
	} catch (e) {
	}
}
function contentNavSortChanged(sOrder) {
	currentSortOrder = sOrder;
	currentPage = 0;
	renderContentNavSortOrder();
	queryForContent();
	reportUserAction('play_nav_sort-order_popularity::', sOrder);
}
function queryForContent() {
	var searchMode = getCookie("searchMode");
	if (searchMode != null && searchMode != undefined && searchMode != "") {
		findRelatedVideos(currentIndex);
	} else {
		findContentByTags("", "");
	}

}
function switchNavViewMode(currentViewStyle) {

	if (currentViewStyle == "list") {
		param.renderStyle = 6;

	} else if (currentViewStyle = "thumbnail") {
		param.renderStyle = 5;
	}
	currentPage = 0;
	renderNavToggler();
	renderCollectionMedia(findCollection(currentCollectionId), param);
}
function enableLinksInText(inputTxt) {
	return inputTxt; // still debugginh

	var MAX_ALLOWED_LINKS_IN_TXT = 10;
	var txt = inputTxt;
	if (txt == null || txt == undefined)
		return txt;

	// check for http://
	var sPos = 0;
	ePos = 0;
	var linkTxt = "";
	var count = 0;

	while (txt.indexOf("http://") != -1 && count < MAX_ALLOWED_LINKS_IN_TXT) {
		txt = formatLinkTxt(txt, "http://", true);

		count += 1;
	}
	while (txt.indexOf("www.") != -1 && count < MAX_ALLOWED_LINKS_IN_TXT) {
		txt = formatLinkTxt(txt, "www.", true);
		count += 1;
	}

	return txt;

}

function formatLinkTxt(txt, replTxt, isPreceeding) {
	var linkTxt = "";
	var delimiter = " ";
	var sPos = 0;
	var outTxt = "";
	if (isPreceeding) {
		linkTxt = txt.subStr((sPos = txt.indexOf(replTxt)) - replTxt.length,
				txt.indexOf(delimiter, sPos));

		// Next, there should be a . somthing at the end, and also avoid
		// replacing at already formatted text
		if (linkTxt.indexOf(".") != -1
				&& txt.indexOf("<a href='", sPos - "<a href='".length + 1) == -1) {
			outTxt = txt.replace(linkTxt, "<a href='"
					+ linkTxt
					+ "'  target='_blank'>"
					+ txt.subStr(txt.indexOf(replTxt), txt.indexOf(delimiter,
							sPos))// remove protocol txt
					+ "</a>");
		}
	} else {// for surfices
		/*
		 * linkTxt=txt.subStr(txt.lastIndexOf(replTxt)-replTxt.length,txt.indexOf(delimiter,pos));
		 * //make sure a delimiter exist after replacing txt
		 * if(linkTxt.indexOf(".")!=-1){ }
		 */
	}
	return outTxt;
}

function renderPageNavigation(collection, index) { // index is the current item
	// in the collection at the
	// start of the page

	if (!collection)
		return;
	// render pages navigation
	// rest of images are left to be displayed on different pages
	if (collection.images.length - index > -1) {
		htmlStr = "<table width=100%><tr><td></td></tr><tr><td width='25%'></td><td><td align='right'><span class='pageNavTitleStyle' >"
				+ getLocaleStr("pages", "Pages")
				+ ":</span><td  align=right><A onClick=\"renderPage(-1);return false;\"  href='#'  class='pageNavStyle'><img src='images/arrow_prev.gif' atl='<<'></A>";
		var totalPageCount = 0;
		for ( var pages = 0; pages < (collection.images.length)
				/ (maxRows * maxCols); pages++) {
			if (currentPage == pages) {
				htmlStr += "<span class='pageNavStyle2'>" + (pages + 1)
						+ "</span>";
			} else {
				if (totalPageCount > 20) {
					htmlStr += "<A  onClick=\"renderPage("
							+ pages
							+ ");currentPage="
							+ pages
							+ ";return false;\"  href='#' class='pageNavStyle'>...</A>";
					break;
				} else {
					htmlStr += "<A  onClick=\"renderPage("
							+ pages
							+ ");currentPage="
							+ pages
							+ ";return false;\"  href='#' class='pageNavStyle'>"
							+ (pages + 1) + "</A>";
				}
			}
			totalPageCount += 1;
		}

		htmlStr += "<A onClick='renderPage(-2);return false;'  href='#'  class='pageNavStyle' > <img src='images/arrow_next.gif' atl='>>'> </A>";
		htmlStr += "</td></tr><tr><td></td></tr></table>";
		ipagediv = _elem(pageNavTopDiv);
		// ipagediv.style.display='block';
		ipagediv.innerHTML = htmlStr;
		ipagediv = _elem(pageNavDownDiv);
		ipagediv.style.display = 'block';
		ipagediv.innerHTML = htmlStr;
	} else {// no need for page navigation
		if (collection.images.length - index <= 0
				&& collection.images.length < maxRows) {
			clearInnerHTML(_elem(pageNavTopDiv));
			clearInnerHTML(_elem(pageNavDownDiv));
		}
	}

}

function contentSourceChanged() {
	var sel = _elem("sourceList");
	setCookie('ContentSource', sel.value, null, null, null, null);
	resetQuery();// refetch records
}

var currentPage = 0;

function resetQuery() {
	showAjaxCallProggress(true);
	currentIndex = -1;
	currentSortOrder = 'random';
	currentPage = 0;
	currentTimeFactor = 'all_time';
	currentMediaInfo = null;
	setCookie('currentVideoId', null, null, null, null, null);
	setCookie('searchMode', null, null, null, null, null);

	renderAssociatedDivs();
	// check whether searching for related videos is relevant
	var extraParam = "&filterOpt=" + getCookie("MediaTypeFilter");
	if (getCookie("VideoCtlPageType") != "collectionPage") {
		var source = getCookie("ContentSource");
		source = source == null ? "" : source;
		source = source.replace("Q", "");
		loadNavigation('notification', 'notificationType=findRelated&time='
				+ currentTimeFactor + '&tags=_&source=' + source + extraParam,
				param);
	} else {
		loadNavigation('notification', getCookie('parameter') + extraParam,
				param);
	}

}

function renderPage(pageNum) {

	try {
		var navCtlMode = getCookie("VideoNavCtlMode");
		if (navCtlMode == "enlarged") {// not equal because of the toggling of
			// navCtlMode
			maxRows = 4;
		}

		collectionId = currentCollectionId;
		var collection = findCollection(collectionId);
		// avoid repeatition
		if (pageNum != -1 && pageNum != -2) {
			currentPage = pageNum;
		}
		if (pageNum == imageIndex) {
			return;
		}
		if (pageNum == -2) {// next page - negative number are used as controls
			currentPage += 1;
			pageNum = currentPage;
		}
		if (pageNum == -1) {// go to previous page
			currentPage -= 1;
			pageNum = currentPage;
		}

		var oldIndex = imageIndex;
		imageIndex = pageNum * maxRows * maxCols;

		if (param != null || param != undefined) {
			param.imageIndex = imageIndex;
		}

		renderCollectionMedia(collection, param);

		if (param != null || param != undefined) {
			param.imageIndex = oldIndex;
		}

	} catch (e) {
	}

}
var isMouseOn = false;
var isMouseOff = false;
var contentProtectedIcon = null;
function mouseOnThumbnail(callId, id) {
	if (!isMouseOn) {
		_elem(id).className = "videoNavThumbnailFocused";
		isMouseOn = true;
	}
	isMouseOff = false;

	// add protection icon if protected
	var collection = findCollection(callId);
	try {
		var indexFromThumbnail = id.substr("videoThumbnailSection".length);
		if (collection.images != null
				&& collection.images[indexFromThumbnail] != null) {
			if (!hasAccessTo("W",
					collection.images[indexFromThumbnail].access_restrict)) {
				contentProtectedIcon = document.createElement("img");
				contentProtectedIcon.src = "images/viewRestricted.png"
				contentProtectedIcon.style.styleFloat = "right";
				contentProtectedIcon.style.position = "absolute";
				contentProtectedIcon.style.marginTop = "-34px";
				contentProtectedIcon.style.padding = "1px";
				contentProtectedIcon.style.zIndex = _elem(id).style.zIndex + 5;
				_elem(id).appendChild(contentProtectedIcon);
			}
		}
	} catch (e) {
	} finally {
		collection = null;
	}
}
function mouseOffThumbnail(id) {
	if (!isMouseOff) {
		_elem(id).className = "videoNavThumbnailLostFocused";
		isMouseOff = true;
	}

	isMouseOn = false;
	if (contentProtectedIcon != null) {
		clearInnerHTML(contentProtectedIcon);
	}
}
function showVideoNavSelected() {
	var collection = findCollection(currentCollectionId);
	try {
		var prefix = "videoNavSection";
		var div = null;
		for ( var i = 0; i < collection.images.length; i++) {
			div = _elem(prefix + i);
			if (div == null)
				continue;
			if (i == currentIndex) {
				div.className = "videoNavSelected";
				div.style.height = _elem("videoDescSection" + i).offsetHeight + 'px';
			} else {
				div.className = "videoNavUnSelected";
			}

		}
		// update source combo to reflect current state
		_elem("sourceList").value = getCookie('ContentSource');

	} catch (e) {
	} finally {
		collection = null;
	}

}

function mediaTypeChanged(filter) {
	/*
	 * matches this filter against a stored filter to toggle off and on the
	 * mediatype filter Note: filters are stored in specific order, VPG
	 */
	var newFilter = getCookie("MediaTypeFilter") == null ? " "
			: getCookie("MediaTypeFilter");// first char = either blank or V,
	// second either blank or P
	var mTypes = Array("V", "G", "P", "M");

	for ( var i = 0; i < mTypes.length; i++) {
		if (filter == mTypes[i]) {
			if (newFilter.indexOf(mTypes[i]) != -1) {
				newFilter = newFilter.replace(mTypes[i], "");
			} else {
				newFilter += mTypes[i];
			}
		}
	}

	setCookie('MediaTypeFilter', newFilter, null, null, null, null);
	renderMediaType();

	queryForContent();
	reportUserAction('play_nav_media-type-switch::', filter);
}
function renderMediaType() {
	try {
		var storedFilter = getCookie("MediaTypeFilter");
		if (storedFilter == null) {
			storedFilter = "P";
			setCookie("MediaTypeFilter", storedFilter, null, null, null, null);
		}

		var htmlStr = "";
		if (storedFilter.indexOf('V') != -1) { // toggle off video filter
			htmlStr += "<div id='mediaTypeDivVideo' style='float:left;width:40' class='mediaTypeInactive' onmouseover=\"this.style.cursor='pointer'\" onclick=\"mediaTypeChanged(\'V\')\" >"
					+ getLocaleStr('content_type_video', 'Video') + "</div> ";
		} else {
			htmlStr += "<div id='mediaTypeDivVideo' style='float:left;width:40;' class='mediaTypeActive' onmouseover=\"this.style.cursor='pointer'\" onclick=\"mediaTypeChanged(\'V\')\" >"
					+ getLocaleStr('content_type_video', 'Video') + "</div> ";
		}
		// inactive for a while -audio & music
		if (storedFilter.indexOf('M') != -1) {// toggle off video filter
			htmlStr += "<div id='mediaTypeDivMusic' style='float:left;width:40;' class='mediaTypeInactive' onmouseover=\"this.style.cursor='pointer'\" onclick=\"mediaTypeChanged(\'M\')\" >"
					+ getLocaleStr('content_type_music', 'Music') + "</div> ";
		} else {
			htmlStr += "<div id='mediaTypeDivMusic' style='float:left;width:40;' class='mediaTypeActive' onmouseover=\"this.style.cursor='pointer'\" onclick=\"mediaTypeChanged(\'M\')\" >"
					+ getLocaleStr('content_type_music', 'Music') + "</div> ";
		}

		if (storedFilter.indexOf('P') != -1) {
			htmlStr += "<div id='mediaTypeDivImage' style='float:left;width:50;' class='mediaTypeInactive' onmouseover=\"this.style.cursor='pointer'\" onclick=\"mediaTypeChanged(\'P\')\" >"
					+ getLocaleStr('content_type_picture', 'Photo') + "</div>";
		} else {
			htmlStr += "<div id='mediaTypeDivImage' style='float:left;width:50;' class='mediaTypeActive' onmouseover=\"this.style.cursor='pointer'\" onclick=\"mediaTypeChanged(\'P\')\" >"
					+ getLocaleStr('content_type_picture', 'Photo') + "</div>";
		}

		if (storedFilter.indexOf('G') != -1) {// toggle off video filter
			htmlStr += "<div id='mediaTypeDivGame' style='float:left;width:40;' class='mediaTypeInactive' onmouseover=\"this.style.cursor='pointer'\" onclick=\"mediaTypeChanged(\'G\')\" >"
					+ getLocaleStr('content_type_game', 'Game') + "</div> ";
		} else {
			htmlStr += "<div id='mediaTypeDivGame' style='float:left;width:40;' class='mediaTypeActive' onmouseover=\"this.style.cursor='pointer'\" onclick=\"mediaTypeChanged(\'G\')\" >"
					+ getLocaleStr('content_type_game', 'Game') + "</div> ";
		}

		_elem("nav_ctl_media_type").innerHTML = htmlStr;
	} catch (e) {
	}
}

var currentMediaInfo = null;

function findRelatedVideos(index) {

	var collection = findCollection(currentCollectionId);
	try {
		// save current index - Note: storing the index is of no use since
		// collection is repopulated after ajax call
		if (collection != null && collection.images[index] != null
				&& (index < 0 || index > collection.images.length)) {
			setCookie('currentVideoId', collection.images[index].video_id,
					null, null, null, null);
		}
		currentIndex = index;// for intermittent use
		setCookie('autoPlayFeatured', 'false', null, null, null, null);

		// add title to tags
		var tags = '';
		if (collection != null && collection.images[index] != null) {
			tags = (index < 0 || index > collection.images.length ? ''
					: collection.images[index].tags);
		}
		try {
			var title = collection.images[index].title;
			if (title != null) {
				// title=title.replace(/\s+/g,",");
				title = title.replace("'s", "");// avoid 's
				title = title.replace("'S", "");
				title = title.replace("'", "");
				tags = title + "," + tags;
			}
		} catch (e) {
		}

		findContentByTags(tags, "");

	} catch (e) {
	} finally {
		collection = null;// release memory
	}

}
function findContentByTags(tags, extraParam) {

	try {
		showAjaxCallProggress(true);
		// add time factor to ajax call
		var callParam = "&" + extraParam + "&";
		if (currentTimeFactor != null && currentTimeFactor != 'all_time') {
			callParam = "&time=" + currentTimeFactor;
		}
		// add sort order
		callParam += "&sort=" + currentSortOrder;

		// add media type filtering
		callParam += "&filterOpt=" + getCookie("MediaTypeFilter");

		// add content source
		callParam += "&source=" + getCookie("ContentSource");

		// check whether searching for related videos is relevant
		if (getCookie("VideoCtlPageType") != "collectionPage") {
			callParam += "&tags=" + tags;
			loadNavigation('notification',
					'notificationType=findRelated&' + callParam, param);
		} else {
			loadNavigation('notification', getCookie('parameter') + callParam,
					param);
		}
	} catch (e) {
	}

}
document.onmousedown = trackCurrentClickPos;
var mousePos;
function trackCurrentClickPos(e) {
	mousePos = getMousePos(e);
}
function showAjaxCallProggress(show) {
	try {
		var ajaxProgDiv = _elem("ajaxProgDiv");
		if (!show) {
			// hide
			if (ajaxProgDiv != null) {
				clearInnerHTML(ajaxProgDiv);
			}
			return;
		}

		if (ajaxProgDiv == null) {
			ajaxProgDiv = document.createElement("div");
			ajaxProgDiv.id = "ajaxProgDiv";
		}
		ajaxProgDiv.style.top = "35px";// mousePos[1]+"px";
		ajaxProgDiv.style.left = mousePos[0] - 360 + "px";
		ajaxProgDiv.style.styleFloat = "left";
		ajaxProgDiv.style.position = "absolute";
		ajaxProgDiv.style.display = "block";
		ajaxProgDiv.style.zIndex = 1000;

		ajaxProgDiv.innerHTML = "<img src='images/loader.gif' alt='-----------------------'>";

		_elem("tableDiv").appendChild(ajaxProgDiv);
	} catch (e) {

	}

}
function restoreValuesAfterAjaxCall() {
	// ------------restore current index ------------------
	try {
		var collection = findCollection(currentCollectionId);
		currentIndex = -1;
		var videoId = getCookie('currentVideoId');
		for ( var i = 0; i < collection.images.length; i++) {
			if (videoId == collection.images[i].video_id) {
				currentIndex = i;
				break;
			}
		}

		// make sure the currently playing media in contained in new collection
		// from ajax call, if not then restore
		if (currentMediaInfo != null) {
			var currentMediaInfoExists = false;
			for ( var i = 0; i < collection.images.length; i++) {
				if (currentMediaInfo.video_id == collection.images[i].video_id) {
					currentMediaInfoExists = true;
					break;
				}
			}
			if (!currentMediaInfoExists) {

				/*
				 * collection[collection.images.length] = new CollectionImage(
				 * currentMediaInfo.url, currentMediaInfo.thumbnail,
				 * currentMediaInfo.comp_id, currentMediaInfo.date,
				 * currentMediaInfo.tags, currentMediaInfo.title,
				 * currentMediaInfo.desc, currentMediaInfo.view_count,
				 * currentMediaInfo.video_id, currentMediaInfo.name,
				 * currentMediaInfo.logo_link, currentMediaInfo.web_link,
				 * currentMediaInfo.access_restrict);
				 */

				collection[collection.images.length] = currentMediaInfo;
				storeCollection(collection);
			}
		}

		// ------------ end of restore current index ---------------
	} catch (e) {
	} finally {
		// collection=null;//free memory
	}
}

function indexOfContent(collection, contentId) {
	for ( var k = 0; k < collection.images.length; k++) {
		if (collection.images[k].video_id == contentId)
			return k;
	}
	return -1;
}
function swapMediaContent(collection, contentId1, contentId2) {

	try {
		var p1 = indexOfContent(collection, contentId1);
		var p2 = indexOfContent(collection, contentId2);

		var tempStore = collection.images[p1];

		collection.images[p1] = collection.images[p2];

		collection.images[p2] = tempStore;

		return collection;
	} catch (e) {
	}
	return null;
}

// ---------------- video comment section -------------------
var isSpamHidden = false;
function getCommentCount(videoId, elemId) {

	dojo
			.xhrGet( {
				url :'service?action=getMediaComments&findTotalComment=true&mediaId=' + videoId,
				handleAs :"xml",
				load : function(data, evt) {

					var comment = data.getElementsByTagName("comment_data");
					for ( var col = 0; col < comment.length; col++) {
						var cInfo = comment[col];
						_elem(elemId).innerHTML = " <span style='font-weight:normal;'>("
								+ cInfo.getAttribute("comment_count")
								+ ")</span>";
					}
				}
			});

}
function hideSpams() {
	var comDiv = null;
	for ( var i = 0; i < spamLevels.length; i++) {
		comDiv = _elem(spamLevels[i].id);
		if (comDiv == null)
			continue;
		if (spamLevels[i].value >= MAX_FLAG_COUNT_FOR_A_SPAM && isSpamHidden) {
			comDiv.style.display = 'none';
		} else {
			comDiv.style.display = 'block';
		}
	}

	var a = _elem('spamDisplay');
	if (isSpamHidden) {
		isSpamHidden = false;
		// hide them
		a.innerHTML = getLocaleStr("show_spam", "Show Spam");

	} else {
		isSpamHidden = true;
		// show spam then
		a.innerHTML = getLocaleStr("hide_spam", "Hide Spam");
	}

}
function hideMediaComment(commentDivId) {
	// destroy comment panel
	// _elem(commentDivId).style.display="none";
	destroyElement(commentDivId);
}
function destroyElement(id) {
	var elem = _elem(id);
	if (elem != null) {
		// clearInnerHTML(elem);
		elem.innerHTML = "";
	}
}
function hidePostCommentForm() {
	destroyElement("postMediaCommentFrm");
	var elem = _elem("postMediaCommentFrm");
	elem.style.display = "none";
}
function submitMediaCommentForm(videoId, refCommentId) {
	var commentTxt = _elem("mediaCommentCommentTxt").value;
	if (commentTxt == null || commentTxt == '') {
		alert(getLocaleStr("comment_null_msg", "Please enter a comment"));
		return;
	}
	// make ajax call
	dojo.xhrGet( {
		url :'service?action=postComment&mediaId=' + videoId + '&comment='
				+ commentTxt + '&refCommentId=' + refCommentId,
		handleAs :"xml",
		load : function(data, evt) {
		}
	});

	alert(getLocaleStr("comment_submitted", "Comment was submited successfully"));
	destroyElement("postMediaCommentFrm");
}
function postMediaComment(videoId, refCommentId, parentDivId) {
	// destroy any opened comment form
	if (getCookie("CompId") == null) {
		signin();
		return;
	}

	destroyElement("postMediaCommentFrm");

	var newDiv = document.createElement("div");
	newDiv.id = "postMediaCommentFrm";
	newDiv.className = "postMediaCommentFrm";
	newDiv.innerHTML += '<div class="close" onclick="hidePostCommentForm();">&nbsp;</div>';
	newDiv.innerHTML += '<div align="center" style="padding:3px;width:298px"><textarea cols="40" rows="5" name="mediaCommentCommentTxt" id="mediaCommentCommentTxt" onfocus="if(this.value==\'Comment\')this.value=\'\';" onblur="if(this.value==\'\')this.value=\'' + getLocaleStr(
			"comment", "Comment") + '\';"></textarea>';
	newDiv.innerHTML += '<input onclick="submitMediaCommentForm(' + videoId
			+ ',\'' + refCommentId
			+ '\')" name="submitMediaComment" id="submitMediaComment" value="'
			+ getLocaleStr("submit", "Submit")
			+ '" class="submit" type="button"></div>';
	_elem(parentDivId).appendChild(newDiv);

}
function renderCommentHrd(videoId, refCommentId, commentDiv) {
	// note: the comment header for sub comments differs from the main header
	if (refCommentId == null || refCommentId == "") {
		var newDiv = document.createElement("div");
		newDiv.id = "CommentHrdDiv";
		newDiv.className = "mediaCommentHrdStyle";
		commentDiv.appendChild(newDiv);
		// comment title
		var commentTitleDiv = document.createElement("div");

		commentTitleDiv.className = "mediaCommentTitle";
		commentTitleDiv.innerHTML = getLocaleStr("comment", "Comment");
		newDiv.appendChild(commentTitleDiv);

		var commentCloseDiv = document.createElement("div");
		commentCloseDiv.className = "mediaCommentClose";
		commentCloseDiv.innerHTML = "<div class='close' onclick='hideMediaComment(\""
				+ commentDiv.id + "\");return false;'></div>";
		newDiv.appendChild(commentCloseDiv);

		var commentCtrlDiv = document.createElement("div");
		commentCtrlDiv.className = "mediaCommentHeaderCtl";

		commentCtrlDiv.innerHTML = "<a id='spamDisplay' href=# onclick='hideSpams();return false;'>"
				+ getLocaleStr("hide_spam", "Hide Spam")
				+ "</a>&nbsp;&nbsp;"
				+ "<a href=# onclick='postMediaComment("
				+ videoId
				+ ",\"\",\"ComPost"
				+ refCommentId
				+ "\");reportUserAction(\"comment_content_submitted::\","
				+ videoId
				+ ");return false;'>"
				+ getLocaleStr("post_comment", "Post Comment")
				+ "</a>&nbsp;&nbsp;";

		commentCloseDiv.appendChild(commentCtrlDiv);

		var dummyDiv = document.createElement("div");
		dummyDiv.style.clear = "both";
		newDiv.appendChild(dummyDiv);// this clears the floating divs

		var commentPageCtrlDiv = document.createElement("div");
		commentPageCtrlDiv.className = "mediaCommentPageNav";
		newDiv.appendChild(commentPageCtrlDiv);

		// vacant div for comment posting form
		var newCommentPostingDiv = document.createElement("div");
		newCommentPostingDiv.id = "ComPost";
		commentDiv.appendChild(newCommentPostingDiv);

	} else {
		// for subheaders

	}

}
function renderCommentSubHrd(cInfo, commentDiv) {
	var newDiv = document.createElement("div");
	newDiv.className = "mediaCommentSubHrdStyle";
	commentDiv.appendChild(newDiv);

	newDiv.innerHTML = "<img class='mediaCommentThumbnail' onclick='visitUserProfile("
			+ cInfo.getAttribute("comp_id")
			+ ");return false;' onmouseover=\"this.style.cursor='pointer'\" src='"
			+ cInfo.getAttribute("logo_link")
			+ "' style='width:27px;height:30px' alt=''>";
	newDiv.innerHTML += "<span style='float:left;text-align:left;'><small><a href=#  onclick='visitUserProfile("
			+ cInfo.getAttribute("comp_id")
			+ ");return false;'>"
			+ cInfo.getAttribute("name")
			+ "</a></small><br/>"
			// date added
			+ "<small>"
			+ cInfo.getAttribute("date")
			+ " "
			+ ago(cInfo.getAttribute("date")) + "</small><br/></span>";

	// spam
	newDiv.innerHTML += "<div style='padding:5px;float:right;'><a href=# onclick=\"reportCommentSpam("
			+ cInfo.getAttribute("video_id")
			+ ",'"
			+ cInfo.getAttribute("id")
			+ "');return false;\">"
			+ getLocaleStr("spam", "Spam")
			+ "</a>"
			// rank
			+ "&nbsp;&nbsp;<a href=# onclick=\"rankMediaComment("
			+ cInfo.getAttribute("video_id")
			+ ",'"
			+ cInfo.getAttribute("id")
			+ "',1);return false;\"><img src='images/push_up.png' alt='"
			+ getLocaleStr("comment_rank_up", "Put On Top")
			+ "'></a><a href=# onclick=\"rankMediaComment("
			+ cInfo.getAttribute("video_id")
			+ ",'"
			+ cInfo.getAttribute("id")
			+ "',-1);return false;\"><img src='images/push_down.png' alt='"
			+ getLocaleStr("comment_rank_down", "Push Down")
			+ "'></a>"
			// reply
			+ "&nbsp;&nbsp;<a href=# onclick=\"postMediaComment("
			+ cInfo.getAttribute("video_id")
			+ ","
			+ cInfo.getAttribute("id")
			+ ",'ComPost"
			+ cInfo.getAttribute("id")
			+ "');return false;\">"
			+ getLocaleStr("reply", "Reply") + "</a></div>";

}

function visitUserProfile(compId) {
	location.href = "profile.html?pageId=" + compId + "&ownerId=" + compId;
}
var commentDivsPreffix = "VidCom";

function renderComment(videoId, commentId, commentDivId) {
	var commentDiv = _elem(commentDivId);
	commentDiv.style.display = 'block';
	renderCommentHrd(videoId, commentId, commentDiv);
	var url = 'service?action=getMediaComments&mediaId=' + videoId;
	if (commentId != null && commentId != '') {
		url += '&commentId=' + commentId;
	}
	dojo.xhrGet( {
		url :url,
		load : function(data, evt) {
			var comment = data.getElementsByTagName("comment_data");

			var ul = document.createElement("ul");
			commentDiv.appendChild(ul);

			for ( var col = 0; col < comment.length; col++) {
				var cInfo = comment[col];

				var newCommentDiv = document.createElement("li");
				newCommentDiv.id = commentDivsPreffix
						+ cInfo.getAttribute("id");

				ul.appendChild(newCommentDiv);

				newCommentDiv.className = "mediaCommentBody";
				renderCommentSubHrd(cInfo, newCommentDiv);
				// --- comment content ---

				var newCommentContentDiv = document.createElement("div");
				newCommentContentDiv.id = commentDivsPreffix + "C"
						+ cInfo.getAttribute("id");
				newCommentContentDiv.innerHTML = cInfo.getAttribute("comment");
				newCommentContentDiv.className = "mediaCommentContentStyle";
				newCommentDiv.appendChild(newCommentContentDiv);
				// -----------------------

				// vacant div for comment posting form
				var newCommentPostingDiv = document.createElement("div");
				newCommentPostingDiv.id = "ComPost" + cInfo.getAttribute("id");
				newCommentPostingDiv.className = "mediaCommentPostCommentFrm";
				newCommentDiv.appendChild(newCommentPostingDiv);

				// render sub comment under for this comment
				var newSubCommentDiv = document.createElement("div");
				newSubCommentDiv.id = commentDivsPreffix + "S"
						+ cInfo.getAttribute("id");
				newCommentDiv.appendChild(newSubCommentDiv);

				// spam assasination tracking
				spamLevels.push(new setSpamLevel(newCommentDiv.id, cInfo
						.getAttribute("flag_count")));

				renderComment(videoId, cInfo.getAttribute("id"),
						newSubCommentDiv.id);
			}

		},
		handleAs :'xml'
	});

}
var MAX_FLAG_COUNT_FOR_A_SPAM = 1;
var spamLevels = [];
function setSpamLevel(id, value) {
	this.id = id;
	this.value = value;
}

function rankMediaComment(videoId, commentId, rankValue) {
	dojo.xhrGet( {
		url :'service?action=postComment&mediaId=' + videoId + '&rank='
				+ rankValue + '&commentId=' + commentId,
		error : function(data, evt) {
			signin();
		},
		load : function(data, evt) {
		},
		handleAs :'xml'
	});
	alert(getLocaleStr("comment_ranked_msg", "Comment ranking successful"));
}
function reportCommentSpam(videoId, commentId) {
	dojo.xhrGet( {
		url :'service?action=postComment&mediaId=' + videoId
				+ '&spam=true&commentId=' + commentId,
		error : function(data, evt) {
			signin();
		},
		load : function(data, evt) {
		},
		handleAs :'xml'
	});

	// hide Comment
	destroyElement(commentDivsPreffix + commentId);
}
var currentCommentDiv = null;
function showComments(videoId, commentDiv) {
	// hide all other videos for space

	//
	try {
		if (currentCommentDiv != null && currentCommentDiv != "") {
			var elem = _elem(currentCommentDiv);
			if (elem != null) {
				elem.innerHTML = "";
				elem.style.display = 'none';
			}
			// destroyElement(currentCommentDiv);
		}
		currentCommentDiv = commentDiv;
		renderComment(videoId, "", commentDiv);
	} catch (e) {
	}
}
// ----------------- end of video comment section-------------

// end of rendering

function download(videoId) {
	dojo
			.xhrPost( {
				url :'service?action=notification&notificationType=initSession&SelVideoId=' + videoId,
				load : function(data, evt) {
					location.href = "download.jsp";
				},
				handleAs :'xml'
			});

}

var dojoIsLoaded = false;
function dojoLoaded() {
	dojoIsLoaded = true;

	// init source combo
	try {
		initContSrc();// making sure content sources is initialised
		/*
		 * var sourceList= dojo.widget.createWidget( "dojo:Select", { dataUrl:
		 * "", name: "sourceList", value: "", widgetId: "sourceList" },
		 * dojo.byId("sourceList") ); //dojo.connect(sourceList, "_startSearch",
		 * "initContentSourceSelection");
		 */
		setTimeout("initContentSourceSelection()", 2000);// just a little
		// delay to allow
		// for ajax loading

	} catch (e) {
	}
	// end of combo init
	if (!isIE()) {
		if (poolingForStorage) {
			storeCollection(collection);
		}
	}

}
function initContentSourceSelection() {
	/*
	 * dojo.widget.getWidgetById('sourceList').dataProvider.setData(getContentSourceNameId());
	 */
	try {
		var s = getContentSourceNameId();
		var sourceList = _elem("sourceList");
		clearInnerHTML(sourceList);
		for (j = 0; j < s.length; j++) {
			var oOption = document.createElement("OPTION");
			oOption.text = s[j][0];
			oOption.value = s[j][1];
			sourceList.options.add(oOption);

		}
		sourceList.value = getCookie("ContentSource");
	} catch (e) {
	}
}
function favourite(contentId) {
	signin();
	dojo
			.xhrPost( {
				url :'service?action=updateFavouriteContent&operation=add&contentId=' + contentId,
				load : function(data, evt) {
					alert(getLocaleStr("favourite_added",
							"This content has been added to your favourites"));
				},
				handleAs :'json'
			});

}

function _elem(id) {
	return document.getElementById(id);
}
// dojo.addOnLoad(dojoLoaded);
// //end of AJAX/////

/**
 * SWFObject v1.5: Flash Player detection and embed -
 * http://blog.deconcept.com/swfobject/
 * 
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */
if (typeof deconcept == "undefined") {
	var deconcept = new Object();
}
if (typeof deconcept.util == "undefined") {
	deconcept.util = new Object();
}
if (typeof deconcept.SWFObjectUtil == "undefined") {
	deconcept.SWFObjectUtil = new Object();
}
deconcept.SWFObject = function(_1, id, w, h, _5, c, _7, _8, _9, _a) {
	if (!document.getElementById) {
		return;
	}
	this.DETECT_KEY = _a ? _a : "detectflash";
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if (_1) {
		this.setAttribute("swf", _1);
	}
	if (id) {
		this.setAttribute("id", id);
	}
	if (w) {
		this.setAttribute("width", w);
	}
	if (h) {
		this.setAttribute("height", h);
	}
	if (_5) {
		this.setAttribute("version", new deconcept.PlayerVersion(_5.toString()
				.split(".")));
	}
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if (!window.opera && document.all && this.installedVer.major > 7) {
		deconcept.SWFObject.doPrepUnload = true;
	}
	if (c) {
		this.addParam("bgcolor", c);
	}
	var q = _7 ? _7 : "high";
	this.addParam("quality", q);
	this.setAttribute("useExpressInstall", false);
	this.setAttribute("doExpressInstall", false);
	var _c = (_8) ? _8 : window.location;
	this.setAttribute("xiRedirectUrl", _c);
	this.setAttribute("redirectUrl", "");
	if (_9) {
		this.setAttribute("redirectUrl", _9);
	}
};
deconcept.SWFObject.prototype = {
	useExpressInstall : function(_d) {
		this.xiSWFPath = !_d ? "expressinstall.swf" : _d;
		this.setAttribute("useExpressInstall", true);
	},
	setAttribute : function(_e, _f) {
		this.attributes[_e] = _f;
	},
	getAttribute : function(_10) {
		return this.attributes[_10];
	},
	addParam : function(_11, _12) {
		this.params[_11] = _12;
	},
	getParams : function() {
		return this.params;
	},
	addVariable : function(_13, _14) {
		this.variables[_13] = _14;
	},
	getVariable : function(_15) {
		return this.variables[_15];
	},
	getVariables : function() {
		return this.variables;
	},
	getVariablePairs : function() {
		var _16 = new Array();
		var key;
		var _18 = this.getVariables();
		for (key in _18) {
			_16[_16.length] = key + "=" + _18[key];
		}
		return _16;
	},
	getSWFHTML : function() {
		var _19 = "";
		if (navigator.plugins && navigator.mimeTypes
				&& navigator.mimeTypes.length) {
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute("swf", this.xiSWFPath);
			}
			_19 = "<embed type=\"application/x-shockwave-flash\" src=\""
					+ this.getAttribute("swf") + "\" width=\""
					+ this.getAttribute("width") + "\" height=\""
					+ this.getAttribute("height") + "\" style=\""
					+ this.getAttribute("style") + "\"";
			_19 += " id=\"" + this.getAttribute("id") + "\" name=\""
					+ this.getAttribute("id") + "\" ";
			var _1a = this.getParams();
			for ( var key in _1a) {
				_19 += [ key ] + "=\"" + _1a[key] + "\" ";
			}
			var _1c = this.getVariablePairs().join("&");
			if (_1c.length > 0) {
				_19 += "flashvars=\"" + _1c + "\"";
			}
			_19 += "/>";
		} else {
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute("swf", this.xiSWFPath);
			}
			_19 = "<object id=\""
					+ this.getAttribute("id")
					+ "\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""
					+ this.getAttribute("width") + "\" height=\""
					+ this.getAttribute("height") + "\" style=\""
					+ this.getAttribute("style") + "\">";
			_19 += "<param name=\"movie\" value=\"" + this.getAttribute("swf")
					+ "\" />";
			var _1d = this.getParams();
			for ( var key in _1d) {
				_19 += "<param name=\"" + key + "\" value=\"" + _1d[key]
						+ "\" />";
			}
			var _1f = this.getVariablePairs().join("&");
			if (_1f.length > 0) {
				_19 += "<param name=\"flashvars\" value=\"" + _1f + "\" />";
			}
			_19 += "</object>";
		}
		return _19;
	},
	write : function(_20) {
		if (this.getAttribute("useExpressInstall")) {
			var _21 = new deconcept.PlayerVersion( [ 6, 0, 65 ]);
			if (this.installedVer.versionIsValid(_21)
					&& !this.installedVer.versionIsValid(this
							.getAttribute("version"))) {
				this.setAttribute("doExpressInstall", true);
				this.addVariable("MMredirectURL", escape(this
						.getAttribute("xiRedirectUrl")));
				document.title = document.title.slice(0, 47)
						+ " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if (this.skipDetect
				|| this.getAttribute("doExpressInstall")
				|| this.installedVer.versionIsValid(this
						.getAttribute("version"))) {
			var n = (typeof _20 == "string") ? _elem(_20) : _20;
			n.innerHTML = this.getSWFHTML();
			return true;
		} else {
			if (this.getAttribute("redirectUrl") != "") {
				document.location.replace(this.getAttribute("redirectUrl"));
			}
		}
		return false;
	}
};
deconcept.SWFObjectUtil.getPlayerVersion = function() {
	var _23 = new deconcept.PlayerVersion( [ 0, 0, 0 ]);
	if (navigator.plugins && navigator.mimeTypes.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if (x && x.description) {
			_23 = new deconcept.PlayerVersion(x.description.replace(
					/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".")
					.split("."));
		}
	} else {
		if (navigator.userAgent
				&& navigator.userAgent.indexOf("Windows CE") >= 0) {
			var axo = 1;
			var _26 = 3;
			while (axo) {
				try {
					_26++;
					axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."
							+ _26);
					_23 = new deconcept.PlayerVersion( [ _26, 0, 0 ]);
				} catch (e) {
					axo = null;
				}
			}
		} else {
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
			} catch (e) {
				try {
					var axo = new ActiveXObject(
							"ShockwaveFlash.ShockwaveFlash.6");
					_23 = new deconcept.PlayerVersion( [ 6, 0, 21 ]);
					axo.AllowScriptAccess = "always";
				} catch (e) {
					if (_23.major == 6) {
						return _23;
					}
				}
				try {
					axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				} catch (e) {
				}
			}
			if (axo != null) {
				_23 = new deconcept.PlayerVersion(axo.GetVariable("$version")
						.split(" ")[1].split(","));
			}
		}
	}
	return _23;
};
deconcept.PlayerVersion = function(_29) {
	this.major = _29[0] != null ? parseInt(_29[0]) : 0;
	this.minor = _29[1] != null ? parseInt(_29[1]) : 0;
	this.rev = _29[2] != null ? parseInt(_29[2]) : 0;
};
deconcept.PlayerVersion.prototype.versionIsValid = function(fv) {
	if (this.major < fv.major) {
		return false;
	}
	if (this.major > fv.major) {
		return true;
	}
	if (this.minor < fv.minor) {
		return false;
	}
	if (this.minor > fv.minor) {
		return true;
	}
	if (this.rev < fv.rev) {
		return false;
	}
	return true;
};
deconcept.util = {
	getRequestParameter : function(_2b) {
		var q = document.location.search || document.location.hash;
		if (_2b == null) {
			return q;
		}
		if (q) {
			var _2d = q.substring(1).split("&");
			for ( var i = 0; i < _2d.length; i++) {
				if (_2d[i].substring(0, _2d[i].indexOf("=")) == _2b) {
					return _2d[i].substring((_2d[i].indexOf("=") + 1));
				}
			}
		}
		return "";
	}
};
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var _2f = document.getElementsByTagName("OBJECT");
	for ( var i = _2f.length - 1; i >= 0; i--) {
		_2f[i].style.display = "none";
		for ( var x in _2f[i]) {
			if (typeof _2f[i][x] == "function") {
				_2f[i][x] = function() {
				};
			}
		}
	}
};
if (deconcept.SWFObject.doPrepUnload) {
	if (!deconcept.unloadSet) {
		deconcept.SWFObjectUtil.prepUnload = function() {
			__flash_unloadHandler = function() {
			};
			__flash_savedUnloadHandler = function() {
			};
			window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
		};
		window
				.attachEvent("onbeforeunload",
						deconcept.SWFObjectUtil.prepUnload);
		deconcept.unloadSet = true;
	}
}
if (!document.getElementById && document.all) {
	document.getElementById = function(id) {
		return document.all[id];
	};
}
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject;
var SWFObject = deconcept.SWFObject;
