if (!Function.prototype.bindAsEventListener) {
	Function.prototype.bindAsEventListener = function() {
		var __method = this, args = $A(arguments), object = args.shift();
		return function(event) {
			return __method.apply(object, [event || window.event].concat(args));
		}
	}
}
var $A = Array.from = function(iterable) {
	if (!iterable) return [];
	if (iterable.toArray) {
		return iterable.toArray();
	} else {
		var results = [];
		for (var i = 0; i < iterable.length; i++)
			results.push(iterable[i]);
		return results;
	}
}

if (!Math.customRound) {
	Math.customRound = function (number, digits) {
		if (arguments.length == 1) var digits = 2;
		var d = Math.pow(10, digits);
		return parseInt(number * d) / d;
	}
}
if (typeof(IDTVLBP) == "undefined") {
	IDTVLBP = function () {this.initialize.apply(this, arguments);};
	IDTVLBP.prototype = {
		frame: null,
		initialize: function (ds) {
			this.ds = ds;
			this.element = document.getElementById('IDTVP_' + this.ds.id);
			if (!this.element) { alert ('The iDesktop.tv video wall is not not embedded properly!'); return;}
				if (!this.element && document.getElementsByClassName)
				try {
					this.element = document.getElementsByClassName ('idtv_dbaa167b87')[0];
				} catch(e) {}
			this.element.innerHTML = '<div class="idtv_' + this.ds.id + '"><div class="idtv_tb"></div><div class="idtv_inres"></div><div class="idtv_bb"></div></div>';
			this.elementout = this.element.getElementsByTagName('div')[0];
			this.elementin = this.element.getElementsByTagName('div')[2];
			this.results = new Array();
			if (this.ds.data.error) {
				this.elementin.innerHTML = '<div style="text-align:center">' + this.ds.data.error + '</div>';
			} else {
				if (this.ds.only_public) { // go trough ds.data.results and remove all private videos
					var newdata = new Array();
					for (var i = 0; i < this.ds.data.results.length; i ++)
						if (!this.ds.data.results[i].isprivate)
							newdata.push(this.ds.data.results[i]);
					this.ds.data.results = newdata;
				}
				var jsonArr = this.ds.data.results;
				this.page = 0; this.resc = jsonArr.length;
				this.maxpage = Math.ceil(this.resc/this.ds.pp) ;
				for (var i = 0, n = this.resc; i < n; i ++) {
					if (this.ds.only_public && jsonArr[i].isprivate) continue;
					var nr = document.createElement('div');
					nr.className = 'idtv_res';
					if (i % 2) nr.className += ' alt';
					jsonArr[i].title_esc = (jsonArr[i].title ? jsonArr[i].title.replace(/"/g, "&quot;") : '');// "
					var title = jsonArr[i].title_esc + (this.ds.thumb_show_length && jsonArr[i].length_seconds?' (' + jsonArr[i].length_seconds + ')':'');
					var t = '<img src="' + jsonArr[i].thumbnail_url + '" alt="' + jsonArr[i].title_esc + '" title="' + title + '" />';
					if (this.ds.thumb_show_title || this.ds.thumb_show_author || this.ds.thumb_show_length || this.ds.thumb_show_rating || this.ds.thumb_show_description) {
						var at = '';
						if (this.ds.thumb_show_title) {
							//at = '<a href="http://www.idesktop.tv/?watch=' + jsonArr[i].id + '" title="' + jsonArr[i].title + '" target="_blank">' + jsonArr[i].title + "</a>";
							at = '<span class="t">' + (jsonArr[i].title ? jsonArr[i].title : '') + "</span>";
						}
						if (this.ds.thumb_show_author) {
							at += '<span class="ah">' + (this.ds.thumb_show_labels?'<span class="lb">Author: </span>':'') + (jsonArr[i].author ? jsonArr[i].author : '') + '</span>';
						}
						if (this.ds.thumb_show_length || this.ds.thumb_show_views) {
							at += '<span class="lv">';
							if (this.ds.thumb_show_length) at += (this.ds.thumb_show_labels?'<span class="lb">Length: </span>':'') + (jsonArr[i].length_seconds ? jsonArr[i].length_seconds : '');
							if (this.ds.thumb_show_length && this.ds.thumb_show_views) at += ' | ';
							if (this.ds.thumb_show_views) at += (this.ds.thumb_show_labels?'<span class="lb">Views: </span>':'') + (jsonArr[i].view_count ? this.formatCommasInt(jsonArr[i].view_count) : '');
							at += '</span>';
						}
						if (this.ds.thumb_show_rating)
							at += '<span class="r">' + (this.ds.thumb_show_labels?'<span class="lb">Rating: </span>':'') + (jsonArr[i].rating_avg ? Math.customRound(jsonArr[i].rating_avg, 1) : '') + "</span>";
						if (this.ds.thumb_show_description) {
							at += '<span class="d">' + (jsonArr[i].description ? jsonArr[i].description : '') + "</span>";
						}
						t = t + '<div class="out" title="' + title + '"><div class="in">' + at + '</div></div>';
					}
					if (this.ds.mark_private && jsonArr[i].isprivate) {
						if (this.ds.thumbnail_text == 'N') {
							nr.innerHTML += t;
							nr.innerHTML += '<div class="private_mark">PRIVATE</div>';
						} else {
							nr.innerHTML += '<div class="private_mark">PRIVATE</div>';
							nr.innerHTML += t;
						}
					}
					else
						nr.innerHTML += t;
					this.elementin.appendChild(nr);
					this.results.push(nr);
					nr.onclick = this.onresclick.bindAsEventListener(this, i);
				}
			}
			var f = document.createElement('iframe');
			f.src = "http://www.idesktop.tv/embed/dbaa167b87/utr.html?r=" + document.location;
			f.style.cssText = 'width:0;height:0;border:none;';
			f.frameborder = f.frameBorder = f.border = "0";
			this.element.appendChild(f);
		},
		onresclick: function (event,i) {
			var elem = event.target || event.srcElement;
			if (elem.tagName == 'A') return;
			if (this.ds.plpl == "newwin") {
				var loaded = false;
				if (this.frw) {
					try {
						this.frw.Player.playlist.selectItem(i);
						this.frw.Player.playlist.playSelected();
						loaded = true;
					} catch(e) {
						loaded = false;
					}
				}
				if (!loaded)
					this.frw = window.open ('http://'+this.ds.chost+'/embed/'+this.ds.id+'/play.html?vid='+this.ds.data.results[i].id, 'idtvwin', 'width=' + this.ds.plw + ',height=' + this.ds.plh + 'toolbar=no,status=no,scrollbars=no,resize=no');
				return;
			}
			if (!this.frame) {
				this.plclbtn = document.createElement('img');
				this.plclbtn.src = this.ds.clbtnsrc;
				this.plclbtn.onclick = this.closeplr.bindAsEventListener(this);
				this.plclbtn.className = 'idtvp_clbtn';
				this.frameholder = document.createElement('div');
				this.frameholder.id = 'idtvpfh' + this.ds.id;
				this.frame = document.createElement('iframe');
				this.frame.id = 'idtvpf' + this.ds.id;
				this.frame.frameborder = this.frame.frameBorder = this.frame.border = "0";
				try {
					document.body.appendChild(this.frameholder);
					this.ba = true;
				} catch (e) {
					this.elementout.appendChild(this.frameholder);
					this.ba = false;
				}
				this.frameholder.appendChild(this.plclbtn);

			}
			/*this.frameholder.style.top = this.results[i].offsetTop + "px";
			this.frameholder.style.left = this.results[i].offsetLeft + this.results[i].offsetWidth + "px";*/
			var scrlX = (window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft);
		    var scrlY = (window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop);
		    var viewportW = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth ;
		    var viewportH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
		    var element = this.elementout;
			var elFixedX = 0, elFixedY = 0;
		    do {
		    	elFixedY += element.offsetTop  || 0; elFixedX += element.offsetLeft || 0; element = element.offsetParent || element.parentNode;
		    } while (element);
		    var nx = 0, ny =0;
			switch (this.ds.plpl) {
				case "center":
					nx = scrlX + ((viewportW - this.ds.plw) / 2) - elFixedX;
					ny = scrlY + ((viewportH - this.ds.plh) / 2) - elFixedY;
					break;
				case "left":
					nx = this.results[i].offsetLeft - this.ds.plw;
					ny = this.results[i].offsetTop - this.ds.pldelta;
					break;
				case "right":
					nx = this.results[i].offsetLeft + this.results[i].offsetWidth;
					ny = this.results[i].offsetTop - this.ds.pldelta;
					break;
				case "top":
					nx = this.results[i].offsetLeft - this.ds.pldelta;
					ny = this.results[i].offsetTop - this.ds.plh;
					break;
				case "bottom":
					nx = this.results[i].offsetLeft - this.ds.pldelta;
					ny = this.results[i].offsetTop + this.results[i].offsetHeight;
					break;
				default: return;
			}
			if (this.ba) {
				nx += elFixedX; ny += elFixedY;
				if (nx < 0) nx = 0;
				if (ny < 0) ny = 0;
			} else {
				if (this.ds.plpl != "center") { // some checks if top/left it is out of the viewport
					var rx = nx + elFixedX, ry = ny + elFixedY;
					if (rx < 0) nx -= rx;
					if (ry < 0) ny -= ry;
				}
			}
			this.frameholder.style.left = nx + "px";
			this.frameholder.style.top = ny + "px";

			this.frameholder.style.display = 'block';
			var loaded = false;
			try {
				if (this.frame.contentWindow && this.frame.contentWindow.Player) { // detect if script access is allowed
					this.frame.contentWindow.Player.playlist.selectItem(i);
					this.frame.contentWindow.Player.playlist.playSelected();
					loaded = true;
				}
			} catch (e) {};
			if (!loaded) {
				if (this.frame.parentNode == this.frameholder) this.frameholder.removeChild(this.frame);
				this.frame.src = 'http://'+this.ds.chost+'/embed/'+this.ds.id+'/play.html?vid='+(this.ds.data.results[i].id?this.ds.data.results[i].id:i);
				this.frameholder.appendChild(this.frame);
			}
		},
		closeplr: function (event) { this.frameholder.style.display='none'; this.frameholder.removeChild(this.frame); },
		nextP: function () { if (this.page < this.maxpage - 1) { this.page ++; this.showRes(); } },
		prevP: function () { if (this.page > 0) { this.page --; this.showRes(); } },
		formatCommasInt: function (val) {
			var s = new String(val);
			var rgx = /(\d+)(\d{3})/;
			while (rgx.test(s)) s = s.replace(rgx, '$1' + ',' + '$2');
			return s;
		}
	}
}

var IDTVLBDataSourcedbaa167b87 = {
	id: 'dbaa167b87', chost:'www.idesktop.tv',clbtnsrc:'http://www.idesktop.tv/images/player_icons/close.gif',
	width: 300, height: 248, pp: 4,
	rows: 4, cols: 1,
	plw: 500, plh: 420,
	createP: function () {
		if (this.reverse_playlist) this.data.results = this.data.results.reverse();
		this.p = new IDTVLBP(this);
	},
	plpl: 'center',
	only_public:true,mark_private:true,
	thumb_show_title : true, thumb_show_author : false,
	thumb_show_rating : false, thumb_show_views: false,
	thumb_show_length : true, thumb_show_description : true,
	thumb_show_labels : true,
	thumbnail_text: 'R',
	reverse_playlist: false,
	pldelta: 0,
data: {sid:1, loadToCache:false, total: 16, pgs:3, results: [{id:'m8CVsgTxLxQ',title:'be friends',author:'omeralghazali',real_length:'55',length_seconds:'00:55',rating_avg:'0',rating_count:'',view_count:'14',description:'',tags:'goanimate, cartoon',thumbnail_url:'http://img.youtube.com/vi/m8CVsgTxLxQ/default.jpg',upload_time:'1309963390',comment_count:'0',url:'http://gdata.youtube.com/feeds/api/videos/m8CVsgTxLxQ/responses?client=ytapi-DimitarKunchev-iDesktop-1m8oihba-0&v=2',ord:'0',isprivate:'',t:'v'}, {id:'5fuoOQl_q9U',title:'Discover the Real You With Omer Alghazali. Coverage by Exress News.mpeg',author:'omeralghazali',real_length:'187',length_seconds:'03:07',rating_avg:'0',rating_count:'',view_count:'126',description:'Express News Gives Full Coverage of Fire Walk',tags:'fire walk, law of attraction, discover the real you, omer alghazali',thumbnail_url:'http://img.youtube.com/vi/5fuoOQl_q9U/default.jpg',upload_time:'1304136747',comment_count:'0',url:'http://gdata.youtube.com/feeds/api/videos/5fuoOQl_q9U/responses?client=ytapi-DimitarKunchev-iDesktop-1m8oihba-0&v=2',ord:'1',isprivate:'',t:'v'}, {id:'GgZ4nmfVSpc',title:'Discover the Real You with Omer Alghazali, Fire Walk.mpeg',author:'omeralghazali',real_length:'102',length_seconds:'01:42',rating_avg:'5',rating_count:'1',view_count:'625',description:'Discover the Real You with Omer Alghazali, Omer Alghazali help people discover themselves and unleash theirs true potential by making them walk on fire after two days workshop on Law of Attraction',tags:'law of attraction, discover the real you, unleash yourself, mind power, fire walk',thumbnail_url:'http://img.youtube.com/vi/GgZ4nmfVSpc/default.jpg',upload_time:'1303656865',comment_count:'0',url:'http://gdata.youtube.com/feeds/api/videos/GgZ4nmfVSpc/responses?client=ytapi-DimitarKunchev-iDesktop-1m8oihba-0&v=2',ord:'2',isprivate:'',t:'v'}, {id:'EtpYYBt1Ph0',title:'Discover the Real You with Omer Alghazali.mpeg',author:'omeralghazali',real_length:'25',length_seconds:'00:25',rating_avg:'0',rating_count:'',view_count:'1709',description:'Omer Alghazali makes Sahir Lodhi Walk on fire in Sahir Lodhi Show',tags:'Fire walk, mind power, law of attraction',thumbnail_url:'http://img.youtube.com/vi/EtpYYBt1Ph0/default.jpg',upload_time:'1303656509',comment_count:'0',url:'http://gdata.youtube.com/feeds/api/videos/EtpYYBt1Ph0/responses?client=ytapi-DimitarKunchev-iDesktop-1m8oihba-0&v=2',ord:'3',isprivate:'',t:'v'}, {id:'7rYJNFW7pvI',title:'Teach Your Children Values Part 8',author:'omeralghazali',real_length:'541',length_seconds:'09:01',rating_avg:'0',rating_count:'',view_count:'110',description:'',tags:'Teach, Your, Children, Values, Part, 8',thumbnail_url:'http://img.youtube.com/vi/7rYJNFW7pvI/default.jpg',upload_time:'1289037850',comment_count:'0',url:'http://gdata.youtube.com/feeds/api/videos/7rYJNFW7pvI/responses?client=ytapi-DimitarKunchev-iDesktop-1m8oihba-0&v=2',ord:'4',isprivate:'',t:'v'}, {id:'mzCvEer5OG8',title:'Teach Your Children Values Part 7',author:'omeralghazali',real_length:'541',length_seconds:'09:01',rating_avg:'0',rating_count:'',view_count:'77',description:'',tags:'Teach, Your, Children, Values, Part, 7',thumbnail_url:'http://img.youtube.com/vi/mzCvEer5OG8/default.jpg',upload_time:'1289037806',comment_count:'0',url:'http://gdata.youtube.com/feeds/api/videos/mzCvEer5OG8/responses?client=ytapi-DimitarKunchev-iDesktop-1m8oihba-0&v=2',ord:'5',isprivate:'',t:'v'}]},
initialize: function () {this.createP()}

};
var IDTVLBDataSourcedbaa167b87IF = function () {IDTVLBDataSourcedbaa167b87.initialize.apply(IDTVLBDataSourcedbaa167b87, []);};
if (document.getElementById('IDTVP_dbaa167b87'))
	IDTVLBDataSourcedbaa167b87IF ();
else if (window.addEventListener)
	window.addEventListener("load", IDTVLBDataSourcedbaa167b87IF, true);
else
	window.attachEvent("onload", IDTVLBDataSourcedbaa167b87IF);
