var VIDEO_CAPABILITY = {};
function showplayer(url) {
	var ua = navigator.userAgent.toLowerCase();
	if( ua.match(/android|iphone|ipod/) ) {
		var win1 = window.open(url,"_player")
		win1 && win1.focus();
		return;
	}
	var rnd = Math.round;
	var x=screen.availWidth;
	var y=screen.availHeight;
	var aspect_ratio = 1.5;
	var pct = .90;
	if (x > 999 ) {
		pct=0.80;
	}
	if (x > 1199 ) {
		pct=0.75;
	}
	if (x > 1400 ) {
		pct=0.70;
	}
	var width = rnd(pct*x);
	var height = rnd(width/aspect_ratio);
	var top = rnd( (y-height)/3);
	var left= rnd( (x-width)/2);

	var win1=window.open(
		url,
		'YABLA',
		'resizable=yes,location=yes,width='+width+',height='+height+',top='+top+',left='+left);
	win1 && win1.focus();
}
$(function() {
  $('a.gb').live("click",function(e){
    e.preventDefault();
    showplayer(this.href);
    return false;
  });

	var detect = document.createElement('video') || false;
	VIDEO_CAPABILITY.html5 = detect && typeof detect.canPlayType !== "undefined";
	VIDEO_CAPABILITY.mp4 = VIDEO_CAPABILITY.html5 && (detect.canPlayType("video/mp4") === "maybe" || detect.canPlayType("video/mp4") === "probably");
   VIDEO_CAPABILITY.ogg = VIDEO_CAPABILITY.html5 && (detect.canPlayType("video/ogg") === "maybe" || detect.canPlayType("video/ogg") === "probably");
	createCookie('h264_capable', VIDEO_CAPABILITY.mp4 ? '1' : '0',10);
});

function createCookie(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=/";
}

function readCookie(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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

