var today = new Date();
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1) { endstr = document.cookie.length; }
  return unescape(document.cookie.substring(offset, endstr));
  }

function getCookieValue (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg) {
      return getCookieVal (j);
      }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
    }
  return null;
  }

function DeleteCookie (name,path,domain) {
  if (getCookieValue(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
  }

function setCookie (value) {
	name="choice";
	 var today = new Date();
     var expires = new Date(today.getTime() + 555 * 24 * 60 * 60 * 1000);
	 document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "");
  }


function displayVideoPlayer(normalizeUrl)
{
	var quality = "";//$.query.GET('quality');
	var choice = null;
	if(quality=="" || quality==null) // first time load and setting cookie
	{
		//choice = getCookieValue();
		choice=getCookieValue('choice');

		if(choice!=null || quality=="")
		{
			quality=choice;
		}
		else
		{
			quality="standard";
			
		}
	}
	else{
		setCookie(quality);
	}

	if(quality=="standard") // Set flag for switch quality mode
	{
		finalFlag=true;
	}
	else if(quality=="hq"){
		finalFlag=false;
	}
	else{
		finalFlag=true;
	}
	//alert("swtchingFlag:"+swtchingFlag);
	//alert("finalFlag:"+finalFlag);
	if("undefined" == typeof(VideoPlayerRB)){
		VideoPlayer.init(finalFlag, {data_url: normalizeUrl, autoplay: 1}, true);
	} else {
		VideoPlayerRB.init(finalFlag, {data_url: normalizeUrl, autoplay: 1}, true);
	}
}