var player  = null;     
var playid=-1;

function insertVideo(videoid,w,h) {
        document.write('<div id="video'+videoid+'">-- Video Loading --</div>');
        createPlayer(videoid,w,h);
}

function insertAgeVideo(videoid) {
	age=GetCookie('scAge');	
	if (age > 18) {
	document.write(''+age+'');
	document.write('<div id="video'+videoid+'">-- Video Loading --</div>');
        createPlayer(videoid);
	} else {
	document.write('<iframe id="ageverify" src="" style="width:400px;height:250px;"></iframe>');
	}

}

function createPlayer(videoid,w,h) {
	if (!w) { w=640; }
        if (!h) { h=480; }
	var pid="video"+videoid;
    jwplayer(pid).setup({
        flashplayer: "http://video.supercheats.com/jw58/player.swf",
        config: "http://video.supercheats.com/loadvideo/"+videoid,
        height: h,
        width: w
    });

}

function oldcreatePlayer(videoid,w,h) {
	if (!w) { w=640; }
	if (!h) { h=480; }
   var params = { allowScriptAccess: "always",allowfullscreen: "true",allownetworking: "all",wmode:"transparent" };
   var atts = { id: "scplayer" };
   var divname="video"+videoid;
   var playername="player"+videoid;
   var flashvars = { config: 'http://video.supercheats.com/loadvideo/'+videoid }

        var attributes = {
                id: playername,
                name: playername
        }


        swfobject.embedSWF("http://video.supercheats.com/jw5/newplayer/player.swf",
                        divname, w, h, "8", null, flashvars, params, attributes);

}

function playerReady(obj)
      {
	player = document.getElementById(obj.id);
	addListeners();
}


function addListeners() {
	if (player) { 
		player.addModelListener("STATE", "stateMonitor");
	} else {
		setTimeout("addListeners()",100);
	}
}


function stateMonitor(obj)
      {
	var thestate=null;
	if ((obj.oldstate=="BUFFERING") && (obj.newstate=="PLAYING")) { playid++; var thestate="START"; }
	else if ((obj.oldstate=="PLAYING") && (obj.newstate=="COMPLETED")) { var thestate="FINISH"; }
	else { var thestate=null; }
	if (thestate=="START" || thestate=="FINISH") 
        {
		var file = player.getConfig().file;
		var playerid=obj.id;
		var videolist=player.getPlaylist();
		var videofile=player.getPlaylist()[playid].file;
		pic1.src="http://video.supercheats.com/sclytics.php?state="+thestate+"&page="+videofile+"&file="+file;
        }
      };



