//gw.js for group 10 / widget 163870 / WxH: 500x500 / RxC: 0x0 / skin: picnic 
// pgstats - poor mans page statistics.. 
// NOT based on prototype or jquery - cause it must be lightweight

// // get our script src, to know our baseurl so we can call home
// var pgstatsScriptSource = (function(scripts) {
//     var scripts = document.getElementsByTagName('script'),
//         script = scripts[scripts.length - 1];	// at ths very moment, we are the last script guaranteed
// 
//     if (script.getAttribute.length !== undefined) {
//         return script.src
//     }
// 
//     return script.getAttribute('src', -1)
// }());

var pgstats= {
	browser: navigator.userAgent,
	uid: '',
	scr: screen.width.toString()+'x'+screen.height.toString(),
	url: document.URL,
	referrer: document.referrer,
	ecollect: {},
	baseurl: 'http://beta.yubby.com/',	// pgstatsScriptSource.substr(0,pgstatsScriptSource.lastIndexOf('/pgstats/')),
	init: function() {
		if (!(this.uid=this.readCookie('pgstats'))) {
			this.uid= Math.round(Math.random() * 2147483647).toString();
			this.uid+= Math.round(Math.random() * 2147483647).toString();
			this.createCookie('pgstats',this.uid,365*2);
		}
	}, 
	xPageHit: function () {
		var xhReq=this.createXMLHttpRequest();
		if (!xhReq)
			return 'ERR:xhReq';	// forget it..
		if (!this.baseurl)
			return 'ERR:baseurl';	// forget it..
		xhReq.open('get',this.baseurl+'pgstats/tick?'+this.collectInfo(),true);
		// xhReq.onreadystatechange = function() {
		//     if (xhReq.readyState != 4)  { return; }
		//     var serverResponse = xhReq.responseText;
		//     alert(serverResponse);
		// };
		xhReq.send();
		return 'OK';
	},
	collectInfo: function() {
		var rv;
		rv='ts=' + new Date().getTime();
		//rv+='&br='+this.encURI(this.browser);
		rv+='&uid='+this.uid;
		rv+='&url='+this.encURI(this.url);
		rv+='&refer='+this.encURI(this.referrer);
		//rv+='&ssrc='+this.encURI(this.baseurl);
		rv+='&scr='+this.scr;
		for (i in this.ecollect) {
			rv+='&'+i+'='+this.encURI(this.ecollect[i]);
		}

		return rv;
	},
	addcollect: function(key,val) {
		this.ecollect[key]=val;
	},
	//------- helper functions ----------
	createCookie: function (name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	},
	readCookie: function(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	},
	eraseCookie: function(name) {
		createCookie(name,"",-1);
	},
	encURI: function(url) {
		//return encodeURIComponent(url);	// forgets to encode a lot of chars. Useless
		var s = escape(url);	// this is the most complete one, however forgets to encode star, slash, @ and +
		s = s.replace(/\*/g,"%2A");
		s = s.replace(/\//g,"%2F");
		s = s.replace(/\@/g,"%40");
		s = s.replace(/\+/g,"%2B");
		return s;
	},
	createXMLHttpRequest: function() {
  		try { return new XMLHttpRequest(); } catch(e) {}
		try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
		try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch (e) {}
		return null;
	}
}
pgstats.init();
//pgstats.addcollect('vid','234234');
//pgstats.xPageHit();
var isIE = /MSIE ((5\.5)|[6])/.test(navigator.userAgent) && navigator.platform == "Win32";

var chs_163870= new Array();	// channels
var curch_163870=0;			// first channel

var wgElm_163870 = document.getElementById('viidoo_gw_163870');
if (wgElm_163870) {
	vp_createwg();
}

pgstats.addcollect('gid','10');
pgstats.addcollect('hit','embed');
pgstats.addcollect('widget','groupwidget');
pgstats.xPageHit();

function vp_createwg() {
	var html='<div id="widget_flash_163870" style="width: 500px;height:500px;overflow:hidden; border: 1px solid #dddddd;background-color:#ffffff;font-family:Trebuchet MS,Lucida Sans Unicode,Lucida Grande,Lucida Sans,Tahoma,Geneva,Arial,helvetica,sans-serif">';

	chs_163870.push({chid:6881, thumb: 'http://beta.yubby.com/img/channels/000005113u.png',twidth: '563.73333333333',theight: '375.2',tleft: '-166.86666666667',tright: '59',ttop: '-131.6',tbottom: '-131.6',title: 'PICNIC \'09 Day 1 Conference Sessions', desc: 'This Yubby channel groups several of the conference sessions of PICNIC \'09 day 1: \&quot;TURNING POINTS\&quot;. <br/><br/>Videos will be added during the following days so visit often!'});
	chs_163870.push({chid:7034, thumb: 'http://www.yubby.com/img/channels/000005002u.png',twidth: '563.73333333333',theight: '121.33333333333',tleft: '-166.86666666667',tright: '59',ttop: '-9.3333333333333',tbottom: '-9.3333333333333',title: 'PICNIC \'09: Bits from Day 2', desc: 'PICNIC \'09 video-moments created by the GNR8 and InHolland Rookies team... enjoy!'});
	chs_163870.push({chid:7166, thumb: 'http://www.yubby.com/img/channels/000005048u.png',twidth: '563.73333333333',theight: '122.26666666667',tleft: '-166.86666666667',tright: '59',ttop: '-5.6',tbottom: '-4.6666666666667',title: 'PICNIC \'09: Bits from Day 3', desc: 'PICNIC \'09 video-moments created by the InHolland Rookies and GNR8 teams... enjoy!'});
	chs_163870.push({chid:6998, thumb: 'http://www.yubby.com/img/channels/000004989u.png',twidth: '563.73333333333',theight: '205.33333333333',tleft: '-166.86666666667',tright: '59',ttop: '-46.666666666667',tbottom: '-46.666666666667',title: 'PICNIC \'09: Bits from Day 1', desc: 'PICNIC \'09 video-moments created by the InHolland Rookies team... enjoy!'});
	chs_163870.push({chid:6954, thumb: 'http://www.yubby.com/img/channels/000004995u.jpg',twidth: '563.73333333333',theight: '122.26666666667',tleft: '-166.86666666667',tright: '59',ttop: '-5.6',tbottom: '-4.6666666666667',title: 'A video collection from PICNIC \'09', desc: 'A collection of videos of PICNIC \'09 (www.picnicnetwork.com) generated by the attendees. Enjoy!'});
	chs_163870.push({chid:6957, thumb: 'http://www.yubby.com/img/channels/000004970u.png',twidth: '563.73333333333',theight: '205.33333333333',tleft: '-166.86666666667',tright: '59',ttop: '-46.666666666667',tbottom: '-46.666666666667',title: 'Your videos  of PICNIC\'09', desc: 'In this Yubby channel we collect the videos you produce during PICNIC \'09... just be sure to tag them with \&quot;picnic09\&quot;.<br/><br/>YouTube, Vimeo... etc we can get them all!'});
	chs_163870.push({chid:6843, thumb: 'http://www.yubby.com/img/channels/000004938u.png',twidth: '563.73333333333',theight: '205.33333333333',tleft: '-166.86666666667',tright: '59',ttop: '-46.666666666667',tbottom: '-46.666666666667',title: 'The PICNIC \'09 team talks about the highlights of the event', desc: 'Marjolijn of DucthCowbowys.nl \&amp; DutchCowgirls.nl has visited the PICNIC Headquarter lately and asked the team members of PICNIC \'09 to describe in few words some of the speakers and festival activities involved in the 2009 edition.<br/><br/>Enjoy!'});
html+='<div id="thumb_163870" style="width:498px;height:498px;position:relative;padding:5px 0px 0 5px;">';
html+=chMatrixHtml_163870(488,488);
html +='<img style="position:absolute;right:20px;bottom:10px;height:25px;z-index:5;cursor:pointer;" src="http://incdn.s3.amazonaws.com/yubbyb_v2/img/project/yubby/logo_stroke.png" onclick="location.href=\'http://beta.yubby.com/\';">';
html+='</div>';
	/******
	html +='<div style="height:26px;width:500px;position:relative;">';
	html +='<div style="position:absolute;left:35px;top:3px;color:#444;font-size:11px;line-height:10px;cursor:pointer;width:185px;height:20px;overflow:hidden;" onclick="location.href=vidplayurl_163870();"><span style="color:#888;">You are watching channel</span><br/>PICNIC \'09</div>';
	html +='<img style="position:absolute;left:336px;top:0px;height:25px;z-index:5;cursor:pointer;" src="http://incdn.s3.amazonaws.com/yubbyb_v2/img/project/yubby/logo.png" onclick="location.href=vidplayurl_163870();">';
	html +='<img onclick="showmatrix_163870(0);" style="position:absolute;left:5px;top:1px;cursor:pointer;" src="http://beta.yubby.com//img/widget/solo/skins/picnic/iconmatrix24.png" title="Click here for related videos"/>';
	html +='<img onclick="playprev_163870();" style="position:absolute;left:400px;top:1px;cursor:pointer;" src="http://beta.yubby.com//img/widget/solo/skins/picnic/iconprev24.png" title="go to the previous video in the channel"/>';
	html +='<img onclick="playstop_163870();" style="position:absolute;left:424px;top:1px;cursor:pointer;" src="http://beta.yubby.com//img/widget/solo/skins/picnic/iconstop24.png" title="stop"/>';
	html +='<img onclick="playstart_163870();" style="position:absolute;left:448px;top:1px;cursor:pointer;" src="http://beta.yubby.com//img/widget/solo/skins/picnic/iconplay24.png" title="play"/>';
	html +='<img onclick="playnext_163870();" style="position:absolute;left:472px;top:1px;cursor:pointer;" src="http://beta.yubby.com//img/widget/solo/skins/picnic/iconnext24.png" title="go to the next video in the channel"/>';
	html +='</div>';
	html+='</div>';
	*/

	wgElm_163870.innerHTML=html;
	gotopage_163870(1);
	wgElm_163870.style.display = 'block';
}

function playnext_163870() {
	if (curvid_163870 < chs_163870.length -1 ) {
		curvid_163870++;
		if (cpvideo_163870)
			playstart_163870();	// we are playing video
		else {
			var thumbdiv=document.getElementById('thumb_163870');
			thumbdiv.innerHTML=vidthumbhtml_163870(curvid_163870);
		}
	}
}
function playprev_163870() {
	if (curvid_163870 >0 ) {
		curvid_163870--;
		if (cpvideo_163870)
			playstart_163870();	// we are playing video
		else {
			var thumbdiv=document.getElementById('thumb_163870');
			thumbdiv.innerHTML=vidthumbhtml_163870(curvid_163870);
		}
	}
}
function playstart_163870(vnr) {
	closepopup_163870();	// close popup (if open)
	if (vnr==null)
		vnr=curvid_163870;
	else
		curvid_163870=vnr;	// set the current
	var thumbdiv=document.getElementById('thumb_163870');
	thumbdiv.innerHTML='<iframe name="playerframe" class="playerframe" src="http://beta.yubby.com/widget/playvideo/'+chs_163870[vnr].vid+'/500/474/L/W" width="500" height="474" frameborder="0" scrolling="no" allowtransparency="true"></iframe>';
	cpvideo_163870=true;
}

function playstop_163870() {
	cpvideo_163870=false;
	var thumbdiv=document.getElementById('thumb_163870');
	thumbdiv.innerHTML=vidthumbhtml_163870(curvid_163870);
}

function chthumbhtml_163870(vnr) {
	var html='';
	html+='<div style="width:490px;height:306px; overflow:hidden; position:absolute;left:5px;top:5px;">';
html+='<img src="'+chs_163870[vnr].thumb+'" style="width:490px;height:368px;top:-31px;position:relative;">';
html+='</div>';
html+='<div style="width:480px;height:153px;position:absolute;left:5px;top:311px;background-color:#AAA;padding:5px;"><div style="overflow:hidden;height:153px;"><div style="margin: 2px 3px; font-size:16px;color:#555555;">'+chs_163870[vnr].title+'</div><div style="margin: 2px 5px; font-size:13px;line-height:13px;color:#ffffff;overflow:hidden;height:40px;"  title="'+chs_163870[vnr].desc+'">'+chs_163870[vnr].desc+'</div><div style="padding: 3px 5px; letter-spacing:1px; background-color: #aaa; color: white; position: absolute; right: 0px; top: -14px; font-size: 10px;">'+(vnr+1)+'/'+(chs_163870.length)+'</div></div></div>';
html+='<div style="position: absolute; width:72px;height:72px;top:201px;left:214px;z-index:200;cursor:pointer;cursor:hand;background:url(http://beta.yubby.com/img/media_play72.png) no-repeat;" onClick="playstart_163870();"></div>';
	return html;
}

function chthumbhtmlSmall_163870(vnr,twidth,theight) {
	var html='';
	// 162 // 
	// 90 // max-height:122px;
	var twidth=230;		// width 500 3 cols = 480/3-10 = 150 
	var theight=138;
	var titleh=22;
	var dwidth=twidth;
	var iwidth=dwidth;
	var iheight=theight-4-titleh;
	var oimg=chs_163870[vnr];
	var ptop=(iheight-48)/2;
	var imgtooltip=chs_163870[vnr].desc;
	imgtooltip=imgtooltip.replace(/\<br\/\>/g," ");
	//alert(imgtooltip);
	
	html+='<div style="margin: 5px; float: left; position: relative; width: '+twidth+'px; height: '+theight+'px;border:1px solid #dedede;background-color:#00ab4e">';
		//html+='<div style="width:'+dwidth+'px;background:#f6f6f6;margin:0 auto 6px auto;overflow:hidden;position:relative;">';
			html+='<div style="width:'+iwidth+'px;height:'+iheight+'px;background:#cccccc;overflow:hidden;position:relative;">';
				html+='<img style="position:absolute;border:0 solid #ffffff;padding:0;margin:0;left:'+oimg.tleft+'px;top:'+oimg.ttop+'px;width:'+oimg.twidth+'px;height:'+oimg.theight+'px;cursor: pointer;" onclick="playChannel_163870('+vnr+')" title="'+imgtooltip+'" src="'+chs_163870[vnr].thumb+'" />';
										html+='<div style="position: absolute; width:48px;height:48px;top:'+ptop+'px;right:10px;z-index:200;cursor:pointer;cursor:hand;background:url(http://beta.yubby.com/img/media_play48.png) no-repeat;" onclick="playChannel_163870('+vnr+')"></div>';
							html+='</div>';
			html+='<div style="position: absolute; bottom: 0px; left: 0px;width:'+(twidth)+'px;height:'+titleh+'px;z-index:200;background-color:#00ab4e;color:#ffffff;font-size:14px;line-height:normal;overflow:hidden;white-space: nowrap;padding:0px 0px 0px 0px;cursor: pointer;" onclick="playChannel_163870('+vnr+')">'+chs_163870[vnr].title+'</div>';

		//html+='</div>';

	html+='</div>';
	return html;
}

// cp 1..npages
function paginationhtml_163870(cp,npages) {
	if (npages<=1)
		return '';	// empty if no pagination..
	var html='';
	html+='<div class="pages">';
	if (cp>1) {
		// we CAN prev!
		html+= '<span class="pageblock" onclick="gotopage_163870('+(cp-1)+');">&#x25C0;</span>';
	}
	else {
		html+= '<span class="pageblock_disabled">&#x25C0;</span>';
	}
	// Available pages - Link
	var lpage = 1;
	var cpageSur = 2;
	var dotted = false;
	for (var lpage=1;lpage<=npages;lpage++) {
		// 1-2...8-9-[10]-11-12....58-59 
		if ( lpage<=2 || (lpage>=cp-4 && lpage<=cp+4) || lpage>=npages-1) {
			dotted = false;	// we need to dot afterwards
			if (lpage == cp )
				html+='<span class="pageblock_curpage"><b>'+lpage+'</b></span>';
			else
				html+='<span class="pageblock" onclick="gotopage_163870('+lpage+');">'+lpage+'</span>';
		}
		else {
			// no printing.. buttt maybe we need to dot
			if ( !dotted ) {
				html+='<span class="pageblock_dots">&nbsp;...&nbsp;</span>';
				dotted = true;
			}
		}
	}
		
	// Next page - Link
	if ( cp<npages )
		html+='<span class="pageblock" onclick="gotopage_163870('+(cp+1)+');">&#x25B6;</span>';
	else
		html+='<span class="pageblock_disabled">&#x25B6;</span>';
	html+='</div>';
	return html;
}

var curr_channel=0;
function chplayurl_163870(vnr) {
	if (vnr==null)
		vnr=curr_channel;
	return 'http://beta.yubby.com/channel/player/'+chs_163870[vnr].chid+'/first';
}



function closepopup_163870() {
  el = document.getElementById('ipopup_163870');
  if (el) {
    el.parentNode.removeChild(el);
  } 
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}



var matrix_curpg=1;
var matrix_npages=1;

function gotopage_163870(pg) {
	matrix_curpg=pg;
	var ippage=6;	// ncols*nrows;	// items per page
	matrix_npages= Math.ceil(chs_163870.length / ippage);	// global
	
	var mxs=document.getElementById('mxs_163870');
	var html='';
	for (var i=(matrix_curpg-1)*ippage,cv=0;i<chs_163870.length && cv<ippage;i++) {
		html+=  chthumbhtmlSmall_163870(i);
		cv++;
	}
	html+=  '<div style="clear:both;"></div>';
				if (matrix_npages>1) {
				html+=  '<div style="margin:0px 0px;position: absolute; bottom:4px;">'+paginationhtml_163870(matrix_curpg, matrix_npages)+'</div>';
			}
			mxs.innerHTML=html;
}

function chMatrixHtml_163870(base_width,base_height) {	// w500-12 = 488 
	// determine size and cols/rows and pages
	var ncols=2;	// Math.floor(base_width/300)+1;
	var nrows=3;	// Math.floor(base_height/200)+1;
	var ippage=6;	// ncols*nrows;	// items per page
	
	var twidth=230;	//Math.floor(base_width/ncols)-10;
	var theight=138;
	
	matrix_npages= Math.ceil(chs_163870.length / ippage);	// global
	
	var ch_html='';
	ch_html+='<div style="padding:0px;position:relative;background-color:#ffffff;width:'+(base_width)+'px;height:'+(base_height)+'px;">';
	ch_html+='<br style="display:none;"/><style type="text/css">	\
		.pages {padding:2px 0 2px 8px; margin:0; clear:both;font-size:12px;} \
			.pages span.pageblock {border: 1px solid #888;background-color:#fff; color:#000; height: 12px; padding: 3px 6px;margin: 0px 4px 0px 0px;cursor: pointer;cursor:hand;}\
			.pages span.pageblock:hover {color:#D10101;text-decoration:underline;}	\
			.pages span.pageblock_disabled {border: 1px solid #888; background-color:#fff;color: #aaa; height: 12px; padding: 3px 6px;margin: 0px 4px 0px 0px;}\
			.pages span.pageblock_dots {border: 0px solid #888; color: #000; height: 12px; padding: 3px 6px;margin: 0px 4px 0px 0px;}\
			.pages span.pageblock_curpage {border: 1px solid #888; background-color:#fff; color: #aaa; height: 12px; padding: 3px 6px;margin: 0px 4px 0px 0px;}\
		</style>';
	ch_html+=	'<div style="margin:0px 0px 0px 0px;" id="mxs_163870">';
	// for (var i=0,cv=0;i<chs_163870.length && cv<ippage;i++) {
	// 	ch_html+=  chthumbhtmlSmall_163870(i);
	// 	cv++;
	// }
	// ch_html+=  '<div style="clear:both;"></div>';
	// 
	// if (matrix_npages>1) {
	// 	ch_html+=  '<div style="margin:10px 0px;position:abolute;bottom:0px;">'+paginationhtml_163870(matrix_curpg, matrix_npages)+'</div>';
	// }

	ch_html+=	'</div>';
	ch_html+=  '<div style="clear:both;"></div>';
	ch_html+='</div>';
	return ch_html;
}

//--------------------------------------------- POPUP -----------------------------------------------------

// find absolute top loc of object
function vp_offsetTop(obj) {
    curtop = 0;
    if (obj.offsetParent) {
    curtop = obj.offsetTop
    while (obj = obj.offsetParent) {
      curtop += obj.offsetTop
    }
  }
  return curtop;
}

function vp_offsetLeft(obj) {
  curtop = 0;
  if (obj.offsetParent) {
    curtop = obj.offsetLeft;
    while (obj = obj.offsetParent) {
      curtop += obj.offsetLeft;
    }
  }
  return curtop;
}

function closech_163870() {
  el = document.getElementById('chplayer_163870');
  if (el) {
    el.parentNode.removeChild(el);
  } 
}
// obsolete
function closeVideoPlayer_163870() {
	// close screen
	closevid_163870();
	// call to flash object
	getFlashObject("videostrip_163870").videoDeselect(0);
}

function playChannel_163870(vnr) {

	// close old one
	closech_163870();
	curr_channel=vnr;
	// open new
	var ch_div = document.createElement('div');
	var title='hello';
	ch_div.id = "chplayer_163870";
	ch_div.style.position = 'absolute';
	ch_div.style.border = 'none';
	var base_width=500;
	var base_height=500;
	
	ch_div.style.width = (base_width+14)+'px';
	ch_div.style.height = (base_height+16+2*22)+'px';
	ch_div.style.zIndex = '10000';
	//ch_div.style.border = "5px solid #cccccc";
	
	if (true) {
		// CENTER SCREEN
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		var popup_top = arrayPageScroll[1] + ((arrayPageSize[3] -base_height) / 2);
		var popup_left = arrayPageScroll[0] +((arrayPageSize[0] - base_width) / 2);
		if (popup_top<0)
			popup_top=0;
		if (popup_left<0)
			popup_left=0;
		ch_div.style.position = 'absolute';
		ch_div.style.top = popup_top + 'px';
		ch_div.style.left = popup_left + 'px';
	}
	else {
		// left or right of widget
		var top = vp_offsetTop(wgElm_163870);
		var left = vp_offsetLeft(wgElm_163870);

		// left or right
	    if (left < document.body.clientWidth/2) {
			ch_left = left +500; // - 8;
			alert('hij zit links, left='+left);
	    } else {

			ch_left = left - (base_width+2*17+10) ; // 402 plus borders 2x17 
			alert ('left='+left+' basew='+base_width);
	    }
		top=top; // - 3;
	
		//alert('video_left='+video_left+' top='+top);
		ch_div.style.top = top + 'px';
		ch_div.style.left = ch_left + 'px';
	}
	//	$skins['simple']=array('wskin'=>'simple','wbgcol'=>'#ffffff','wborder'=>'0px solid #fff');
	var ch_html = '<div style="padding:3px 3px 3px 3px;position:relative;border:1px solid #000000;background-color:#00ab4e;">';
	ch_html +='<iframe name="playerframe" class="playerframe"	src = "http://beta.yubby.com/widget/embed/square/'+chs_163870[vnr].chid+'/selected_item:first/autoplay:Y/lang:en/500/skin:green" width="500" height="500" frameborder=0 scrolling="no" allowtransparency="true"></iframe>';
	ch_html +=	   '<div onclick="closech_163870();" style="position:absolute;top:13px;right:13px;cursor:pointer;cursor:hand;background:url(http://beta.yubby.com/img/icon_bwht_close22.png) no-repeat;width:24px;height:24px;z-index:10000;"></div>\
					</div>';
					
	ch_div.innerHTML=ch_html;
	document.body.appendChild(ch_div);
}






