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(IDTVVWP) == "undefined") {
	IDTVVWP = function () {this.initialize.apply(this, arguments);};
	IDTVVWP.prototype = {
		frame: null,
		initialize: function (ds) {

			this.ds = ds;
			this.element = document.getElementById('IDTVP_' + this.ds.id);
			if (!this.element && document.getElementsByClassName)
				try {
					this.element = document.getElementsByClassName ('idtv_ad767039ad')[0];
				} catch(e) {}
			if (!this.element) { alert ('The iDesktop.tv video wall is not not embedded properly!'); return;}
			this.element.innerHTML = '<div class="idtv_' + this.ds.id + '"><div class="idtv_inres"></div><div class="idtv_bb">' +
				'<div class="idtv_btn_prev"></div><div class="idtv_btn_next"></div><div class="idtv_bb_pages"></div></div></div>';
			var divs = this.element.getElementsByTagName('div');
			this.elementout = divs[0];
			this.elementin = divs[1];
			this.btn_prev = divs[3];
			this.btn_next = divs[4];
			this.pagers_area = divs[5];
			if (this.ds.data.error) {
				this.elementin.innerHTML = '<div style="text-align:center">' + this.ds.data.error + '</div>';
			} else {
				this.btn_prev.onclick = this.prevP.bindAsEventListener(this);
				this.btn_next.onclick = this.nextP.bindAsEventListener(this);
				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;
				}
				this.results = new Array();
				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 % this.ds.cols + Math.floor(i / this.ds.cols)) % 2) nr.className += ' alt';
					jsonArr[i].title_esc = (jsonArr[i].title ? jsonArr[i].title.replace(/"/g, "&quot;") : '');  // comment only to fix code coloring "
					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)
						nr.innerHTML += '<div class="private_mark">PRIVATE</div>';
					nr.innerHTML += t;
					this.elementin.appendChild(nr);
					nr.style.display = 'none';
					this.results.push(nr);
					nr.onclick = this.onresclick.bindAsEventListener(this, i);
				}
				this.showRes();
			}
			var f = document.createElement('iframe');
			f.src = "http://www.idesktop.tv/embed/ad767039ad/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);
				}
				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); },
		showRes: function () {
			if (this.results.length == 0)
				this.pagers_area.innerHTML = 'no results';
			else {
				var s = this.page * this.ds.pp, e = Math.min (s + this.ds.pp, this.results.length) - 1;
				for (var i = 0, n = this.results.length; i < n; i ++)
					this.results[i].style.display =  (i < s || i > e ? 'none' : 'block');
				this.pagers_area.innerHTML = (s+1) + ' - ' + (e+1) + ' (' + this.results.length + ')';
			}
		},
		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 IDTVLBDataSourcead767039ad = {
	id: 'ad767039ad', chost:'www.idesktop.tv',clbtnsrc:'http://www.idesktop.tv/images/player_icons/close.gif',
	width: 607, height: 530, pp: 5,
	rows: 5, cols: 1,
	plw: 600, plh: 500,
	createP: function () {
		if (this.reverse_playlist) this.data.results = this.data.results.reverse();
		this.p = new IDTVVWP(this);
	},
	plpl: 'center',
	only_public:true,mark_private:true,
	thumb_show_title : false, thumb_show_author : false,
	thumb_show_rating : false, thumb_show_views: false,
	thumb_show_length : false, thumb_show_description : true,
	thumb_show_labels : true,
	thumbnail_text: 'R',
	reverse_playlist: false,
	pldelta: 0,
		data: {results: [{id:'qWoEw0sNxds',title:'Procomp Electronics / Motorsport BLOWN Coupe BAMBAM',author:'PROCOMPMOTORSPORT',real_length:'55',length_seconds:'00:55',rating_avg:'',rating_count:'',view_count:'652',description:'www.procompelectronics.com Procomp Electronics / Motorsport BLOWN Coupe BAMBAM',tags:'Procomp, Electronics, Motorsport, BLOWN, Coupe, BAMBAM',thumbnail_url:'http://i.ytimg.com/vi/qWoEw0sNxds/2.jpg',upload_time:'0',comment_count:'0',url:'http://gdata.youtube.com/feeds/videos/qWoEw0sNxds/related',ord:'28'},{id:'G4lFI1hh2NI',title:'PROCOMP MOTORSPORT / ELECTRONICS FORD 347 CRATE MOTOR',author:'PROCOMPMOTORSPORT',real_length:'102',length_seconds:'01:42',rating_avg:'',rating_count:'',view_count:'1173',description:'FORD 347 PROCOMP MOTORSPORT / ELECTRONICS STROKER MOTOR UP AGAINST TRICK AND MANSWETO 643 - 1200HP BLACK CAPRI.',tags:'FORD, 347, PROCOMP, MOTORSPORT, ELECTRONICS, STROKER, MOTOR, UP, AGAINST, TRICK, AND, MANSWETO, 643, 1200HP, BLACK, CAPRI.',thumbnail_url:'http://i.ytimg.com/vi/G4lFI1hh2NI/2.jpg',upload_time:'0',comment_count:'0',url:'http://gdata.youtube.com/feeds/videos/G4lFI1hh2NI/related',ord:'29'},{id:'5sQV-b5cy6c',title:'Bambams Blown 34 Coupe Hotrod',author:'PROCOMPMOTORSPORT',real_length:'95',length_seconds:'01:35',rating_avg:'',rating_count:'',view_count:'229',description:'Bambams Blown 34 Coupe Hotrod',tags:'Bambams, Blown, 34, Coupe, Hotrod',thumbnail_url:'http://i.ytimg.com/vi/5sQV-b5cy6c/2.jpg',upload_time:'0',comment_count:'0',url:'http://gdata.youtube.com/feeds/videos/5sQV-b5cy6c/related',ord:'30'},{id:'po2w4bJdZNs',title:'FORD 351 - 408 Cleveland Blown Methanol Procomp Electronics / Motorsport',author:'PROCOMPMOTORSPORT',real_length:'207',length_seconds:'03:27',rating_avg:'',rating_count:'',view_count:'7236',description:'www.procompelectronics.com Procomp Electronics / MotorsportFord Cleveland 408 Engine InternalsFord 351 Cleveland 2 - Coverted 4 Bolt Block Procomp 4.00" - Forged 4340 Steel Stroker Crank Procomp Forged Pistons Procomp "H" Beam Forged 3D Conrods Procomp Chrome Moly Rings Procomp HV Sump Procomp HV Oil Pump Mechanical Waterman Fuel Pump (methanol) Procomp Alloy Water Pump Procomp Gear Drive Set Procomp Multi Layer Steel - Full Gasket Kit Procomp Race Damper Clevite "H" Main / Conrod / Cam Bearings Offenhouser Blower Manifold Procomp Aluminium Cylinder Heads Custom Grind Solid Roller Camshaft Procomp Solid Roller Lifters Procomp Custom Pushrods Procomp Billet Aluminium Shaft Mount Roller Rockers Procomp Shaft Mount Individual Pedestals and Studs Procomp 12pt - 1/2"  Main Stud Kit Procomp 12pt - 1/2" Head Stud Kit Procomp HD Flexplate Ford Motorsport Aluminium Valve Covers Procomp Hi Torque Gear Reduction Starter Motor Enderle Blower Injection Hat Procomp Custom Angle Drive Distributor Kit',tags:'Procomp, Electronics, Motorsport, 351, 408, Cleveland, Blown, Methanol',thumbnail_url:'http://i.ytimg.com/vi/po2w4bJdZNs/2.jpg',upload_time:'0',comment_count:'0',url:'http://gdata.youtube.com/feeds/videos/po2w4bJdZNs/related',ord:'30'},{id:'8MOazgwM7vU',title:'Sydney Speed Supplies run in a Procomp Motorsport / Electronics 383 Blown Small Block Chev Motor.',author:'PROCOMPMOTORSPORT',real_length:'55',length_seconds:'00:55',rating_avg:'',rating_count:'',view_count:'1635',description:'Sydney Speed Supplies run in a Procomp Motorsport / Electronics 383 Blown Small Block Chev Motor.',tags:'Sydney, Speed, Supplies, run, in, Procomp, Motorsport, Electronics, 383, Blown, Small, Block, Chev, Motor',thumbnail_url:'http://i.ytimg.com/vi/8MOazgwM7vU/2.jpg',upload_time:'0',comment_count:'0',url:'http://gdata.youtube.com/feeds/videos/8MOazgwM7vU/related',ord:'31'}]},
		initialize: function () {this.createP()}

};
var IDTVLBDataSourcead767039adIF = function () {IDTVLBDataSourcead767039ad.initialize.apply(IDTVLBDataSourcead767039ad, []);};
if (document.getElementById('IDTVP_ad767039ad'))
	IDTVLBDataSourcead767039adIF ();
else if (window.addEventListener)
	window.addEventListener("load", IDTVLBDataSourcead767039adIF, true);
else
	window.attachEvent("onload", IDTVLBDataSourcead767039adIF);
