// Script for NiftyPlayer 1.7, by tvst from varal.org
// Released under the MIT License: http://www.opensource.org/licenses/mit-license.php

var FlashHelper ={
	movieIsLoaded : function (theMovie){
		if (typeof(theMovie) != "undefined") return theMovie.PercentLoaded() == 100;
		else return
		false;
	},
	getMovie : function (movieName){
  	if (navigator.appVersion.indexOf('MSIE 6') != -1 || navigator.appVersion.indexOf('MSIE 7') != -1 || navigator.appVersion.indexOf('MSIE 8') != -1)  return window[movieName];
	  else return document[movieName];
	}
};
 
function ajaxRequest(openThis, id) {
	var AJAX = null;
	if (window.XMLHttpRequest) {
		AJAX=new XMLHttpRequest();
	} else {
		AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX == null) {                                         
		return false;
	}
	AJAX.onreadystatechange = function() {
		if (AJAX.readyState == 4 || AJAX.readyState == "complete") {
			//alert(AJAX.responseText, AJAX.status, id);
		}else{
			//document.getElementById(id).innerHTML = 'Laddar...<br />'; 
		} 
	}
	var url=openThis;
	AJAX.open("GET", url, true);
	AJAX.send(null); 
} 

function niftyplayer(name){
	this.obj = FlashHelper.getMovie(name);

	if (!FlashHelper.movieIsLoaded(this.obj)) return;

	this.play = function (id, btn_id, acc_id) {
		var btn = document.getElementById(btn_id);
		if(btn.className == 'play_btn play'){
			btn.className = 'play_btn pause';
			this.obj.TCallLabel('/','play');
			ajaxRequest('../includes/update_playcount.php?id='+acc_id, 'play_info');
		}else{
			btn.className = 'play_btn play';
			this.obj.TCallLabel('/','pause');
		}
	};

	this.registerEvent = function (eventName, action) {
		this.obj.SetVariable(eventName, action);
	};

	return this;
}

