set_cookie = function(name, value, expires, path, domain){
	if(expires && path && domain){
		if(expires == 'browser'){
			document.cookie = name + '=' + value + ';path=' + path + ';domain=' + domain;
		}else{
			document.cookie = name + '=' + value + ';expires=' + expires.toGMTString() + ';path=' + path + ';domain=' + domain;
		}
	}else if(expires && path){
		document.cookie = name + '=' + value + ';expires=' + expires.toGMTString() + ';path=' + path + ';';
	}else if(expires){
		document.cookie = name + '=' + value + ';expires=' + expires.toGMTString() + ';';
	}else{
		document.cookie = name + '=' + value + ';';
	}	
};


get_cookie = function(name){
	var search = name;
	var returnval = '';

	if(document.cookie.length > 0){
		offset = document.cookie.indexOf(search);
		if(offset != -1){
			offset += search.length+1;
			end = document.cookie.indexOf(';', offset);
			if(end == -1){
				end = document.cookie.length;
			}
			returnval = unescape(document.cookie.substring(offset, end));
		}
	}
	return returnval;
};

  startList = function() {
	  if (document.all&&document.getElementById) {
		  navRoot = document.getElementById("nav");
		  for (i=0; i<navRoot.childNodes.length; i++) {
			  node = navRoot.childNodes[i];
			  if (node.nodeName=="LI") {
				  node.onmouseover=function() {
					  this.className+=" over";
				  }
				  node.onmouseout=function() {
					  this.className=this.className.replace(" over", "");
				  }
			  }
		  }
	  }
  }





var videoPlayerStatus = 'normal';
	
	function videoFullscreen(){ 
		var v = document.getElementById("divUvPlayer").style;
		var bg = document.getElementById("fullScreenBackground").style;

		var maxWidth = document.documentElement.clientWidth;
		var maxHeight = self.innerHeight || document.documentElement.clientHeight;

		if(videoPlayerStatus == 'normal'){			
			//enlarge video play
			v.top = '-90px';
			v.left = '-90px';
			v.width = '620px';
			v.height = '500px';
			v.zindex = '40';

			//bg.display = 'block';
		

			videoPlayerStatus = 'fullscreen';
		}else{
			//normal size
			v.top = '0';
			v.left = '0';
			v.width = '420px';
			v.height = '345px';
			bg.display = 'none';
			v.zindex = '40';
			videoPlayerStatus = 'normal'; 
		}
	}	

	function shareVideo(action){ 
		alert(action);
	}	

var qsParm = new Array();

function qs() {
   var query = window.location.search.substring(1);
   var parms = query.split('&');
   for (var i=0; i<parms.length; i++) {
	 var pos = parms[i].indexOf('=');
	 if (pos > 0) {
	   var key = parms[i].substring(0,pos);
	   var val = parms[i].substring(pos+1);
	   qsParm[key] = val;
	 }
   }
}

//qs();


var CommentsDisplay = false;
function toggleComments() {
  if(document.getElementById("video_comments_content")) {
    var comments = document.getElementById("video_comments_content").style;
    if(CommentsDisplay == false) {
      comments.display = 'none';
      CommentsDisplay = true;
      document.getElementById("toggle_comments").innerHTML = 'Post a Comment';
    } else {
      comments.display = 'block';
      CommentsDisplay = false;
      document.getElementById("toggle_comments").innerHTML = 'Cancel';
    }
  }
}

ReportDisplay = false;
function toggleVideoReport() {
	if(document.getElementById("video_report")){
  	var report = document.getElementById("video_report").style;
  	if(ReportDisplay == false) {
  		report.display = 'none';
  		ReportDisplay = true;
      document.getElementById("toggle_report").innerHTML = 'Report This Video';
  	} else {
  		report.display = 'block';
  		ReportDisplay = false;
      document.getElementById("toggle_report").innerHTML = 'Cancel';
  	}
  }
}

function roadBlockManager(skin){
   
   var date = new Date();
   var timestamp = date.getTime();
	
   clickTag = "http://ad.doubleclick.net/jump/mlg.gameroom;skin="+skin+";sz=990x400;ord="+ timestamp +"?";  
   skinImagePath = "http://ad.doubleclick.net/ad/mlg.gameroom;skin="+skin+";sz=990x400;ord="+ timestamp +"?";

   document.getElementById("ad-wrap-roadblock").innerHTML = "<a href=\""+clickTag+"\" target=\"_newwindow\"><img src=\""+ skinImagePath +"\" alt=\"Ad\" width=\"990\" height=\"400\" border=\"0\" /><\/a>";
}

 function hideGameSearchResults() {
    mlgLayerHide("game_livesearch");
  }
  function livesearchMouseDown(event) {
    event.cancelBubble = true;
  }
  document.onmousedown = hideGameSearchResults;
  if (document.layers) {
    window.captureEvents(Event.MOUSEDOWN);
  }
  window.onmousedown = hideGameSearchResults;

  var list = null;
  var lastitem = null;

  function mlgSetGame(id, title, platform) {
    mlgLayerHide("game_livesearch");
    document.forms["advanced_search_form"]["game_id"].value = id;
    document.forms["advanced_search_form"]["game_title"].value = title + " (" + platform + ")";
  }

  function mlgGameLookupProcess() {
    if (ajax.xml_http.responseText.length > 0) {
      mlgLayerShow("game_livesearch");
      list = null;
      lastitem = null;
      document.getElementById("game_livesearch").innerHTML = ajax.xml_http.responseText;
    } else {
      mlgLayerHide("game_livesearch");
    }
  }

  function mlgGameLookup(event, s) {
    retval = false;
    switch (event.keyCode) {
      case 40: //down arrow
      if (list == null) list = document.getElementById("game_livesearch").firstChild;
      if (lastitem == null) {
        lastitem = list.firstChild;
      } else {
        lastitem.firstChild.style.backgroundColor = '';
        lastitem.firstChild.style.color = '';
        if (lastitem.nextSibling != null) {
          lastitem = lastitem.nextSibling;
        }
      }
      lastitem.firstChild.style.backgroundColor = '#336699';
      lastitem.firstChild.style.color = '#ffffff';
      break;

      case 38: //up arrow
      if (list == null) list = document.getElementById("game_livesearch").firstChild;
      if (lastitem != null) {
        if (lastitem.previousSibling != null) {
          lastitem.firstChild.style.backgroundColor = '';
          lastitem.firstChild.style.color = '';
          lastitem = lastitem.previousSibling;
        }
      }
      lastitem.firstChild.style.backgroundColor = '#336699';
      lastitem.firstChild.style.color = '#ffffff';
      break;
      case 13: //enter
      eval(lastitem.firstChild.attributes.getNamedItem('onclick').value);
      break;

      default:
        retval = true;
        s += String.fromCharCode(event.keyCode);
        if (s.length >= 3) {
          ajax.sendRequest("/live_search/games.php?s="+s, "GET", mlgGameLookupProcess);
        }
        break;
    }
    return retval;
  }
  
  
  function init(){
 	 startList();
 	 toggleComments();
   toggleVideoReport();
  }
  
  window.onload=init;