/* MAIN */

/* Custom fonts */
function replaceFontType() {
	Cufon.replace('div#overStudioTxt P', { fontFamily: 'Distro' });
	Cufon.replace('div#adresTxt p', { fontFamily: 'Distro' });
	Cufon.replace('div#linkContent p', { fontFamily: 'Distro' });
	Cufon.replace('div#linkContent a', { fontFamily: 'Distro' });
	Cufon.replace('div#linkContent a:visited', { fontFamily: 'Distro' });
	Cufon.replace('div#linkContent a:active', { fontFamily: 'Distro' });
	Cufon.replace('div#gearlist1 p', { fontFamily: 'Distro' });
	Cufon.replace('div#gearlist2 p', { fontFamily: 'Distro' });
	Cufon.replace('table#Mics', {fontFamily: 'Distro' });
	Cufon.replace('h1', { fontFamily: 'Distro' });
	Cufon.replace('div#boekformForm label', { fontFamily: 'Distro' });
	Cufon.replace('form#si_contact_form1', { fontFamily: 'Distro' });
	Cufon.replace('input', { fontFamily: 'Distro' });
	Cufon.replace('textarea', { fontFamily: 'Distro' });
	Cufon.replace('#ScrollGB', { fontFamily: 'Distro' });
        Cufon.replace('#ScrollGB submit', { fontFamily: 'Distro' });

};
/* Main navigation */
$(".menu a, .newsTxt a, .overStudio, #overStudio a, #teamtxt a").live("click",function (event) {
	event.preventDefault();
});

function getAjaxContent (pageid, template) {
	$("li.aHome").unbind("click");

	$("li.aStudio, .overStudio").unbind("click");

	$("li.aProjecten, #teamtxt a").unbind("click");

	$("li.aTeam").unbind("click");
	$("li.aContact, #overStudio a").unbind("click");
	var pagedata=0;
	$("div#contentwrapper").fadeOut(400);
	$.ajax({
		url: './wp-content/themes/marmalade/ajax-'+template+'.php',
		type: 'GET',
		dataType: 'html',
		data: {id: pageid,intern: 'false'},
		cache: true,
		async: true,
		timeout: 5000,
		error: function()
		{ 
			pagedata=-1;
			return true;
		},
		success:  function(data) 
		{
			$("div#contentwrapper").html(data).stop().css("display", "block").css("opacity", "0").fadeTo(600,1, function () {
				$("li.aHome").bind("click", {intern: false}, getHome);

				$("li.aStudio, .overStudio").bind("click", {intern: false}, getStudio);

				$("li.aProjecten, #teamtxt a").bind("click", {intern: false}, getProjecten);

				$("li.aTeam").bind("click", {intern: false}, getTeam);
				$("li.aContact, #overStudio a").bind("click", {intern: false}, getContact);	
				$(this).removeAttr("style");
			});
			replaceFontType();
			fleXenv.initByClass("flexcroll");

		}

	});	
	$("li.aHome").unbind("click");
	$("li.aStudio").unbind("click");
	$("#wrapper").attr("class", "page-id-"+pageid);
	$("#Backgrounds").stop().css("opacity", "1").fadeTo(400,0.3, function () {
		$("body").attr("class", "template-"+template+"-php");	
	}).fadeTo(600,1).removeAttr("style");



}

function getHome(event) {
	var intern = event.data.intern;
	if($("#wrapper").hasClass("page-id-2")) return;	
	if(intern) {
		$("img.homeButton").die("click");
		$("img.overStudio").die("click");
		$("img.homeButton").fadeOut(600);
		$("div#Home").fadeOut(600,function() { 
			$.ajax({
				url: './wp-content/themes/marmalade/ajax-home.php',
				type: 'GET',
				dataType: 'html',
				data: {id: '2', intern: 'true'},
				cache: true,
				async: true,
				timeout: 10000,
				error: function(){ return true;},
				success: function(data) {
					$('#Home').html(data);
					$('#Home').fadeIn(400, function (){
						$("#wrapper").attr("class", "page-id-2");
					});
					$("img.overStudio").fadeIn(400);
					fleXenv.initByClass("flexcroll");
					replaceFontType();
				}
			});
		});		

	}
	else {
		getAjaxContent(2,'home');
	}
}


function getStudio(event) {
	var intern = event.data.intern;

	if($("#wrapper").hasClass("page-id-44")) return;
	if(intern) {
		$("img.overStudio").fadeOut('slow');
		$.ajax({
			url: './wp-content/themes/marmalade/ajax-studio.php',
			type: 'GET',
			dataType: 'html',
			data: {id: '44',intern: 'true'},
			cache: true,
			async: true,
			timeout: 10000,
			error: function(){ return true;},
			success: function(data) {
				$('#contentwrapper').append(data);
				$("div#overStudio").fadeIn('600', function (){
					$("#wrapper").attr("class", "page-id-44");
				});
				replaceFontType(); 

			}
		});
		$("img.homeButton").fadeIn(600);
		$("div#newswrapper").fadeOut(400,function() { 
			$("div#DynNews").remove();		  
		});
	}
	else {
		getAjaxContent(44, 'studio');
	}

}

function getProjecten(event) {

	if($("#wrapper").hasClass("page-id-59")) return;

	getAjaxContent(59, 'projecten');

}
function getTeam(event) {

	if($("#wrapper").hasClass("page-id-62")) return;

	getAjaxContent(62, 'team');

}
function getContact(event) {

	if($("#wrapper").hasClass("page-id-64")) return;

	getAjaxContent(64, 'contact');

}

/* Dynamic */


$("#newswrapper td.newsTitle, .newsTxt a").live("click", function () {
	//if($("#wrapper").hasClass("page-id-2")) return;	
	var id = $(this).parents("table").attr("id").substr(5);
	$.ajax({
		url: './wp-content/themes/marmalade/ajax-single.php',
		type: 'GET',
		dataType: 'html',
		data: {id: id, intern: 'true'},
		cache: true,
		async: true,
		timeout: 10000,
		error: function(){ return true;},
		success: function(data) {
			$('#singleNews .newsItem').html(data);
			$('#singleNews .newsItem').fadeIn(400, function (){
			});
			fleXenv.initByClass("flexcroll");
			fleXenv.updateScrollBars();
			replaceFontType();
		}
	});

	$("div#randompic").fadeOut(400);
	$("div#singleNews").fadeIn(600);
});

$("img#singlenewsClose").live("click", function () {
	$("div#randompic").fadeIn(600);
	$("div#singleNews").fadeOut(400);
});
$("div#menuBar img").click( function (){
	$("div#randompic").fadeIn(600);
	$("div#singleNews").fadeOut(400);
});



$("div#boekformForm form").live("submit", function () {
	$(this).attr("action", "http://www.marmalademusic.nl/contact")
})

$("span#Route").click(function() {
	$("div#RouteMap").fadeIn(600);
	$("img#MAP").fadeIn(1200);
});

$("div#RouteMap").click(function (){
	$("div#RouteMap").fadeOut(600);
});

$("div#menuBar").click(function(){
	$("div#RouteMap").fadeOut(600);
});

/* Navigation menu */

$("li.page-item-2").bind("click", {intern: false}, getHome);

$("li.page-item-44, img.overStudio").bind("click", {intern: false}, getStudio);

$("li.page-item-59").bind("click", {intern: false}, getProjecten);

$("li.page-item-62").bind("click", {intern: false}, getTeam);
$("li.page-item-64").bind("click", {intern: false}, getContact);

/* Gastenboek fader */

$("#guestheader").live("click", function () {
	$("#ScrollNews").fadeOut(600);
	$("#ScrollGB").fadeIn(600);
	
	fleXenv.initByClass("flexcroll");
	fleXenv.updateScrollBars();
        Cufon.refresh();
});

$("#guestheader h1").live("click", function () {
	$(this).css("color" , "white");
	$("#newsheader h1").css("color" , "#A56F27");
	Cufon.refresh();
});

$("#newsheader h1").live("click", function () {
	$(this).css("color" , "white");
	$("#guestheader h1").css("color" , "#A56F27");
	Cufon.refresh();
});

$("#newswrapper h1").click( function () {
	$(".hActive").addClass("hClick");
	$(".hActive").removeClass("hActive");
	
	$(this).addClass("hActive");
	$(this).removeClass("hClick");
	Cufon.refresh();
});

$("#newsheader").live("click", function () {
	$("#ScrollNews").fadeIn(600);
	$("#ScrollGB").fadeOut(600);
	
	fleXenv.initByClass("flexcroll");
	fleXenv.updateScrollBars();
});


$("#newsheader h1, #guestheader h1").hover(function () {	
	$(this).addClass("hHover");
	Cufon.refresh();
	} , function () {
	$(this).removeClass("hHover");
	Cufon.refresh();
});


/* Studio Map */
$("#mapImg").live("click", function ()  {
	$("div#BGstudiomap").fadeIn(800);
	$("div#studiomap1wrapper").fadeIn(800);

	$("#fotoImg").fadeIn(800);
	$("#etageImg").fadeIn(500);
	$("#gearImg").fadeIn(800);
	$("#mapImg").fadeOut(800);
	$("#fotoImg2").fadeOut(800);
	$("#overStudio").fadeOut(800);

	$("div#BGstudio").fadeOut(800);
	$("div#BGstudio1").fadeOut(800);
	$("div#BGstudio2").fadeOut(800);
	$("div#BGstudio3").fadeOut(800);
	$("div#BGstudio4").fadeOut(800);
	$("div#studiotxtBG").css("background-image", "none");

	$("div.thumb").fadeOut(800);

	$("div#studiotxtBG h1").fadeOut(800);
	$("div#studiotxt p").fadeOut(800);
	$("div#studiotxt1").fadeOut(800);
	$("div#studiotxt2").fadeOut(800);
	$("div#studiotxt3").fadeOut(800);
	$("div#studiotxt4").fadeOut(800);
	$("#SelectFoto").fadeOut(800);
	$("div#DynGearlist").fadeOut(600);
});

$("div#studiomapStudio1").live("click", function ()  {
	$("div#studiomapStudio1active").fadeIn(600);
	$("div#studiomapStudio2active").fadeOut(600);
	$("div#studiomapOpname1active").fadeOut(600);
	$("div#studiomapOpname2active").fadeOut(600);
	$("div#studiomapOpname3active").fadeOut(600);

	$("div#BG_studio1").fadeIn(900);
	$("div#BG_studio2").fadeOut(900);
	$("div#BG_opname1").fadeOut(900);
	$("div#BG_opname2").fadeOut(900);
	$("div#BG_opname3").fadeOut(900);
	$("div#BGstudiomap").fadeOut(900);
});

$("div#studiomapStudio2").live("click", function ()  {
	$("div#studiomapStudio1active").fadeOut(600);
	$("div#studiomapStudio2active").fadeIn(600);
	$("div#studiomapOpname1active").fadeOut(600);
	$("div#studiomapOpname2active").fadeOut(600);
	$("div#studiomapOpname3active").fadeOut(600);

	$("div#BG_studio1").fadeOut(900);
	$("div#BG_studio2").fadeIn(900);
	$("div#BG_opname1").fadeOut(900);
	$("div#BG_opname2").fadeOut(900);
	$("div#BG_opname3").fadeOut(900);
	$("div#BGstudiomap").fadeOut(900);
});

$("div#studiomapOpname1").live("click", function ()  {
	$("div#studiomapStudio1active").fadeOut(600);
	$("div#studiomapStudio2active").fadeOut(600);
	$("div#studiomapOpname1active").fadeIn(600);
	$("div#studiomapOpname2active").fadeOut(600);
	$("div#studiomapOpname3active").fadeOut(600);

	$("div#BG_studio1").fadeOut(900);
	$("div#BG_studio2").fadeOut(900);
	$("div#BG_opname1").fadeIn(900);
	$("div#BG_opname2").fadeOut(900);
	$("div#BG_opname3").fadeOut(900);
	$("div#BGstudiomap").fadeOut(900);
});

$("div#studiomapOpname2").live("click", function ()  {
	$("div#studiomapStudio1active").fadeOut(600);
	$("div#studiomapStudio2active").fadeOut(600);
	$("div#studiomapOpname1active").fadeOut(600);
	$("div#studiomapOpname2active").fadeIn(600);
	$("div#studiomapOpname3active").fadeOut(600);

	$("div#BG_studio1").fadeOut(900);
	$("div#BG_studio2").fadeOut(900);
	$("div#BG_opname1").fadeOut(900);
	$("div#BG_opname2").fadeIn(900);
	$("div#BG_opname3").fadeOut(900);
	$("div#BGstudiomap").fadeOut(900);
});

$("div#studiomapOpname3").live("click", function ()  {
	$("div#studiomapStudio1active").fadeOut(600);
	$("div#studiomapStudio2active").fadeOut(600);
	$("div#studiomapOpname1active").fadeOut(600);
	$("div#studiomapOpname2active").fadeOut(600);
	$("div#studiomapOpname3active").fadeIn(600);

	$("div#BG_studio1").fadeOut(900);
	$("div#BG_studio2").fadeOut(900);
	$("div#BG_opname1").fadeOut(900);
	$("div#BG_opname2").fadeOut(900);
	$("div#BG_opname3").fadeIn(900);
	$("div#BGstudiomap").fadeOut(900);
});

$("#etageImg").live("click", function () {
	$("div#studiomap1wrapper").fadeOut(800);
	$("#etageImg").fadeOut(800);
	$("#bgImg").fadeIn(800);
	$("div#studiomap2wrapper").fadeIn(800);
	$("div#DynGearlist").fadeOut(600);
});

$("#bgImg").live("click", function ()  {
	$("div#studiomap2wrapper").fadeOut(800);
	$("#bgImg").fadeOut(800);
	$("#etageImg").fadeIn(800);
	$("div#studiomap1wrapper").fadeIn(800);
	$("div#DynGearlist").fadeOut(600);
});

$("#fotoImg").live("click", function () {
	$("div#BGstudio").fadeIn(800);
	$("div.thumb").fadeIn(800);
	$("#mapImg").fadeIn(800);
	$("#SelectFoto").fadeIn(800);
	$("#overStudio").fadeIn(800);
	fleXenv.initByClass("flexcroll");
	fleXenv.updateScrollBars()

	$("div.studiomapAll").fadeOut(800);
	$("#fotoImg").fadeOut(800);
	$("#bgImg").fadeOut(800);
	$("#etageImg").fadeOut(800);
	$("#fotoImg2").fadeOut(800);
	$("#BGgear").fadeOut(800);
	$("div#studiotxtBG").css("background-image", "url(./wp-content/themes/marmalade/images/studioBG.png)");
	$("div#DynGearlist").fadeOut(600);
});

$("#fotoImg2").live("click", function () {
	$("div#BGstudio").fadeIn(800);
	$("div.thumb").fadeIn(800);
	$("#mapImg").fadeIn(800);
	$("#SelectFoto").fadeIn(800);
	$("#gearImg").fadeIn(800);
	$("#overStudio").fadeIn(800);
	fleXenv.initByClass("flexcroll");
	fleXenv.updateScrollBars()
	$("div#studiotxtBG").css("background-image", "url(./wp-content/themes/marmalade/images/studioBG.png)");

	$("div.studiomapAll").fadeOut(800);
	$("#fotoImg").fadeOut(800);
	$("#bgImg").fadeOut(800);
	$("#etageImg").fadeOut(800);
	$("#fotoImg2").fadeOut(800);
	$("#BGgear").fadeOut(800);
	$("div#DynGearlist").fadeOut(600);
});

/* Studio */

$(".thumb").live("click", function() {
	  $("#overStudioTxt").slideUp(600);
	  $("img.showOverStudio").fadeIn(400);
});

$("img.showOverStudio").live("click", function () {
	  $("#overStudioTxt").slideDown(600);
	  $(this).fadeOut(400);
});

$("div#studiopic1 img").live("click", function ()  {
	  $("div#BGstudio1").fadeIn(800);
	  $("div#studiotxt1").fadeIn(800);
	  
	  $("div#BGstudio").fadeOut(800);
	  $("div#BGstudio2").fadeOut(800);
	  $("div#BGstudio3").fadeOut(800);
	  $("div#BGstudio4").fadeOut(800);
	  
	  $("div#studiotxtBG #SelectFoto").fadeOut(800);
	  $("div#studiotxt2").fadeOut(800);
	  $("div#studiotxt3").fadeOut(800);
	  $("div#studiotxt4").fadeOut(800);
	});
	
	$("div#studiopic2").live("click", function ()  {
	  $("div#BGstudio2").fadeIn(800);
	  $("div#studiotxt2").fadeIn(800);
	  
	  $("div#BGstudio").fadeOut(800);
	  $("div#BGstudio1").fadeOut(800);
	  $("div#BGstudio3").fadeOut(800);
	  $("div#BGstudio4").fadeOut(800);
	  
	  $("div#studiotxtBG #SelectFoto").fadeOut(800);
	  $("div#studiotxt1").fadeOut(800);
	  $("div#studiotxt3").fadeOut(800);
	  $("div#studiotxt4").fadeOut(800);
	});
	
	$("div#studiopic3").live("click", function ()  {
	  $("div#BGstudio3").fadeIn(800);
	  $("div#studiotxt3").fadeIn(800);
	  
	  $("div#BGstudio").fadeOut(800);
	  $("div#BGstudio2").fadeOut(800);
	  $("div#BGstudio1").fadeOut(800);
	  $("div#BGstudio4").fadeOut(800);
	  
	  $("div#studiotxtBG #SelectFoto").fadeOut(800);
	  $("div#studiotxt2").fadeOut(800);
	  $("div#studiotxt1").fadeOut(800);
	  $("div#studiotxt4").fadeOut(800);
	});
	
	$("div#studiopic4").live("click", function ()  {
	  $("div#BGstudio4").fadeIn(800);
	  $("div#studiotxt4").fadeIn(800);
	  
	  $("div#BGstudio").fadeOut(800);
	  $("div#BGstudio2").fadeOut(800);
	  $("div#BGstudio3").fadeOut(800);
	  $("div#BGstudio1").fadeOut(800);
	  
	  $("div#studiotxtBG #SelectFoto").fadeOut(800);
	  $("div#studiotxt2").fadeOut(800);
	  $("div#studiotxt3").fadeOut(800);
	  $("div#studiotxt1").fadeOut(800);
	});

	$("#mapImg").live("click", function ()  {
	  $("div.StudActive").fadeOut (300);
	  $("#BGgear").fadeOut(600);	});
	
	$("#bgImg").live("click", function ()  {
	  $("div.StudActive").fadeOut (300);
	});

//Gearlist	
	$("#gearImg").live("click", function ()  {
	  $("#BGgear").fadeIn(800);
	  $("#fotoImg2").fadeIn(800);
	  $("#mapImg").fadeIn(800);
	  $("div#DynGearlist").fadeIn(600);
	  fleXenv.initByClass("flexcroll");
	  
	  $("#gearImg").fadeOut(800);
	  $("#fotoImg").fadeOut(800);
	  $("#etageImg").fadeOut(800);
	  $("#bgImg").fadeOut(800);
	  $("#overStudio").fadeOut(800);
	  
	  $("div.studiomapAll").fadeOut(800);
	  $("div.studioPic").fadeOut(800);
	  $("div.thumb").fadeOut(800);
	  $("div.txtbox").fadeOut(800);
	  $("#SelectFoto").fadeOut(800);
	  $("div#studiotxtBG").css("background-image", "none");  
	});
	
	/* Background fading */
	// Background Image Fader Script by James Brocklehurst 2010
	// Licensed under the MIT License:
	// http://www.opensource.org/licenses/mit-license.php

	// For full instructions visit http://www.mightymeta.co.uk/blog/

	// Version 0.0.1

	//Configuration:

	var selector = ".menu li a"; // CSS Selector/s for element/s you want to apply fade effect to.
	var hoverOverSpeed = "500"; // Hover over fade speed (in milliseconds)
	var hoverOutSpeed = "300"; // Hover out fade speed (in milliseconds)

	// Start JQuery


	// Background Opacity Plugin by Nick Obrien (http://www.nickobrien.nl)

	(function($){
		jQuery.fn.backOpacity = function(settings){
			// Default and argument settings
			settings = jQuery.extend({background: '#000000', opacity: 0.5}, settings);

			// Loop through each element given and add an opacity element
			jQuery(this).each(function(intIndex){
				// For fixing background element's positions/sizes these variables are needed
				var pt = parseInt($(this).css('paddingTop'));
				var pb = parseInt($(this).css('paddingBottom'));
				var pl = parseInt($(this).css('paddingLeft'));
				var pr = parseInt($(this).css('paddingRight'));
				var fixedleft = parseInt($(this).css('marginLeft'));
				var fixedright = parseInt($(this).css('marginRight'));
				
				// Element offset width
				var parentow = $(this).width();

				// Fixed variables
				var fixedwidth, fixedheight, fixedleft, fixedright = 0;
				// Calculate fixing positions/sizes
				fixedwidth = parentow + pl + pr;
				fixedheight = $(this).height() + pt + pb;

				// Add background element
				$(document.createElement('div')).width(fixedwidth).height(fixedheight).css({backgroundColor:settings.background, opacity:settings.opacity, position:'relative', marginLeft:fixedleft+'px', marginRight:fixedright+'px', left:0, top:0, bottom:0, zIndex:((10)+intIndex*10)}).insertAfter($(this));

				// Set positions for the content element
				$(this).css({width: parentow, position:'absolute', zIndex:((20)+intIndex*20)});
			});

			// Return
			return jQuery;
		};
	})(jQuery);


	// Animate Fade Effects
		
		$(selector).css({background:'none'}); //removes default CSS :hover effect

		$(selector).backOpacity({background: '#ccc', opacity: '0'}); // Initiate default background opacity
		
		$(selector).hover( 
			
			function() {
				$(this).siblings('div').stop().animate({'opacity':1},hoverOverSpeed); //fade out on hover
				$("#lamp").stop().animate({
					opacity: 1
				},hoverOverSpeed);	
			},
			
			function() {
				$(this).siblings('div').animate({'opacity':0}, hoverOutSpeed); //fade in on mouseout
				$("#lamp").stop().animate({
					opacity: 0
				},hoverOutSpeed);	
			});

	// Animate Menu on Click
		
		$(selector).click( 
			
			function() {
				$(this).siblings('div').stop().animate({opacity:1}, 300000000, function() { });
				$(selector).siblings('div').not(this).stop().animate({opacity:1}, 300000000, function() { });
			});


/* Pre load */
		(function () {
			// counter
			var i = 0;

			// create object
			imageObj = new Image();

			// set image list
			images = new Array();
			images[0]="wp-content/themes/marmalade/images/background/image85.jpg";
			images[1]="wp-content/themes/marmalade/images/background/image81.jpg";
			images[2]="wp-content/themes/marmalade/images/background/image87.jpg";
			images[3]="wp-content/themes/marmalade/images/background/image84.jpg";
			images[4]="wp-content/themes/marmalade/images/background/image191.jpg";
			images[5]="wp-content/themes/marmalade/images/background/image194.jpg";
			images[6]="wp-content/themes/marmalade/images/background/image189.jpg";
			images[7]="wp-content/themes/marmalade/images/background/image90.jpg";
			images[8]="wp-content/themes/marmalade/images/background/image91.jpg";
			


				// start preloading
				for(i=0; i<=8; i++) 
				{
					imageObj.src=images[i];
				}
		})();

		// 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.appName.indexOf ("Microsoft") !=-1) return window[movieName];
			  else return document[movieName];
			}
		};

		function niftyplayer(name)
		{
			this.obj = FlashHelper.getMovie(name);

			if (!FlashHelper.movieIsLoaded(this.obj)) return;

			this.play = function () {
				this.obj.TCallLabel('/','play');
			};

			this.stop = function () {
				this.obj.TCallLabel('/','stop');
			};

			this.pause = function () {
				this.obj.TCallLabel('/','pause');
			};

			this.playToggle = function () {
				this.obj.TCallLabel('/','playToggle');
			};

			this.reset = function () {
				this.obj.TCallLabel('/','reset');
			};

			this.load = function (url) {
				this.obj.SetVariable('currentSong', url);
				this.obj.TCallLabel('/','load');
			};

			this.loadAndPlay = function (url) {
				this.load(url);
				this.play();
			};

			this.getState = function () {
				var ps = this.obj.GetVariable('playingState');
				var ls = this.obj.GetVariable('loadingState');

				// returns
				//   'empty' if no file is loaded
				//   'loading' if file is loading
				//   'playing' if user has pressed play AND file has loaded
				//   'stopped' if not empty and file is stopped
				//   'paused' if file is paused
				//   'finished' if file has finished playing
				//   'error' if an error occurred
				if (ps == 'playing')
					if (ls == 'loaded') return ps;
					else return ls;

				if (ps == 'stopped')
					if (ls == 'empty') return ls;
					if (ls == 'error') return ls;
					else return ps;

				return ps;

			};

			this.getPlayingState = function () {
				// returns 'playing', 'paused', 'stopped' or 'finished'
				return this.obj.GetVariable('playingState');
			};

			this.getLoadingState = function () {
				// returns 'empty', 'loading', 'loaded' or 'error'
				return this.obj.GetVariable('loadingState');
			};

			this.registerEvent = function (eventName, action) {
				// eventName is a string with one of the following values: onPlay, onStop, onPause, onError, onSongOver, onBufferingComplete, onBufferingStarted
				// action is a string with the javascript code to run.
				//
				// example: niftyplayer('niftyPlayer1').registerEvent('onPlay', 'alert("playing!")');

				this.obj.SetVariable(eventName, action);
			};

			return this;
		}

