// flash detection?
var hasFlash = true;
var iVidIDAutoplay = 0;
var mediaPage = new Array(); // the page the media sits on for pagination reinit to the current page.

function popWin(url,winname,w,h,scroll){
    var LeftPosition = (screen.width)?(screen.width-w)/2:100;
    var TopPosition = (screen.height)?(screen.height-h)/2:100;
    settings = 'width='+ w +',height='+ h +',top='+ TopPosition +',left='+ LeftPosition +',scrollbars='+ scroll +',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
    win = window.open(url, winname, settings);
    win.focus();
}

function newImage(arg) {
    if (document.images) {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}

function chgImg() {
    if (document.images && (preloadflag == true)) {
        for (var i=0; i<chgImg.arguments.length; i+=2) {
            document[chgImg.arguments[i]].src = chgImg.arguments[i+1];
            //alert(chgImg.arguments[i]);
        }
    }
}

function charCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) { // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
    } else { // otherwise, update 'characters left' counter
        countfield.innerHTML = maxlimit - field.value.length;
    }
}

var preloadflag = false;

function preload() {
    lnav1 = newImage("imgs/btn/but_a1_on.gif");
    lnav2 = newImage("imgs/btn/but_a2_on.gif");
    lnav3 = newImage("imgs/btn/but_a3_on.gif");
    preloadflag = true;
}

function validateForm(oForm){
    var o = new Object;
    o.bResult = true;
    o.sAlert = "";
    
    o=valNotNullField(oForm.media_user1,"You need to enter your name.\n",o);
    o=valNotNullField(oForm.media_user2,"You need to enter your age.\n",o);
    o=valNotNullField(oForm.media_user3,"You need to enter your email address.\n",o);
    o=valNotNullField(oForm.media_user4,"You need to enter your parents email address.\n",o);
    o=valNotNullField(oForm.media_user5,"You need to enter your street.\n",o);
    o=valNotNullField(oForm.media_user6,"You need to enter your city.\n",o);
    o=valNotNullField(oForm.media_user7,"You need to enter your state.\n",o);
    o=valNotNullField(oForm.media_user9,"You need to enter your postcode.\n",o);
    o=valNotNullField(oForm.media_user10,"You need to enter your band / group name.\n",o);
    
    
    o=valNotNullField(oForm.title,"You need to enter your song name.\n",o);
    o=valNotNullField(oForm.description,"You need to enter a description.\n",o);
    o=checkExtenstion(oForm.filename_file,"You need to upload the correct file type. These types include: mpg, mpeg, avi, mov, wmv, flv, 3gp, a4a\n",o,'mpg,mpeg,avi,mov,wmv,flv,3gp,a4a');
    o=valIsChecked(oForm.tandc,"You need to agree to the Terms and Conditions.\n",o);  
    
    //o=valNotNullField(oForm.njvm_user1,"You need to enter your name.\n",o);
    //o=valNotNullField(oForm.njvm_user2,"You need to enter your contact number.\n",o);
    //o=valNotNullField(oForm.njvm_user3,"You need to select your city.\n",o);
    //o=valIsChecked(oForm.parents_perm,"You need to get your parent or guardian's permission.\n",o);
    //o=valNotNullField(oForm.title,"You need to create a Cool Trick Name.\n",o);
    //o=valNotNullField(oForm.description,"You need to enter a description.\n",o);
    //o=checkExtenstion(oForm.filename_file,"You need to upload the correct file type. These types include: mpg, mpeg, avi, mov, wmv, flv, 3gp, a4a\n",o,'mpg,mpeg,avi,mov,wmv,flv,3gp,a4a');
    //o=valIsChecked(oForm.tandc,"You need to agree to the Terms and Conditions.\n",o);

    if (!o.bResult) alert(o.sAlert);
    return o.bResult;
}

function submitForm(oForm){
    if(validateForm(oForm)){
        oForm.submit();
    }
}

function onSubmitHandler(oForm){
  submitForm(oForm);
  return false;
}

var xml; var xmltype; var opt;

function loadXMLDoc(url, funcCallback) {
    if (window.ActiveXObject) {
        xml = new ActiveXObject("Microsoft.XMLHTTP");
        if (xml) {
            xml.onreadystatechange = funcCallback;
            xml.open("GET", url, true);
            xml.send();
        }
    }else if (window.XMLHttpRequest) {
        xml = new XMLHttpRequest();
        xml.onreadystatechange = funcCallback;
        xml.open("GET", url, true);
        xml.send(null);
    }
}

function loadXMLDoc2(url, funcCallback) {
    if (window.ActiveXObject) {
        xml2 = new ActiveXObject("Microsoft.XMLHTTP");
        if (xml) {
            xml2.onreadystatechange = funcCallback;
            xml2.open("GET", url, true);
            xml2.send();
        }
    }else if (window.XMLHttpRequest) {
        xml2 = new XMLHttpRequest();
        xml2.onreadystatechange = funcCallback;
        xml2.open("GET", url, true);
        xml2.send(null);
    }
}

function processXML() {
    if (xml.readyState == 4) {
        if (xml.status == 200) {
            processList();
        } else {
            //alert(xml.statusText);
            alert("Sorry, there was a problem loading the video list! Please try again later.\n" + xml.statusText);
        }
    }
}
function binXML(){
}

var hAnchor = '';
var hMouseOut = '';
var cID;
var PageID;



// HBX Function to call when changing sections within TurboNick
function StatCallPage(cID) {

  switch(cID) {
    case 1:
      DSTAPI_Proxy.call({sUrl: 'TurboNick/Nick_Picks'});
      break;
    case 2:
      DSTAPI_Proxy.call({sUrl: 'TurboNick/Nick_Shows'});
      break;
    case 3:
      DSTAPI_Proxy.call({sUrl: 'TurboNick/Sarvo_Vision'});
      break;
    case 4:
      DSTAPI_Proxy.call({sUrl: 'TurboNick/Nick_Shorts'});
      break;
    case 5:
      DSTAPI_Proxy.call({sUrl: 'TurboNick/UNick'});
      break;
    case 6:
      DSTAPI_Proxy.call({sUrl: 'TurboNick/Category6'});
      break;
  }
}

function change(cID){
    // checks to see that we are on the index page
    var sPg = document.location.href;
    if(sPg.indexOf("upload") > 0 || sPg.indexOf("save") > 0){
        document.location.href = 'index.php?cID='+cID;
    }

	  /* 2007-01-12: Set the global PageID to that of the cID.
	   * Used to track the current page section that the user is in.
	   */
	  PageID = cID;

    //alert('hAnchor' + hAnchor);

	  // JM - Call the HBX tracker
	  StatCallPage(PageID);

    // button holding and swapping, complex for such a simple thing
    sURL = "?cID="+cID;
    imgFolder = "";

    if(hAnchor != ''){
        document.getElementById(hAnchor).onmouseout = hMouseOut;
        //switch to check if the variable button is used
        if (hAnchor == "a6" || hAnchor == "a7" ){

            window.location.href = sURL;

           //chgImg('n'+ hAnchor, 'imgs/btn/but_' + hAnchor + '_off.gif');
        } else {

            if (cID == 6 || cID == 7){
                window.location.href = sURL;
            } else {
                //chgImg('n'+ hAnchor, 'imgs/btn/but_' + hAnchor + '_off.gif');
            }

        }
    } else {
        //chgImg('na' + cID, 'imgs/btn/but_a' + cID + '_on.gif');
    	if ( document.getElementById('a'+cID) ) {
    		hAnchor = 'a' + cID;
    		hMouseOut = document.getElementById('a' + cID).onmouseout;
    	}
    }

    /*  --------------------        */

    // save the existing functions in the global var's
    hAnchor = 'a' + cID;
    if ( document.getElementById('a'+cID) ) {
    	hMouseOut = document.getElementById('a'+cID).onmouseout;
        // set the mouse out to nothing
        document.getElementById('a'+cID).onmouseout = '';
    }
    

    document.getElementById('video-playlist').innerHTML = 'Loading ...';
    loadXMLDoc('_dynamic/media_' + cID + '.xml', processXML);

    elTI = document.getElementById("tunein");
    elUTI = document.getElementById("unick_tunein");
    elCAT6 = document.getElementById("cat06_tunein");
    if (cID == 5) {
        if(elTI)    elTI.style.display  = 'none';
        if(elUTI) elUTI.style.display = 'block';
        if(elCAT6) elCAT6.style.display = 'none';
    } else if(cID == 6) {
        if(elTI)    elTI.style.display  = 'none';
        if(elUTI) elUTI.style.display = 'none';
        if(elCAT6) elCAT6.style.display = 'block';
    } else {
        if(elTI)    elTI.style.display  = 'block';
        if(elUTI) elUTI.style.display = 'none';
        if(elCAT6) elCAT6.style.display = 'none';
    }

    // Now tag the category page here: http://.../turbonick/log.php?c="+iCatID+"&r="+Math.floor(Math.random()*999) )
    // throw away the xml response
    //TODO; removed for static Ads loadAds(cID);
    loadXMLDoc2("log.php?c="+cID+"&r="+Math.floor(Math.random()*999), binXML);
}
/**
* Loads the TILE ad
*/
function loadAds(cID) {
  //alert("HTML GOING IN:"+document.getElementById('ad_changer').innerHTML);
   //url = "http://ad.au.doubleclick.net/adi/mcn.nickelodeon.com.au/nickjr_video;dcopt=ist;sz=180x145;ord="+adOrd+"?";
   //window.frames['ad_iframe'].location = url;
   //document.getElementById('ad_changer').innerHTML = "<script language='JavaScript' src='http://ad.au.doubleclick.net/adj/mcn.nickelodeon.com.au/turbo"+append+";dcopt=ist;sz=180x145;ord="+adOrd+"?' type='text/JavaScript'></script><noscript><a href='http://ad.au.doubleclick.net/jump/mcn.nickelodeon.com.au/turbo"+append+";sz=180x145;ord="+adOrd+"?' target='_blank'> <img src='http://ad.au.doubleclick.net/ad/mcn.nickelodeon.com.au/turbo"+append+";sz=180x145;ord="+adOrd+"?' width='180' height='145' border='0' alt='Tempest Media' /></a></noscript>"
   // ENABLE THE USE OF THE NEW API FUNCTIONALITY /export/www/html/inc/nickadapi.php
}

// flag we want to auto play this video when the category has loaded.
function autoplay(iVidID){
    iVidIDAutoplay = iVidID;
}

var skinStyle;

function processList( sortOrder ) {
	if ( !sortOrder ) { sortOrder = 'latest' }
	//sortOrder = 'highest_rated';
    var out = '';
    var ldiv = document.getElementById("video-playlist");

    var media = xml.responseXML.getElementsByTagName("media");
    
    // check if section is CAT6
    //if (hAnchor == "a6"){
    //    skinStyle = "-cat06";
    //} else {
        skinStyle = "";
    //}
   
    var newMedia = new Array();
    if ( sortOrder == 'highest_rated' ) {
    	var mediaContent = new Array();
    	for (var i = (media.length-1); i >= 0; i--) {
    		mediaContent[media[i].childNodes[0].firstChild.nodeValue] = new Array(
    		  media[i].childNodes[0].firstChild.nodeValue,
    		  media[i].childNodes[1].firstChild.nodeValue,
    		  media[i].childNodes[2].firstChild.nodeValue,
    		  media[i].childNodes[3].firstChild.nodeValue,
    		  (media[i].childNodes[6].firstChild)?media[i].childNodes[6].firstChild.nodeValue:''
    		);
    	}
    	var aIndex = new Array();
    	for ( var i = 0; i < jsHighest.length; i++ ) {
    		newMedia[i] = mediaContent[jsHighest[i]];
    		aIndex[jsHighest[i]] = true;
    	}
    	var newMediaCount = newMedia.length;
    	for (var i = 0; i < media.length; i++) {
    		if ( !aIndex[media[i].childNodes[0].firstChild.nodeValue] ) {
    			newMedia[newMediaCount] = new Array(
	    		  media[i].childNodes[0].firstChild.nodeValue,
	    		  media[i].childNodes[1].firstChild.nodeValue,
	    		  media[i].childNodes[2].firstChild.nodeValue,
	    		  media[i].childNodes[3].firstChild.nodeValue,
	    		  (media[i].childNodes[6].firstChild)?media[i].childNodes[6].firstChild.nodeValue:''
	    		);
    			newMediaCount++;
    		}
    	}
    	
    }
    else {
    	var iCount = 0;
    	for (var i = (media.length-1); i >= 0; i--) {
    		newMedia[iCount] = new Array(
    		  media[i].childNodes[0].firstChild.nodeValue,
    		  media[i].childNodes[1].firstChild.nodeValue,
    		  media[i].childNodes[2].firstChild.nodeValue,
    		  media[i].childNodes[3].firstChild.nodeValue,
    		  (media[i].childNodes[6].firstChild)?media[i].childNodes[6].firstChild.nodeValue:''
    		);
    		iCount++;
    	}
    }
    var media = newMedia;
    
    var iPage = 0;
    var iCount = 1;
	for (var i = 0; i < media.length; i++) {
		// Get the page for the media items.
		mediaPage[media[i][0]] = iPage;
		if ( iCount > 4 ) {
			iPage++;
			iCount = 0;
		}
		iCount++;
		// end getting th epage for the media items
		out += '<div id="idVideo_'+media[i][0]+'" class="video-notplaying">';
	    out += '<div class="video'+ skinStyle +'" onmouseover="this.className=\'video-on'+ skinStyle +'\';" onmouseout="this.className=\'video'+ skinStyle +'\';" ';
	    if(bGeolocationApproved){ 
	      out += 'onclick="loadmedia(' + media[i][0] + ');"';
	    } else {
	    	
	      out += 'onclick="alert(\'Sorry, you must be a resident of Australia to view this content.\');"';
	    }
	    out += '>';
			  
	    out += '<div class="video-holder">';
				out += '<div class="vid-player-overlay">' + '</div>';
	    out += '<img src="' + media[i][3] + '" width="72" height="60" alt="' + media[i][1] + '" />';
	    out += '<strong>' + media[i][1] + '</strong><br />';
	    out += '<p>' + media[i][4] + '</p>';
	    var iRating = 0
	    if ( jsAverage[media[i][0]] ) {
	    	iRating = jsAverage[media[i][0]];
	    }
	    out += '<div class="rating-stars"><img src="../images/ratingstars_' + iRating + '.gif" alt="Rated: ' + iRating + ' Chilli\'s" /></div>';
	    out += '</div>';
	    out += '</div>';
	    out += '</div>';
	    //out += '<div class="clear">&nbsp;</div>';
	}

    ldiv.innerHTML = out;
    VideoItems_Init();
    
    // check for autoplay
    if(iVidIDAutoplay != 0){
      loadmedia(iVidIDAutoplay);
    }
}

var pmID = '';

function noFlashOnClick() {
    if (confirm("TurboNick videos need Macromedia Flash Player 8 or above.\n\nWould you like to download and install the free Flash Player now?\n\n(If you've just downloaded and installed the player, refresh this page!)")) {
    window.open(getFlashURL, "downloadFlash", "");
    } else {
        window.alert("By clicking 'Cancel' you cannot view the video.\n\nIf you would like to view the video, please install the Flash Player!");
    }
}

/*
 * Use this function to strip out illegal characters that HBX does not accept.
 */
function HBXStrip(a)
{
     a = a.split("|").join("");
     a = a.split("&").join("");
     a = a.split("'").join("");
     a = a.split("#").join("");
     a = a.split("$").join("");
     a = a.split("%").join("");
     a = a.split("^").join("");
     a = a.split("*").join("");
     a = a.split(":").join("");
     a = a.split("!").join("");
     a = a.split("<").join("");
     a = a.split(">").join("");
     a = a.split("~").join("");
     a = a.split(";").join("");
     a = a.split(",").join("+");
     a = a.split(" ").join("+");
     return a;
}



/* 2007-01-12: JM
 * Use this function to do HBX tracking on individual video clicks.
 * Tracks videos as 'submenu' items of the section they reside in.
 */
function HBXLoadMedia(mID, label) {

  label = HBXStrip(label);

  switch(PageID) {
    case 1:
      _hbLink('//TurboNick//Nick_Picks//'+label, 'right');
      break;
    case 2:
      _hbLink('//TurboNick//Nick_Shows//'+label, 'right');
      break;
    case 3:
      _hbLink('//TurboNick//Sarvo_Vision//'+label, 'right');
      break;
    case 4:
      _hbLink('//TurboNick//Nick_Shorts//'+label, 'right');
      break;
    case 5:
      _hbLink('//TurboNick//UNick//'+label, 'right');
      break;
    case 6:
      _hbLink('//TurboNick//Category6//'+label, 'right');
      break;
  }

  //_hbSend();

}



/* XML Description...
 * media[i].childNodes[0].firstChild.nodeValue    ID
 * media[i].childNodes[1].firstChild.nodeValue    Title
 * media[i].childNodes[2].firstChild.nodeValue    Description
 * media[i].childNodes[3].firstChild.nodeValue    imgPath
 * media[i].childNodes[4].firstChild.nodeValue    MediaPath
 * media[i].childNodes[5].firstChild.nodeValue    AdTag
 * media[i].childNodes[6].firstChild.nodeValue    VideoBy
 */
function loadmedia(mID) {
    var adTag = '';

    if (hasFlash) {
        document.getElementById("videoflash").innerHTML = 'Loading ...';
        var out = '';
        var media = xml.responseXML.getElementsByTagName("media");

        for (var i=0; i<media.length; i++) {
            if(media[i].childNodes[0].firstChild.nodeValue == mID){
                pmID = i;
                break;
            }
        }

        // now playing
        var idMedia = media[i].childNodes[0].firstChild.nodeValue;
        if ( mediaPage[idMedia] ) {
        	VideoItems_Init( mediaPage[idMedia] );
        }
        var currentRating = 0;
    	if ( aRatings && aRatings[mID] ) {
    		currentRating = aRatings[mID][2];
    	}
        var checked = new Array();
        checked[0] = '';
    	checked[1] = '';
    	checked[2] = '';
    	checked[3] = '';
    	checked[4] = '';
    	checked[5] = '';
    	checked[currentRating] = 'checked="checked"';
    	$('.video-playing').attr('class' , 'video-notplaying');
    	document.getElementById( "idVideo_"+idMedia ).className = "video-playing";
    	
    	var ldiv = document.getElementById("video-nowplaying-holder");
        out = '<div id="video-nowpplaying" class="video-holder">';
        
        // out += '<img src="' + media[i].childNodes[3].firstChild.nodeValue + '" width="72" height="60" alt="' + media[i].childNodes[1].firstChild.nodeValue + '" />';
        out += '<strong>' + media[i].childNodes[1].firstChild.nodeValue + '</strong><br />';
        out += '<p>' + media[i].childNodes[2].firstChild.nodeValue + '</p>';
        out += '<div class="nowplaying-rating-container">';
        if ( nhLoggedIn ) {
	        	out += '<div class="nowplaying-rating loggedin">';
		        out += '<input type="radio" name="nowplayingrating" value="1" class="nowplaying-ratingstars" '+checked[1]+' />';
		        out += '<input type="radio" name="nowplayingrating" value="2" class="nowplaying-ratingstars" '+checked[2]+' />';
		        out += '<input type="radio" name="nowplayingrating" value="3" class="nowplaying-ratingstars" '+checked[3]+' />';
		        out += '<input type="radio" name="nowplayingrating" value="4" class="nowplaying-ratingstars" '+checked[4]+' />';
		        out += '<input type="radio" name="nowplayingrating" value="5" class="nowplaying-ratingstars" '+checked[5]+' />';
		        out += '</div>';
		    
		   
        }
        else {
        	out += '<div class="nowplaying-rating loggedout"><a href="../../nickname/login.php"></a></div>';
        }
        out += '</div>';
        out += '</div>';
        ldiv.innerHTML = out;

        // write the flash object
        var mdiv = document.getElementById("videoflash");

		    // ********************************************
		    // 2007-01-12: JM
		    // send out a HBX tracker packet to track viewing of the media clip
		    // media[i].childNodes[4].firstChild.nodeValue == mediapath
		    HBXLoadMedia(mID, media[i].childNodes[4].firstChild.nodeValue)
		    // ********************************************

        out = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
        out += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
        out += 'width="416" height="360" id="MediaPlayer" align="top">';
        // ********************************************
        out += '<param name="movie" value="njv.swf" /><param name="quality" value="high" /><param name="FlashVars" value="iVID='+media[i].childNodes[0].firstChild.nodeValue +'&media=' + media[i].childNodes[4].firstChild.nodeValue + '&window=no">';
        out += '<embed src="njv.swf" FlashVars="iVID='+media[i].childNodes[0].firstChild.nodeValue +'&media=' + media[i].childNodes[4].firstChild.nodeValue + '&window=no" quality="high" width="416" height="360" name="MediaPlayer" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        // ********************************************
        out += '</object>';

        //alert(out);

        mdiv.innerHTML = out;
        enableRating(idMedia);

    } else {
        noFlashOnClick();
    }
}

function playMediaDirect(iVID, imgPath, title, description, mediaPath){
    if (hasFlash) {
        document.getElementById("videoflash").innerHTML = 'Loading ...';
        var out = '';

        var ldiv = document.getElementById("video-nowplaying-holder");
        out = '<img src="' + imgPath + '" width="72" height="60" alt="' + title + '" />';
        out += '<strong>' + title + '</strong><br />';
        out += '<p>' + description + '</p>';
        ldiv.innerHTML = out;

        // write the flash object
        var mdiv = document.getElementById("videoflash");

        out = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
        out += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
        out += 'width="416" height="360" id="MediaPlayer" align="top">';
        // ***********************************
        out += '<param name="movie" value="njv.swf" /><param name="quality" value="high" /><param name="FlashVars" value="iVID='+iVID+'&media=' + mediaPath + '&window=no">';
        out += '<embed src="njv.swf" FlashVars="iVID='+iVID+'&media='+ mediaPath + '&window=no" quality="high" width="416" height="360" name="MediaPlayer" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        // ***********************************
        out += '</object>';

        mdiv.innerHTML = out;
    } else {
        noFlashOnClick();
    }
}

var fSize = false ;

function resizeObj(iVID, mPath, sTime) {

    var fs = window.open("" ,"fs", "toolbar=no,width=" + screen.availWidth  + ",height=" + screen.availHeight + ",status=no,resizable=yes,fullscreen=yes,scrollbars=no");

    out = '<html>';
    out += '<body>';

    out += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
    out += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
    out += 'width="100%" height="100%" id="MediaPlayer" align="top">';
    out += '<param name="movie" value="njv.swf" /><param name="quality" value="high" /><param name="FlashVars" value="iVID='+iVID+'&media='+ mPath +'&sTime=' + sTime + '&window=yes">';
    out += '<embed src="njv.swf" FlashVars="iVID='+iVID+'&media='+ mPath +'&sTime=' + sTime + '&window=yes" quality="high" width="100%" height="100%" name="MediaPlayer" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
    out += '<\/object>';

    out += '<\/body>';
    out += '<\/html>';

    fs.document.write(out);
    fs.focus();
}

function resizeBirthday() {

    var fs = window.open("" ,"fs", "toolbar=no,width=" + screen.availWidth  + ",height=" + screen.availHeight + ",status=no,resizable=yes,fullscreen=yes,scrollbars=no");

    out = '<html>';
    out += '<body>';

    out += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
    out += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
    out += 'width="100%" height="100%" id="MediaPlayer" align="top">';
    out += '<param name="movie" value="bm.swf" /><param name="quality" value="high" /><param name="FlashVars" value="window=yes">';
    out += '<embed src="bm.swf" FlashVars="window=yes" quality="high" width="100%" height="100%" name="MediaPlayer" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
    out += '<\/object>';

    out += '<\/body>';
    out += '<\/html>';

    fs.document.write(out);
    fs.focus();
}

function ShowLeaveBehind(sAdTag){
    sAdTileSource = '';
    document.getElementById("ad_tile").innerHTML = sAdTileSource;
    // ENABLE THE USE OF THE NEW API FUNCTIONALITY /export/www/html/inc/nickadapi.php

    //iOrd = Math.round(Math.random() * 999999);

    // Note you can't rewrite the javascript in javascript
    //sAdTileSource = '<img src="imgs/title_advertisement.gif" width="69" height="9"><script language="JavaScript" src="http://ad.au.doubleclick.net/adj/mcn.nickelodeon.com.au/'+sAdTag+';dcopt=ist;sz=180x145;ord='+iOrd+'?" type="text/JavaScript"></script>';
    //sAdTileSource = '<script language="JavaScript">document.write(\'<a target="_top" href="http://ad.au.doubleclick.net/click;h=v8/3479/0/0/%2a/s;49879710;0-0;0;13849733;10850-180/145;18410803/18428698/1;;~sscs=%3fhttp://www.nickelodeon.com.au"><img src="http://m1.2mdn.net/viewad/1273298/turbonick_test.gif" border=0 alt="Click here to find out more!"></a>\');</script>';

    // doubleclick iframe method
    //sAdTileSource = '<img style="padding:0px;margin:0px;" src="imgs/title_advertisement.gif" width="69" height="9" border="0" alt="Advertisement" /><iframe style="padding:0px; margin:0px;" frameborder="0" scrolling="no" width="180" height="145" src="http://ad.au.doubleclick.net/adi/mcn.nickelodeon.com.au/'+sAdTag+';dcopt=ist;sz=180x145;ord='+iOrd+'?"></iframe>';
    
    //alert('sAdTag='+sAdTag+' iOrd='+iOrd+' \nsAdTileSource='+sAdTileSource);
    //document.getElementById("ad_tile").innerHTML = sAdTileSource;
}

function recordRating(mID,rating,idRecord) {
	loadXMLDoc2("log.php?v="+mID+"&vr="+rating+"&oid="+idRecord+"&r="+Math.floor(Math.random()*999), binXML);
}
function enableRating(mID) {
//	return;
	$('.nowplaying-ratingstars').rating({
		required: true,
		callback: function(value, link){
		  //alert(value +' | '+ mID);
		  var idRecord = 0;
		  if ( !aRatings[mID] ) {
			  aRatings[mID] = new Array( 0 , mID , value );
		  }
		  if ( aRatings[mID] ) {
			aRatings[mID][2] = value;
			idRecord = aRatings[mID][0];
		  }
		  recordRating( mID , value , idRecord );
		  showThanks(mID);
		  
		}
	});
}
function showThanks(mID) {
	var oldContent = $('.nowplaying-rating-container').text();
	$('.nowplaying-rating-container').html( '<div class="nowplaying-rating-thanks" style="padding-left: 120px;padding-top: 40px;"><img src="imgs/thankyou.jpg" alt="" /></div>' );
	setTimeout( "loadmedia("+mID+");" , 5000 );
}

