//solo.js for channel 7656 / widget 596923 / WxH: 300x260.47058823529 / skin: clean / vid: 0
// 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://www.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 cvids_596923= new Array();	// channelvideo's
var curvid_596923=0;			// first video
var cpvideo_596923=false;		// false=thumb, true=video

var wgElm_596923 = document.getElementById('viidoo_solo_596923');
if (wgElm_596923) {
	vp_createwg();
}

pgstats.addcollect('chid','7656');
pgstats.addcollect('hit','embed');
pgstats.addcollect('widget','solo');
pgstats.xPageHit();

function vp_createwg() {
	var html='<div id="widget_flash_596923" class="widget_flash" style="width: 300px;height:260.47058823529px;overflow:hidden; border: 1px solid #DDDDDD;font-family:Trebuchet MS,Lucida Sans Unicode,Lucida Grande,Lucida Sans,Tahoma,Geneva,Arial,helvetica,sans-serif">';

	cvids_596923.push({vid:62998, thumb: 'http://a.images.blip.tv/Vincente-MitchCanterInterviewAtBlogworldExpo2009200-389-907.jpg', title: 'Mitch Canter interview at Blogworld Expo 2009', desc: '\nAn interview with Mitch Canter from http://www.studionashvegas.com interview at Blogworld Expo 2009. \n'});
	cvids_596923.push({vid:62999, thumb: 'http://cdn-thumbs.viddler.com/thumbnail_2_937dbeac.jpg', title: 'Mitchlog - Vol 1 (Thoughts On Social South)', desc: 'Mitch weighs in on Social South'});
	cvids_596923.push({vid:59779, thumb: 'http://a.images.blip.tv/Studionashvegas-PodCampNashvilleWordPressPodcasting521-402-907.jpg', title: 'PodCampNashville - WordPress \& Podcasting', desc: '\n\nMitch\'s presentation at PodCampNashville on Podcasting and WordPress.\n\n'});
	cvids_596923.push({vid:59777, thumb: 'http://a.images.blip.tv/Shermanhu-GetYourOoVooOn6PersonVideoChatWithJosephJaffe284-874.jpg', title: 'Get Your ooVoo On - 6-Person Video Chat with Joseph Jaffe', desc: '\nConnie Crosby (PodcampToronto.org), Eden Spodek (Bargainista.Blogspot.com), Mitch Canter (StudioNashVegas.com), Al Mostow, Joseph Jaffe (JaffeJuice.com) and I, Sherman Hu *(ShermanLive.com) had a short but sweet video chat on ooVoo. Joseph Jaffe shared about his \"Second Life\" life and the intersections between our physical, digital and virtual worlds. This short video sample of our chat will give you an idea of well this platform works. Effective platform for business owners to use ooVoo for video interviews and webinars. Fantastic platform for families and friends to connect across the globe, six at a time.\n'});
	cvids_596923.push({vid:59776, thumb: 'http://cdn-thumbs.viddler.com/thumbnail_2_5d80cad1.jpg', title: 'Live from the food line', desc: 'Talking with Mitch Canter and Nathan Ketsdever live at the lunch buffet line. They also share their morning session experience. Also check out Mitch at http://studionashvegas.com and Nathan at http://creativefusionmedia.wordpress.com/'});
	cvids_596923.push({vid:62997, thumb: 'http://ts.vimeo.com.s3.amazonaws.com/399/900/3999006_640.jpg', title: 'PodCamp Nashville 2009 - studionashvegas', desc: 'studionashvegas and nashvogue at PodCamp Nashville 2009'});
	cvids_596923.push({vid:59778, thumb: 'http://www.yubby.com/util/fetchurl?http%3A%2F%2F2.gvt0.com%2FThumbnailServer2%3Fapp%3Dvss%26contentid%3D7fc5fd2c02579d0a%26offsetms%3D20000%26itag%3Dw160%26hl%3Dnl%26sigh%3DGOEsd48omG_2gpl-B0gtcaXFAEE', title: 'confessions of a blogtender - entry one', desc: 'the first entry into my videolog. I\&#39;m hosting on Google Video in order to allow visitors to get to my weblog and see what I\&#39;ve got. www ...'});
	cvids_596923.push({vid:59781, thumb: 'http://i.ytimg.com/vi/9vaC_PfKHnw/0.jpg', title: 'BarCamp Memphis Eve - Mitch Canter', desc: 'Mitch Canter share a moment at Memphis first BarCamp pre-event mixer on November 7th, 2008. The \"Eve\" was held at Ground Zero Blues Club.'});
html+='<div id="thumb_596923" style="width:300px;height:234.47058823529px;background-color:#FFFFFF;position:relative;">';
html+=vidthumbhtml_596923(curvid_596923);
html+='</div>';
	html +='<div style="height:26px;width:300px;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_596923();"><span style="color:#888;"></div>';
	html +='<img style="position:absolute;left:136px;top:0px;height:25px;z-index:5;cursor:pointer;margin:0;padding:0;" src="http://www.yubby.com/img/project/yubby/logo.png" onclick="location.href=vidplayurl_596923();">';
	html +='<img onclick="showmatrix_596923(0);" style="position:absolute;left:5px;top:1px;cursor:pointer;margin:0;padding:0;" src="http://www.yubby.com//img/widget/solo/iconmatrix24.png" title="popup an overview with all videos"/>';
	html +='<img onclick="playprev_596923();" style="position:absolute;left:200px;top:1px;cursor:pointer;margin:0;padding:0;" src="http://www.yubby.com//img/widget/solo/iconprev24.png" title="go to the previous video in the channel"/>';
	html +='<img onclick="playstop_596923();" style="position:absolute;left:224px;top:1px;cursor:pointer;margin:0;padding:0;" src="http://www.yubby.com//img/widget/solo/iconstop24.png" title="stop"/>';
	html +='<img onclick="playstart_596923();" style="position:absolute;left:248px;top:1px;cursor:pointer;margin:0;padding:0;" src="http://www.yubby.com//img/widget/solo/iconplay24.png" title="play"/>';
	html +='<img onclick="playnext_596923();" style="position:absolute;left:272px;top:1px;cursor:pointer;margin:0;padding:0;" src="http://www.yubby.com//img/widget/solo/iconnext24.png" title="go to the next video in the channel"/>';
	html +='</div>';
	html+='</div>';
	wgElm_596923.innerHTML=html;
	wgElm_596923.style.display = 'block';
}

function playnext_596923() {
	if (curvid_596923 < cvids_596923.length -1 ) {
		curvid_596923++;
		if (cpvideo_596923)
			playstart_596923();	// we are playing video
		else {
			var thumbdiv=document.getElementById('thumb_596923');
			thumbdiv.innerHTML=vidthumbhtml_596923(curvid_596923);
		}
	}
}
function playprev_596923() {
	if (curvid_596923 >0 ) {
		curvid_596923--;
		if (cpvideo_596923)
			playstart_596923();	// we are playing video
		else {
			var thumbdiv=document.getElementById('thumb_596923');
			thumbdiv.innerHTML=vidthumbhtml_596923(curvid_596923);
		}
	}
}
function playstart_596923(vnr) {
	closepopup_596923();	// close popup (if open)
	if (vnr==null)
		vnr=curvid_596923;
	else
		curvid_596923=vnr;	// set the current
	var thumbdiv=document.getElementById('thumb_596923');
	thumbdiv.innerHTML='<iframe name="playerframe" class="playerframe" src="http://www.yubby.com/widget/playvideo/'+cvids_596923[vnr].vid+'/300/234.47058823529/L/W" width="300" height="234.47058823529" frameborder="0" scrolling="no" allowtransparency="true"></iframe>';
	cpvideo_596923=true;
}

function playstop_596923() {
	cpvideo_596923=false;
	var thumbdiv=document.getElementById('thumb_596923');
	thumbdiv.innerHTML=vidthumbhtml_596923(curvid_596923);
}

function vidthumbhtml_596923(vnr) {
	var html='';
	html+='<div style="width:290px;height:181px; overflow:hidden; position:absolute;left:5px;top:5px;">';
html+='<img src="'+cvids_596923[vnr].thumb+'" style="width:290px;height:218px;top:-18px;position:relative;">';
html+='</div>';
html+='<div style="width:280px;height:38.470588235294px;position:absolute;left:5px;top:186px;background-color:#AAA;padding:5px;"><div style="overflow:hidden;height:38.470588235294px;"><div style="margin: 2px 3px; font-size:16px;color:#555555;">'+cvids_596923[vnr].title+'</div><div style="margin: 2px 5px; font-size:13px;line-height:13px;color:#ffffff;overflow:hidden;height:40px;"  title="'+cvids_596923[vnr].desc+'">'+cvids_596923[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)+'/'+(cvids_596923.length)+'</div></div></div>';
html+='<div style="position: absolute; width:72px;height:72px;top:81.235294117647px;left:114px;z-index:200;cursor:pointer;cursor:hand;background:url(http://www.yubby.com/img/media_play72.png) no-repeat;" onClick="playstart_596923();"></div>';
	return html;
}

function vidthumbhtmlSmall_596923(vnr) {
	var html='';
	html='';
	html+='<div style="margin: 5px; float: left; position: relative; width: 162px; height: 90px;">';
		html+='<div style="width:160px;max-height:122px;background:#f6f6f6;margin:0 auto 6px auto;overflow:hidden;position:relative;">';
			html+='<div style="width:156px;height:86px;background:#cccccc;border:2px solid #dedede;overflow:hidden;position:relative;">';
				html+='<img style="position:absolute;width:160px;height:119px;top:-20px;left:0;cursor: pointer;" onclick="playstart_596923('+vnr+')" title="'+cvids_596923[vnr].desc+'" src="'+cvids_596923[vnr].thumb+'" />';
				html+='<div style="position: absolute; width:24px;height:24px;top:28px;left:68px;z-index:200;cursor:pointer;cursor:hand;background:url(http://www.yubby.com/img/media_play24.png) no-repeat;" onclick="playstart_596923('+vnr+')"></div>';
				html+='<div style="position: absolute; bottom: 0px; left: 0px;width:156px;height:15px;z-index:200;background-color:#dedede;color:#000000;font-size:11px;overflow:hidden;white-space: nowrap;padding:2px 5px 2px 3px;filter: alpha(opacity=80);filter: progid:DXImageTransform.Microsoft.Alpha(opacity=80);-moz-opacity: 0.80; opacity: 0.80;cursor: pointer;" onclick="playVideo_773417(15893)" >'+cvids_596923[vnr].title+'</div>';
			html+='</div>';
		html+='</div>';
	html+='</div>';
	return html;
}

// cp 1..npages
function paginationhtml_596923(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_596923('+(cp-1)+');">&#171; Previous</span>';
	}
	else {
		html+= '<span class="pageblock_disabled">&#171; Previous</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_596923('+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_596923('+(cp+1)+');">Next &#187;</span>';
	else
		html+='<span class="pageblock_disabled">Next &#187;</span>';
	html+='</div>';
	return html;
}

function vidplayurl_596923(vnr) {
	if (vnr==null)
		vnr=curvid_596923;
	return 'http://www.yubby.com/channel/player/7656/'+cvids_596923[vnr].vid;
}

// 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 closepopup_596923() {
  el = document.getElementById('ipopup_596923');
  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_596923(pg) {
	matrix_curpg=pg;
	var mxs=document.getElementById('mxs_596923');
	var html='';
	for (var i=(matrix_curpg-1)*16,cv=0;i<cvids_596923.length && cv<16;i++) {
		html+=  vidthumbhtmlSmall_596923(i);
		cv++;
	}
	html+=  '<div style="clear:both;"></div>';
	if (matrix_npages>1) {
		html+=  '<div style="margin:10px 0px">'+paginationhtml_596923(matrix_curpg, matrix_npages)+'</div>';
	}

	mxs.innerHTML=html;
}

function showmatrix_596923() {
	// close old one
	closepopup_596923();

	matrix_npages= Math.ceil(cvids_596923.length / 16);
	
	// open new
	var popup_div = document.createElement('div');
	var title='matrix';
	popup_div.id = "ipopup_596923";
	popup_div.style.position = 'absolute';
	popup_div.style.border = 'none';
	var base_width=172*4+25;

	var base_height=100*4+30+10+4;
	if (matrix_npages>1) 
		base_height+=30;
	popup_div.style.width = base_width+'px';
	popup_div.style.height = base_height+'px';
	popup_div.style.fontFamily='Trebuchet MS,Lucida Sans Unicode,Lucida Grande,Lucida Sans,Tahoma,Geneva,Arial,helvetica,sans-serif';
	popup_div.style.zIndex = '10000';

	// 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;
	popup_div.style.position = 'absolute';
	popup_div.style.top = popup_top + 'px';
	popup_div.style.left = popup_left + 'px';


	
	var vid_html='';
	vid_html+='<div style="padding:0px;position:relative;border:2px #CCC solid;background-color:white;width:'+(base_width-4)+'px;height:'+(base_height-4)+'px;">';
	vid_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; 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; 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; color: #aaa; height: 12px; padding: 3px 6px;margin: 0px 4px 0px 0px;}\
		</style>';
	vid_html+=	'<div onclick="closepopup_596923();" style="position:absolute;top:7px;right:8px;cursor:pointer;cursor:hand;background:url(http://www.yubby.com/img/icon_bw_close22.png) no-repeat;width:24px;height:24px;z-index:10000;"></div>';
	vid_html+=	'<div style="position:absolute;top:8px;left:15px;color:#888;font-size:15px;overflow:hidden;width:'+(base_width-50)+'px;">Mitch\'s Videos</div>';
	vid_html+=	'<div style="margin:30px 10px 10px 10px;" id="mxs_596923">';
	// for (var i=0,cv=0;i<cvids_596923.length && cv<16;i++) { 
	// 		vid_html+=  vidthumbhtmlSmall_596923(i);
	// 		cv++;
	// 	}
	// 	vid_html+=  '<div style="clear:both;"></div>';
	// 
	// 	if (matrix_npages>1) {
	// 		vid_html+=  '<div style="margin:10px 0px">'+paginationhtml_596923(matrix_curpg, matrix_npages)+'</div>';
	// 	}
	vid_html+=	'</div>';
	vid_html+=  '<div style="clear:both;"></div>';
	vid_html+='</div>';
					
	popup_div.innerHTML=vid_html;
	document.body.appendChild(popup_div);
	gotopage_596923(matrix_curpg);
}

// utf8 to string conversions
var escapable = /[\\\"\x00-\x1f\x7f-\uffff]/g,
    meta = {    // table of character substitutions
        '\b': '\\b',
        '\t': '\\t',
        '\n': '\\n',
        '\f': '\\f',
        '\r': '\\r',
        '"' : '\\"',
        '\\': '\\\\'
    };

function utf8quote(string) {
	// If the string contains no control characters, no quote characters, and no
	// backslash characters, then we can safely slap some quotes around it.
	// Otherwise we must also replace the offending characters with safe escape
	// sequences.

    escapable.lastIndex = 0;
    return escapable.test(string) ?
        '"' + string.replace(escapable, function (a) {
            var c = meta[a];
            return typeof c === 'string' ? c :
                '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
        }) + '"' :
        '"' + string + '"';
}



