/**
 *
 * OMS Widget : Homepage
 * Version: 2009.03.25.01.TS06
 * Bugfixes by Tony Simbine <t.simbine (at) oms.eu>
 *
**/

if(typeof bc_id != 'array') {
	var bc_id = new Array();
}

function bc_widget_homepage(arg) {
	bc_status = 1;
	var id = bc_id.length;
	bc_id.push(new bc_make_widget_homepage(arg, id));
	bc_id[id].generate();
	bc_id[id].layout();
	bc_id[id].retrieve(1);
}

function bc_make_widget_homepage(arg, id) {
	this.id = id;
	this.postfix = arg.postfix || '';
	this.token = arg.token || (this.id > 0? bc_id[0].token: 'myReadToken.');
	this.url = arg.url || (this.id > 0? bc_id[this.id - 1].url: '/videocenter-Url');
	this.dir = arg.dir || 'bcw_homepage';
	this.width = arg.width || 500;
	this.playerId1 = (!arg.playerIds || arg.playerIds[0] == 0) ? null : arg.playerIds[0];
	this.playerId2 = (!arg.playerIds || arg.playerIds[1] == 0) ? null : arg.playerIds[1];
	this.playlistId1 = (!arg.playlistIds || arg.playlistIds[0] == 0) ? null : arg.playlistIds[0];
	this.playlistId2 = (!arg.playlistIds || arg.playlistIds[1] == 0) ? null : arg.playlistIds[1];
	this.xmlUrl = arg.xml || false;
	this.xml = '';
	this.httpRequest = null;
	this.referName = 'homepage';
	this.sliding = false;
	this.page = 0;
	this.currentTab = 1;
	this.scriptCount = 1;
	this.videoCount1 = null;
	this.videoCount2 = null;
	this.pageCount1 = null;
	this.pageCount2 = null;
	this.test = null;
	this.ie = (document.all) ? true : false;
	this.TStab = new Array(null, null);
	if (arg.TsTabs)	{
		if (arg.TsTabs[0] != null && arg.TsTabs[0].length > 1)
			this.TStab[0] = arg.TsTabs[0];
		if (arg.TsTabs[1] != null && arg.TsTabs[1].length > 1)
			this.TStab[1] = arg.TsTabs[1];
	}
	this.TSlink = new Array(null, null);
	this.TStarget = this.TStargets = null;
	this.maximum = 15;
	this.tsCol = 3;
	if (arg.TSopt)	{
		if (arg.TSopt['target'] && arg.TSopt['target'].length > 2)	{
			this.TStarget = ' target="' + arg.TSopt.target + '"';
			this.TStargets = arg.TSopt.target;
		}
		if (arg.TSopt['maximum'] && arg.TSopt['maximum'] > 0)
			this.maximum = arg.TSopt['maximum'];
		if (arg.TSopt['tsCol'] && arg.TSopt['tsCol'] > 1)
			this.tsCol = arg.TSopt['tsCol'];
	}
	this.url += ((this.url.indexOf('?') > -1)? '&': '?');
	
	this.generate = function() {
		var code;
		if (this.id < 1)	{
			code = document.createElement("script");
			code.setAttribute('src', 'http://admin.brightcove.com/js/BrightcoveExperiences.js');
			code.setAttribute('charset', 'UTF-8');
			code.setAttribute('type', 'text/javascript');
			document.getElementsByTagName('head')[0].appendChild(code);
			code = document.createElement("script");
			code.setAttribute('src', 'http://admin.brightcove.com/js/APIModules_all.js');
			code.setAttribute('charset', 'UTF-8');
			code.setAttribute('type', 'text/javascript');
			document.getElementsByTagName('head')[0].appendChild(code);
		}
		code = document.createElement("link");
		code.setAttribute('href', this.dir + this.postfix + '/brightcove.css');
		code.setAttribute('rel', 'stylesheet');
		code.setAttribute('type', 'text/css');
		document.getElementsByTagName('head')[0].appendChild(code);
		
		document.write('<style type="text/css">');
		
		if(this.ie) {
			document.write('div.bc_widget_homepage' + this.postfix + ' div.bc_outer' + this.postfix + ' div.bc_inner' + this.postfix + ' div.bc_video' + this.postfix + ' div.bc_thumb' + this.postfix + ' div.bc_overlay' + this.postfix + ' { background-image: none; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + this.dir + this.postfix + '/bc_overlay.png",sizingMethod="scale"); }');
			document.write('div.bc_widget_homepage'+ this.postfix + ' div.bc_header'+ this.postfix + ' { height: 31px; overflow: hidden; }');
			document.write('div.bc_widget_homepage'+ this.postfix + ' div.bc_pagination'+ this.postfix + ' ul li { width: 16px; }');
			document.write('div.bc_widget_homepage'+ this.postfix + ' img.bc_arrow_right'+ this.postfix + ' { margin-left: -2px; }');
			document.write('div.bc_widget_homepage'+ this.postfix + ' div.bc_header'+ this.postfix + ' div.bc_link'+ this.postfix + ' { margin-right: 8px; }');
			document.write('div.bc_widget_homepage'+ this.postfix + ' div.bc_outer'+ this.postfix + ' div.bc_inner'+ this.postfix + ' div.bc_video'+ this.postfix + ' div.bc_thumb'+ this.postfix + ' { width: 128px; height: 98px; }');
		} else {
			document.write('div.bc_widget_homepage' + this.postfix + ' div.bc_outer' + this.postfix + ' div.bc_inner' + this.postfix + ' div.bc_video' + this.postfix + ' div.bc_thumb' + this.postfix + ' div.bc_overlay' + this.postfix + ' { background: transparent url("' + this.dir + this.postfix + '/bc_overlay.png"); }');
		}
		
		document.write('</style>');
		document.write('<div id="' + this.id + 'BCWH_widget" class="bc_widget_homepage' + this.postfix + '">');
		document.write('<div id="' + this.id + 'BCWH_header" class="bc_header' + this.postfix + '"><div id="' + this.id + 'BCWH_tab1" class="bc_tab_left' + this.postfix + ' bc_tab_active' + this.postfix + '" onclick="bc_id[' + this.id + '].view(1)"></div><div id="' + this.id + 'BCWH_tab2" class="bc_tab_right' + this.postfix + '" onclick="bc_id[' + this.id + '].view(2)"></div><div class="bc_link' + this.postfix + '"><a href="' + this.url + 'refer=' + this.referName + '" id="' + this.id + 'BC_TS_All"' + (this.TStarget? this.TStarget: '') + '>Alle Videos &raquo;</a></div></div>');
		document.write('<div class="bc_pagination' + this.postfix + '"><ul id="' + this.id + 'BCWH_paginationList"></ul></div>');
		document.write('<img src="' + this.dir + this.postfix + '/arrow_left.png" id="' + this.id + 'BCWH_arrowLeft" class="bc_arrow_left' + this.postfix + ' bc_arrow_disabled' + this.postfix + '" onclick="bc_id[' + this.id + '].slide(0)" onmouseover="bc_id[' + this.id + '].arrowHover(0);" onmouseout="bc_id[' + this.id + '].arrowOff(0);" /><img src="' + this.dir + this.postfix + '/arrow_right.png" id="' + this.id + 'BCWH_arrowRight" class="bc_arrow_right' + this.postfix + ' bc_arrow_disabled' + this.postfix + '" onclick="bc_id[' + this.id + '].slide(1)" onmouseover="bc_id[' + this.id + '].arrowHover(1);" onmouseout="bc_id[' + this.id + '].arrowOff(1);" />');
		document.write('<div id="' + this.id + 'BCWH_outer1" class="bc_outer' + this.postfix + '"><div id="' + this.id + 'BCWH_inner1" class="bc_inner' + this.postfix + '"></div></div>');
		document.write('<div id="' + this.id + 'BCWH_outer2" class="bc_outer' + this.postfix + '" style="display: none;"><div id="' + this.id + 'BCWH_inner2" class="bc_inner' + this.postfix + '"></div></div>');
		document.write('</div>');
	};
	
	this.retrieve = function(pCount) {
		if(pCount == 1) {
			if(this.playlistId1) {
				this.auto(1);
			} else {
				this.manual(1);
			}
		} else {
			if(this.playlistId2) {
				this.auto(2);
			} else {
				this.manual(2);
			}
		}
	}
	
	this.auto = function(pCount) {
		if(pCount == 1) {
			var playlistId = this.playlistId1;
		} else {
			var playlistId = this.playlistId2;
		}
		
		var code = document.createElement('script');
		code.setAttribute('src', 'http://api.brightcove.com/services/library?command=find_playlist_by_id&playlist_id=' + playlistId + '&token=' + this.token + '&callback=bc_id[' + this.id + '].autoReturn');
		code.setAttribute('charset', 'UTF-8');
		code.setAttribute('type', 'text/javascript');
		document.getElementsByTagName('head')[0].appendChild(code);
	}
	
	this.autoReturn = function(pData) {		
		document.getElementById(this.id + 'BCWH_tab' + this.scriptCount).innerHTML = this.TStab[this.scriptCount - 1] || pData.name;
		var videos = pData['videos'];

		var maximum = this.maximum;
		var tsCol = this.tsCol;
		
		if(videos.length < maximum) {
			maximum = videos.length;
		}
		
		if(this.scriptCount == 1) {
			this.videoCount1 = videos.length;
			this.pageCount1 = Math.ceil(maximum / tsCol);
			var playerId = this.playerId1;
			var lineupId = this.playlistId1;
			
			for(var i = 0; i < this.pageCount1; i++) {
				var code = document.createElement('li');
				
				if(i == 0) {
					code.className = 'selected' + this.postfix;
				}
				
				document.getElementById(this.id + 'BCWH_paginationList').appendChild(code);
			}
		} else {
			this.videoCount2 = videos.length;
			this.pageCount2 = Math.ceil(maximum / tsCol);
			var playerId = this.playerId2;
			var lineupId = this.playlistId2;
		}
		
		for(var i = 0; i < maximum; i++) {
			var minutes = Math.floor((videos[i]['length'] / 1000) / 60);
			var seconds = Math.round((((videos[i]['length'] / 1000) % 60) * 60) / 60);
			
			if(seconds < 10) {
				seconds = '0' + seconds;
			}
			
			var timeString = minutes + ':' + seconds;
			
			var date = new Date();
			date.setTime(videos[i]['publishedDate']);
			var dateString = date.getDate() + '.' + (date.getMonth() + 1) + '.' + date.getFullYear();
			
			if(videos[i]['thumbnailURL']) {
				var image = '<img src="' + videos[i]['thumbnailURL'] + '" width="120" height="90" />';
			} else {
				var image = '';
			}
			

			var code = document.createElement('div');
			code.className = 'bc_video' + this.postfix;
			code.innerHTML = '<div class="bc_thumb' + this.postfix + '" onmouseover="bc_id[' + this.id + '].over(this,1)" onmouseout="bc_id[' + this.id + '].over(this,0)" onclick="window.location=\'' + this.url + 'bcpid=' + playerId + '&bclid=' + lineupId + '&bctid=' + videos[i].id + '&refer=' + this.referName + '\'">' + image + '<div class="bc_overlay' + this.postfix + '" style="visibility: hidden;"></div></div><div class="title' + this.postfix + '">' + videos[i]['name'] + '</div><div class="time' + this.postfix + '">' + timeString + ' | ' + dateString + '</div>';
			document.getElementById(this.id + 'BCWH_inner' + this.scriptCount).appendChild(code);
		}
		this.TSlink[this.scriptCount - 1] = this.url + 'refer=' + this.referName;
		if (playerId && lineupId)
			this.TSlink[this.scriptCount - 1] += '&bcpid=' + playerId + '&bclid=' + lineupId;
		if (this.scriptCount == 1)
			document.getElementById(this.id + 'BC_TS_All').href = this.TSlink[this.scriptCount - 1];
		
		if(this.scriptCount == 1) {
			this.arrows();
			this.scriptCount++;
			this.retrieve(2);
		} else {
			this.layout();
		}
	}
	
	this.over = function(pEl, pState) {
		if(pState == 1) {
			pEl.childNodes[1].style.visibility = 'visible';
			pEl.className = 'bc_thumb bc_thumb_over';
		} else {
			pEl.childNodes[1].style.visibility = 'hidden';
			pEl.className = 'bc_thumb';
		}
	}
	
	this.manual = function(pCount) {		
		if(window.XMLHttpRequest) {
			this.httpRequest = new XMLHttpRequest();
			if(this.httpRequest.overrideMimeType) {
				this.httpRequest.overrideMimeType('text/xml');
			}
		} else if(window.ActiveXObject) {
			try {
				this.httpRequest = new ActiveXObject('Msxml2.XMLHTTP');
			}
			catch (e) {
				try {
					this.httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
				}
			catch (e) {}
			}
		}
		
		if(!this.httpRequest) {
			return false;
		}
		
		var thispointer = this;
		
		this.httpRequest.onreadystatechange = function() {
			thispointer.handler();
		};
	
		this.httpRequest.open('GET', this.xmlUrl, true);
		this.httpRequest.send('');
	}
	
	this.handler = function() {
		var tabs, tab, videos;
		var videoIds = '';
		
		if(this.httpRequest.readyState == 4) {
			if(this.httpRequest.status == 200) {
				this.xml = this.httpRequest.responseXML;
				tabs = this.xml.getElementsByTagName('lineup');
				
				for(var i = 0; i < tabs.length; i++) {
					var tabId = tabs[i].getAttribute('tab');
					
					if(tabId == this.scriptCount) {
						tab = tabs[i];
					}
				}
				
				document.getElementById(this.id + 'BCWH_tab' + this.scriptCount).innerHTML = this.TStab[this.scriptCount - 1] || tab.getAttribute('name');
				videos = tab.getElementsByTagName('video');
				
				for(var i = 0; i < videos.length; i++) {
					var video = videos[i];
					var title = video.getElementsByTagName('title_id')[0].childNodes[0].nodeValue;
					
					videoIds += title;
					
					if(i + 1 < videos.length) {
						videoIds += ',';
					}
				}
				
				var code = document.createElement('script');
				code.setAttribute('src', 'http://api.brightcove.com/services/library?command=find_videos_by_ids&token=' + this.token + '&video_ids=' + videoIds + '&fields=id,name,thumbnailURL,length,publishedDate&callback=bc_id[' + this.id + '].manualReturn');
				code.setAttribute('charset', 'UTF-8');
				code.setAttribute('type', 'text/javascript');
				document.getElementsByTagName('head')[0].appendChild(code);
			}
		}
	}
	
	this.manualReturn = function(pData) {
		var videos = pData['items'];
		var maximum = this.maximum;
		var tsCol = this.tsCol;
		var tab;
		var tabs = this.xml.getElementsByTagName('lineup');
		
		for(var q = 0; q < tabs.length; q++) {
			var tabId = tabs[q].getAttribute('tab');
			
			if(tabId == this.scriptCount) {
				tab = tabs[q];
			}
		}
		var videosXml = tab.getElementsByTagName('video');
		for (var i = 0; i < videos.length; i++) {
			if (videos[i] == null)	{
				videos.splice(i, 1);
				var removednode = videosXml[i];
				removednode.parentNode.removeChild(removednode);
				i--;
			}
			if (i >= maximum)
				break;
		}
		
		if(videos.length < maximum) {
			maximum = videos.length;
		}
		
		if(this.scriptCount == 1) {
			this.videoCount1 = videos.length;
			this.pageCount1 = Math.ceil(maximum / tsCol);
			
			for(var i = 0; i < this.pageCount1; i++) {
				var code = document.createElement('li');
				
				if(i == 0) {
					code.className = 'selected' + this.postfix;
				}
				
				document.getElementById(this.id + 'BCWH_paginationList').appendChild(code);
			}
		} else {
			this.videoCount2 = videos.length;
			this.pageCount2 = Math.ceil(maximum / tsCol);
		}
		
		var _playerId, __playerId, _playlistId, __playlistId;
		for(var i = 0; i < maximum; i++) {
				var minutes = Math.floor((videos[i]['length'] / 1000) / 60);
				var seconds = Math.round((((videos[i]['length'] / 1000) % 60) * 60) / 60);
				
				if(seconds < 10) {
					seconds = '0' + seconds;
				}
				
				var timeString = minutes + ':' + seconds;
				
				var date = new Date();
				date.setTime(videos[i]['publishedDate']);
				var dateString = date.getDate() + '.' + (date.getMonth() + 1) + '.' + date.getFullYear();
				
				if(videos[i]['thumbnailURL']) {
					var image = '<img src="' + videos[i]['thumbnailURL'] + '" width="120" height="90" />';
				} else {
					var image = '';
				}
	
				var lineupId = videosXml[i].getElementsByTagName('lineup_id')[0].childNodes[0].nodeValue;
				var playerId = videosXml[i].getElementsByTagName('player_id')[0].childNodes[0].nodeValue;
				if (i == 0)	{
					_playerId = playerId;
					__playerId = _playerId;
					_playlistId = lineupId;
					__playlistId = _playlistId;
				}
				if (_playerId != playerId && __playerId == _playerId)
					__playerId = playerId;
				if (_playlistId != lineupId && __playlistId == _playlistId)
					__playlistId = lineupId;
	
				var code = document.createElement('div');
				code.className = 'bc_video' + this.postfix;
				code.innerHTML = '<div class="bc_thumb' + this.postfix + '" onmouseover="bc_id[' + this.id + '].over(this,1)" onmouseout="bc_id[' + this.id + '].over(this,0)"  onclick="window.location=\'' + this.url + 'bcpid=' + playerId + '&bclid=' + lineupId + '&bctid=' + videos[i].id + '&refer=' + this.referName + '\'">' + image + '<div class="bc_overlay' + this.postfix + '" style="visibility: hidden;"></div></div><div class="title' + this.postfix + '">' + videos[i]['name'] + '</div><div class="time' + this.postfix + '">' + timeString + ' | ' + dateString + '</div>';
				document.getElementById(this.id + 'BCWH_inner' + this.scriptCount).appendChild(code);
		}
		this.TSlink[this.scriptCount - 1] = this.url + 'refer=' + this.referName;
		if (_playerId && _playlistId && __playerId == _playerId && __playlistId == _playlistId)
			this.TSlink[this.scriptCount - 1] += '&bcpid=' + _playerId + '&bclid=' + __playlistId;

		if(this.scriptCount == 1) {
			document.getElementById(this.id + 'BC_TS_All').href = this.TSlink[this.scriptCount - 1];
			this.arrows();
			this.scriptCount++;
			this.retrieve(2);
		} else {
			this.layout();
		}
	}
	
	this.view = function(pId) {
		if(pId == 1) {
			var active = 'bc_tab_left' + this.postfix;
			var inactive = 'bc_tab_right' + this.postfix;
			var pageCount = this.pageCount1;
		} else {
			var active = 'bc_tab_right' + this.postfix;
			var inactive = 'bc_tab_left' + this.postfix;
			var pageCount = this.pageCount2;
		}
		
		document.getElementById(this.id + 'BCWH_paginationList').innerHTML = '';
		document.getElementById(this.id + 'BCWH_outer' + this.currentTab).style.display = 'none';
		document.getElementById(this.id + 'BCWH_inner' + this.currentTab).style.left = '0px';
		document.getElementById(this.id + 'BCWH_tab' + this.currentTab).className = inactive;
		document.getElementById(this.id + 'BC_TS_All').href = this.TSlink[pId - 1];
		
		this.currentTab = pId;
		this.page = 0;
		this.arrows();
		
		for(var i = 0; i < pageCount; i++) {
			var code = document.createElement('li');
			
			if(i == 0) {
				code.className = 'selected' + this.postfix;
			}

			document.getElementById(this.id + 'BCWH_paginationList').appendChild(code);
		}
		
		var offset = document.getElementById(this.id + 'BCWH_paginationList').offsetWidth;
		var pEl = document.getElementById(this.id + 'BCWH_paginationList').parentNode;
		pEl.style.left = (this.width / 2) - (offset / 2) + 2 + 'px';
				
		document.getElementById(this.id + 'BCWH_outer' + this.currentTab).style.display = 'block';
		document.getElementById(this.id + 'BCWH_inner' + this.currentTab).style.left = '0px';
		document.getElementById(this.id + 'BCWH_tab' + this.currentTab).className = active + ' bc_tab_active' + this.postfix;
	}
	
	this.arrows = function() {
		if(this.currentTab == 1) {
			var pageCount = this.pageCount1;
		} else {
			var pageCount = this.pageCount2;
		}
		
		if(this.page > 0) {
			document.getElementById(this.id + 'BCWH_arrowLeft').className = 'bc_arrow_left' + this.postfix;
		} else {
			document.getElementById(this.id + 'BCWH_arrowLeft').className = 'bc_arrow_left' + this.postfix + ' bc_arrow_disabled' + this.postfix;
		}
		
		if(this.page + 1 < pageCount) {
			document.getElementById(this.id + 'BCWH_arrowRight').className = 'bc_arrow_right' + this.postfix;
		} else {
			document.getElementById(this.id + 'BCWH_arrowRight').className = 'bc_arrow_right' + this.postfix + ' bc_arrow_disabled' + this.postfix;
		}
	}
	
	this.arrowHover = function(pSide) {
		var arrow;
		
		if(pSide == 0) {
			arrow = document.getElementById(this.id + 'BCWH_arrowLeft');
			arrow.src = this.dir + this.postfix + '/arrow_left_hover.png';
		} else {
			arrow = document.getElementById(this.id + 'BCWH_arrowRight');
			arrow.src = this.dir + this.postfix + '/arrow_right_hover.png';
		}
	}
	
	this.arrowOff = function(pSide) {
		var arrow;
		
		if(pSide == 0) {
			arrow = document.getElementById(this.id + 'BCWH_arrowLeft');
			arrow.src = this.dir + this.postfix + '/arrow_left.png';
		} else {
			arrow = document.getElementById(this.id + 'BCWH_arrowRight');
			arrow.src = this.dir + this.postfix + '/arrow_right.png';
		}
	}
	
	this.layout = function() {
		var delta = 227;
		if(this.ie) {
			document.getElementById(this.id + 'BCWH_widget').style.width = (this.width + 1) + 'px';
			document.getElementById(this.id + 'BCWH_header').style.width = (this.width - 2) + 'px';
			document.getElementById(this.id + 'BCWH_outer1').style.left = ((this.width / 2) - delta - 1) + 'px';
			document.getElementById(this.id + 'BCWH_outer2').style.left = ((this.width / 2) - delta - 1) + 'px';
			document.getElementById(this.id + 'BCWH_arrowRight').style.left = (this.width - 21) + 'px';
			document.getElementById(this.id + 'BCWH_arrowLeft').style.left = '4px';
		} else {
			document.getElementById(this.id + 'BCWH_widget').style.width = (this.width - 2) + 'px';
			document.getElementById(this.id + 'BCWH_header').style.width = (this.width - 2) + 'px';
			document.getElementById(this.id + 'BCWH_outer1').style.left = ((this.width / 2) - delta) + 'px';
			document.getElementById(this.id + 'BCWH_outer2').style.left = ((this.width / 2) - delta) + 'px';
			document.getElementById(this.id + 'BCWH_arrowRight').style.left = (this.width - 26) + 'px';
		}
		
		var offset = document.getElementById(this.id + 'BCWH_paginationList').offsetWidth;
		var pEl = document.getElementById(this.id + 'BCWH_paginationList').parentNode;
		pEl.style.left = (this.width / 2) - (offset / 2) + 2 + 'px';
	}

	this.getNum = function(pNum) {
		if(pNum) {
			if(pNum.indexOf('px') > -1) {
				return parseInt(pNum.substring(0, pNum.indexOf('px')));
			} else {
				return parseInt(pNum);
			}
		} else {
			return 0;
		}
	}
	
	this.slide = function(pDir) {
		if(!this.sliding) {
			if(this.currentTab == 1) {
				var pageCount = this.pageCount1;
				var el = document.getElementById(this.id + 'BCWH_inner1');
			} else {
				var pageCount = this.pageCount2;
				var el = document.getElementById(this.id + 'BCWH_inner2');
			}
			var distance = -453;
			if (this.ie)
				distance -= 6;
			if(pDir == 0) {
				if(this.page > 0) {
					this.page--;
					this.sliding = true;
					this.prepSlide(el, (this.page * distance));
				}
			} else {
				if(this.page + 1 < pageCount) {
					this.page++;
					this.sliding = true;
					this.prepSlide(el, (this.page * distance));
				}
			}
			
			this.arrows();
		}
	}

	this.prepSlide = function(pEl, pEnd) {
		var moveStart = this.getNum(pEl.style['left']);
		var amountToMove = pEnd - moveStart;
		var timeStart = new Date().getTime();
		var timeEnd = timeStart + 1000;
		
		this.doSlide(this.id, pEl, 'left', amountToMove, moveStart, 1000, timeEnd);
	}
	
	this.doSlide = function(id, pEl, pType, pDistance, pStart, pTimeTotal, pTimeEnd) {
		var currentTime = new Date().getTime();
		var timeRemaining = Math.max(0, pTimeEnd - currentTime);
		var currentMove = parseInt(pDistance - (Math.pow(timeRemaining, 3) / Math.pow(pTimeTotal, 3)) * pDistance);
		pEl.style[pType] = (pStart + currentMove) + 'px';
		
		if(timeRemaining > 0) {
		  setTimeout(function () { bc_id[id].doSlide(id, pEl, pType, pDistance, pStart, pTimeTotal, pTimeEnd); }, 10);
		} else {
			var parent = document.getElementById(this.id + 'BCWH_paginationList');
			var children = parent.childNodes;
			
			for(var i = 0; i < children.length; i++) {
				if(i != this.page) {
					children[i].className = '';
				} else {
					children[i].className = 'selected' + this.postfix;
				}
			}
			
			this.sliding = false;
		}	
	}
}
