/************************************************\
 *              Musicbox Player                *
\************************************************/
// Debug Messages
document.playerdebug = 0;
var mouseX=null;var mouseY=null;
var pic2="";
var songid2="";
function Player() {
	this.debug = p_debug;
	this.pstatus = p_current_status;
	this.playercode_nn =   function (url) { return '<EMBED TYPE="audio/x-pn-realaudio-plugin" NAME="RAPlayer" '
				+ 'SRC="' + url + '" WIDTH="0" HEIGHT="0" CONSOLE="_master" '
				+ 'CONTROLS="PositionField" NOLABELS="TRUE" AUTOSTART="true">' };
	this.playercode_ie =   function (url) { return '<OBJECT ID="RAPlayer" CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" '
				+ 'WIDTH=1 HEIGHT=1>'
				+ "\n" + '<PARAM NAME="SRC" VALUE="' + url + '">'
				+ "\n" + '<PARAM NAME="CONSOLE" VALUE="one">'
				+ "\n" + '<PARAM NAME="CONTROLS" VALUE="PositionField">'
				+ "\n" + '<PARAM NAME="NOLABELS" VALUE="TRUE">'
				+ "\n" + '<PARAM NAME="AUTOSTART" VALUE="true">'
				+ "\n" + '</OBJECT>' };
	this.findplayer = function () {
			switch(navigator.family) {
				case 'nn4':
					if ( document.RAPlayer )
						return document.RAPlayer;
				break;
				case 'ie4':
					if ( RAPlayer )
    	  					return RAPlayer;
				break;
				case 'gecko':
					if ( document.RAPlayer )
						return document.RAPlayer;
				break;

				case 'opera':
					if ( document.RAPlayer )

						return document.RAPlayer;

				break;

				case 'safari':
					if ( RAPlayer )

    	  					return RAPlayer;

				break;
			}
			this.debug("Failed to Find Player, unknown browser! " + navigator.family,1);
		};
	this.writeplayer = function (url) {
			w_done = 0;
			switch(navigator.family) {
				case 'nn4':
					document.open();
					document.write(this.playercode_nn(url));
					document.close();
					w_done = 1;
				break;
				case 'ie4':
    	  				document.write(this.playercode_ie(url));
    	  				w_done = 1;
				break;
				case 'gecko':
					document.write(this.playercode_nn(url));
					w_done = 1;
				break;

				    case 'opera':
					document.open();

					document.write(this.playercode_nn(url));

					document.close();

					w_done = 1;

				break;

				 case 'safari':
					document.open();

					document.write(this.playercode_nn(url));

					document.close();

					w_done = 1;

				break;
			}
			if ( w_done == 1 ) {
				this.debug("Wrote Player");
			} else {
				this.debug("Failed to Write Player, unknown browser! " + navigator.family,1);
			}
			this.player = this.findplayer();
			if (this.player)
				this.debug("Player Write Success");
	};
	this.checkplayer = function () {
				methods = new Array("CanPlayPause","CanPause","CanPlay",
						    "CanStop","DoNextEntry","DoPlayPause"
						    ,"DoPause","DoPlay","DoPrevEntry"
						    ,"DoStop","GetAuthor","GetBufferingTimeElapsed"
						    ,"GetBufferingTimeRemaining", "GetCanSeek"
						    ,"GetCopyright","GetLength","GetMute"
						    ,"GetPlayState","GetPosition","GetShuffle"
						    ,"HasNextEntry","HasPrevEntry","SetMute"
						    ,"SetShuffle","SetSource","SetVolume","GetVolume");
				if ( navigator.family == 'nn4' || navigator.family == 'gecko' ) {
					if ( this.player ) {
						w_ok = 1;
						for ( i=0; i<methods.length; i++ ) {
							if ( ! this.player[methods[i]] ) {
								w_ok = 0;
							}
						}
						if ( w_ok == 0 )
							alert("Methods missing!");
					} else {
						this.debug('Could not find RealMedia Player object',1);
					}
				}
	};
	this.chkobj = function () { if ( ! this.player ) {this.debug('Could not find RealMedia Player object',1); return 0;} else { return 1; } };
	this.start = function (url) {
		if ( ! this.chkobj()) return;
		this.layer_volslide = MM_findObj('volslide');
		this.layer_clipslide = MM_findObj('clipslide');
		this.debug('Setting Source and playing clip Source: ' + url);
		this.player.SetSource(url);
		if ( navigator.family == 'ie4' ) {
			this.player.Source = url;
		}
		this.player.SetEnableContextMenu(false);
		this.player.SetAutoStart(true);
		this.player.DoPlay();
		this.xvolset(40);
		this.setmute(0);
		this.setloop(0);
		this.setshuffle(0);
		this.timer = setTimeout("playerh.tickhandler()",500);
	}
	this.play = function () {
		if ( ! this.chkobj()) return;
		if ( this.player.CanPlay() ) {
			this.player.DoPlay();
		} else {
			this.pstatus('Could not play clip!');
			this.debug('Could not play clip!',1);
		}
	};
	this.pause = function () {
		if ( ! this.chkobj()) return;
		if ( this.player.CanPause() ) {
			this.player.DoPause();
		} else {
			this.pstatus('Could not pause clip!');
			this.debug('Could not pause clip!',1);
		}
	};
	this.stop = function () {
		if ( ! this.chkobj()) return;
		if ( this.player.CanStop() ) {
			this.player.DoStop();
		} else {
			this.pstatus('Could not stop clip!');
			this.debug('Could not stop clip!',1);
		}
	};
	this.nextclip = function () {
		if ( ! this.chkobj()) return;
		if ( this.player.HasNextEntry() )
        {
			this.player.DoNextEntry();
            //TODO:




        } else {
			this.pstatus('This is the last clip in this playlist!');
			this.debug('This is the last clip in this playlist!',1);
		}
	};
	this.prevclip = function () {
		if ( ! this.chkobj()) return;
		if ( this.player.HasPrevEntry() ) {
			this.player.DoPrevEntry();
            //TODO:



		} else {
			this.pstatus('This is the first clip in this playlist!');
			this.debug('This is the first clip in this playlist!',1);
		}
	};
	this.ismute = function () {
		if ( ! this.chkobj()) return;
		return this.player.GetMute();
	};
	this.setmute = function (bool) {
		if ( ! this.chkobj()) return;
		if ( bool ) {
			this.player.SetMute(true);
		} else {
			this.player.SetMute(false);
		}
	};
	this.amute = function () {
		if ( ! this.chkobj()) return;
		if ( this.ismute() ) {
			this.setmute(0);
			MM_swapImage('muteimg','','player/volume/muteoff.gif',1);
			window.status = 'Mute Off';
			this.pstatus('<b><font face="Verdana, Arial" color="#FFFFFF" size=1>Mute Off');
		} else {
			this.setmute(1);
			MM_swapImage('muteimg','','player/volume/muteon.gif',1);
			window.status = 'Mute On';
			this.pstatus('<b><font face="Verdana, Arial" color="#FFFFFF" size=1>Mute On');
		}
	};
	this.getvolume = function () {
		if ( ! this.chkobj()) return;
		return this.player.GetVolume();
	}
	this.setvolume = function (level) {
		if ( ! this.chkobj()) return;
		if ( level < 0 || level > 100 ) return;
		return this.player.SetVolume(level);
	};
	this.isinloop = function () {
		if ( ! this.chkobj()) return;
		return this.player.GetLoop();
	};
	this.setloop = function (bool) {
		if ( ! this.chkobj()) return;
		if ( bool ) {
			this.player.SetLoop(true);
		} else {
			this.player.SetLoop(false);
		}
	};
	this.aloop = function () {
		if ( ! this.chkobj()) return;
		if ( this.isinloop() ) {
			this.setloop(0);
			MM_swapImage('loopimg','','player/controlbuttons/switchoff.gif',1);
			window.status = 'Loop Off';
			this.pstatus('<b><font face="Verdana, Arial" color="#FFFFFF" size=1>Loop Off');
		} else {
			this.setloop(1);
			MM_swapImage('loopimg','','player/controlbuttons/switchon.gif',1);
			window.status = 'Loop On';
			this.pstatus('<b><font face="Verdana, Arial" color="#FFFFFF" size=1>Loop On');
		}
	};
	this.isshuffle = function () {
		if ( ! this.chkobj()) return;
		return this.player.GetShuffle();
	};
	this.setshuffle = function (bool) {
		if ( ! this.chkobj()) return;
		if ( bool ) {
			this.player.SetShuffle(true);
		} else {
			this.player.SetShuffle(false);
		}
	};
	this.ashuffle = function () {
		if ( ! this.chkobj()) return;
		if ( this.isshuffle() ) {
			this.setshuffle(0);
			MM_swapImage('shuffleimg','','player/controlbuttons/switchoff.gif',1);
			window.status = '<b><font face="Verdana, Arial" color="#FFFFFF" size=1>Shuffle Off';
			this.pstatus('<b><font face="Verdana, Arial" color="#FFFFFF" size=1>Shuffle Off');
		} else {
			this.setshuffle(1);
			MM_swapImage('shuffleimg','','player/controlbuttons/switchon.gif',1);
			window.status = '<b><font face="Verdana, Arial" color="#FFFFFF" size=1>Shuffle On';
			this.pstatus('<b><font face="Verdana, Arial" color="#FFFFFF" size=1>Shuffle On');
		}
	};
	this.vstate = null;
	this.vstate_t = null;
	this.getstate = function () {
		if ( ! this.chkobj()) return;
		this.vstate = this.player.GetPlayState();
		switch(this.vstate) {
			case 0 :
				this.vstate_t = 'Status : Stopped';
			break;
			case 1 :
				this.vstate_t = 'Status : Contacting...';
			break;
			case 2 :
				this.vstate_t = 'Status : Buffering...' + this.buffertime();
			break;
			case 3 :
				this.vstate_t = 'Status : Playing';
			break;
			case 4 :
				this.vstate_t = 'Status : Paused';
			break;
			case 5 :
				this.vstate_t = 'Status : Seeking... (' + this.lastseekcmd_t + ')';
			break;
			case 6 :
				this.vstate_t = 'Status : Initializing...';
			break;
		}

	}
	this.tickhandler = function () {
		this.getstate();
		if ( this.vstate_t && document.MM_curDrag != this.layer_volslide) {
			this.xrmpstatus(this.vstate_t);
			window.status = this.vstate_t;
		}
		this.xclipinf(this.gettitle(),this.getauthor(),this.getcopyright());
		this.vclippos = this.clippos();
		this.vcliplen = this.cliplen();
		if ( this.vstate != 2 ) {
			this.xclipposinf(this.vclippos,this.vcliplen);
			this.xclipposmove(this.vclippos,this.vcliplen);
		}
		this.timer = setTimeout("playerh.tickhandler()",500);
	};
	this.clippos = function () {
		if ( ! this.chkobj()) return;
		if ( this.vstate == 3 || this.vstate == 4 ) {
			return this.player.GetPosition();
		} else if ( this.vstate == 5 ) {
			return this.lastseekcmd;
		}
	};
	this.cliplen = function () {
		if ( ! this.chkobj()) return;
		if ( this.vstate == 3 || this.vstate == 4 || this.vstate == 5 ) {
			this.currcliplen = this.player.GetLength();
			return this.currcliplen;
		}
	};
	this.seek = function (pos,len) {
		lenx = len ? len : this.currcliplen;
		if ( ! this.chkobj() || !lenx ) return;
		if ( pos >= 0 && pos <= lenx ) {
			this.player.SetPosition(pos);
			this.lastseekcmd = pos;
			time = new calctime( pos );
			this.lastseekcmd_t = (time.hr + '.' + time.min + '.' + time.sec);
			return true;
		} else {
			return;
		}
	};
	this.buffertime = function () { // Returns as string HH.MM.SS
		if ( navigator.family == 'ie4' ) return '  ';
		if ( ! this.chkobj()) return;
		if ( this.vstate == 2 ) {
			get = this.player.GetBufferingTimeRemaining(); if ( get < 0 ) get = ( get * -1 );
			time = new calctime( get );
			return ( time.hr + '.' + time.min + '.' + time.sec );
		}
	};
	this.getauthor = function () {
		if ( ! this.chkobj()) return;
		if ( this.vstate == 3 || this.vstate == 4 || this.vstate == 5 ) {
			return this.player.GetAuthor();
		}
	};
	this.gettitle = function () {
		if ( ! this.chkobj()) return;
		if ( this.vstate == 3 || this.vstate == 4 || this.vstate == 5 ) {
			return this.player.GetTitle();
		}
	};
	this.getcopyright = function () {
		if ( ! this.chkobj()) return;
		if ( this.vstate == 3 || this.vstate == 4 || this.vstate == 5 ) {
			return this.player.GetCopyright();
		}
	};
	this.avol = p_volume_slider;
	this.xvolset = p_volume_slider_set;
	this.xrmpstatus = p_status_rm_player;
	this.xclipinf = p_status_clipinfo;
	this.xclipposinf = p_clip_pos_inf;
	this.xclipposmove = p_clip_pos_move;
	this.xclipposset = p_clip_slider;
	this.xvolclick = p_volume_click;
	this.xposclick = p_clip_pos_click;
}

function calctime(mili) {
	if ( ! mili ) {
		this.mili = 0;
		this.sec = 0;
		this.min = 0;
		this.hr = 0;
	} else {
		this.mili = mili;
		this.sec = ( mili / 1000 );
		this.min = ( this.sec / 60 );
		this.hr = Math.floor( this.min / 60 );
		this.min = Math.floor( this.min - ( this.hr * 60 ) );
		this.sec = Math.floor( this.sec - ( this.min * 60 ) );
		this.mili = Math.floor( this.mili - ( this.sec * 1000 ) );
	}
}

function p_volume_slider_set(vol) {
	var layerref = this.layer_volslide,maxsize = 64,maxvol = 100;
	var ratio = (maxsize / maxvol), mintop = layerref.MM_startT;
	var pp = Math.floor(vol * ratio); var pos = (mintop - pp);
        if (navigator.family == 'nn4') {layerref.top = pos;}
        else if (navigator.family == 'gecko'){layerref.style.top = pos;}
        else if (navigator.family == 'ie4') {layerref.style.pixelTop = pos;}
        this.setvolume( vol );
        window.status = 'Volume : ' + vol;
        this.pstatus('Volume : ' + vol);
}

function p_volume_click() {
	var maxvol = 100,incre=10,layerref = this.layer_volslide;
	var vol = Math.floor((((layerref.MM_startT + incre) - mouseY) / layerref.MM_startT) * maxvol);
	this.xvolset(vol);
}

function p_clip_pos_move(curr,total) {
	layerref = this.layer_clipslide;
	maxsize = 139; minleft = layerref.MM_startL;
	if (document.MM_curDrag == layerref) return;
	if ( curr < 0 ) curr = 0;
	if ( ( ! curr && ! total ) || curr == 'NaN' || total == 'NaN' ) {
        	if (navigator.family == 'nn4') {layerref.left = minleft;}
        	else if (navigator.family == 'gecko'){layerref.style.left = minleft;}
        	else if (navigator.family == 'ie4') {layerref.style.pixelLeft = minleft;}
	} else {
		maxclip = total; ratio = (maxsize / maxclip);
		pp = Math.floor(curr * ratio); pos = (minleft + pp);
        	if (navigator.family == 'nn4') {layerref.left = pos;}
        	else if (navigator.family == 'gecko'){layerref.style.left = pos;}
        	else if (navigator.family == 'ie4') {layerref.style.pixelLeft = pos;}
        }
}


function p_clip_pos_inf(curr,total) {
	currobj = new calctime(curr);
	totalobj = new calctime(total);
	write_layer('TimeElasped','<b><font face="Verdana, Arial" color="#CCCCCC" size=1>' + currobj.hr + '.' + currobj.min + '.' + currobj.sec + '</font></b>', 'plain');
	write_layer('TotalTime', '<b><font face="Verdana, Arial" color="#CCCCCC" size=1>|' + totalobj.hr + '.' + totalobj.min + '.' + totalobj.sec + '</font></b>', 'plain');
}

function p_clip_slider() {
	var maxsize = 139,maxclip = this.vcliplen; var ratio = (maxsize / maxclip);
	var pos = getdragPos(this.layer_clipslide,1);
	var gpos = Math.floor(pos / ratio);
	this.seek( gpos );
}

function p_clip_pos_click() {
	var maxsize = 139,maxclip = this.vcliplen,layerref = this.layer_clipslide;
	if ( !maxclip ) return;
	var ratio = (maxsize / maxclip);var pos = mouseX - layerref.MM_startL;var gpos = Math.floor(pos / ratio);
	this.seek( gpos );
}


function getMouseXPos(e) {
  if (document.layers||ns6) {
    return parseInt(e.pageX+10)
  } else {
    return (parseInt(event.clientX+10) + parseInt(document.body.scrollLeft))
  }
}

function getMouseYPos(e) {
  if (document.layers||ns6) {
    return parseInt(e.pageY)
  } else {
    return (parseInt(event.clientY) + parseInt(document.body.scrollTop))
  }
}


function p_volume_slider() {
	maxsize = 64; maxvol = 100; ratio = (maxsize / maxvol);
	pos = getdragPos(this.layer_volslide,1);
	vol = Math.floor(pos / ratio);
	this.setvolume( vol );
	window.status = '<b><font face="Verdana, Arial" color="#CCCCCC" size=1>Volume : ' + vol;
	this.pstatus('<b><font face="Verdana, Arial" color="#CCCCCC" size=1>Volume : ' + vol);
}

function p_status_rm_player(status) {
	this.pstatus(status);
}

function p_status_clipinfo(title,author,copyright) {
	title = title ? title : '........';
	author = author ? author : '........';
    	copyright = copyright ? copyright : '........';
    //alert(title);
    //alert(author);
    //alert(copyright);
    title = title.substring(0,title.lastIndexOf('|'));
    rateinfo = 5;

    if(author !='........')
    {
	    ArtistId = author.substring(0,author.lastIndexOf('|'));
    	ArtistName = author.substring(author.lastIndexOf('|')+1);
    }
    else
    {
    ArtistId="";
    ArtistName="";

    }

    if(copyright !='........')
    {
	    AlbumId = copyright.substring(0,copyright.lastIndexOf('|'));
    	AlbumName = copyright.substring(copyright.lastIndexOf('|')+1);
    }
    else
    {
        AlbumId="";
        AlbumName="";
    }

    fnt = '<b><font face="Verdana, Arial" color="#000000" size=1>Song : ';
    write_layer('TitleText', fnt + title + '</font></b>', 'plain');
    fnt = '<b><font face="Verdana, Arial" color="#000000" size=1>Album : ';
	write_layer('AlbumText',fnt +'<a href="?action=album&id='+ AlbumId +'" target="_blank">'+ AlbumName+'</a></font></b>', 'plain');
	fnt = '<b><font face="Verdana, Arial" color="#000000" size=1>Artist : ';
	write_layer('ArtistText',fnt +'<a href="?action=artist&id='+ ArtistId +'" target="_blank">'+ ArtistName+'</a></font></b>', 'plain');
    fnt = '<img border="0" src="images/'+rateinfo+'_s.gif">';
	write_layer('ratealbum', fnt, 'plain');
document.title = title;
    //showRate(rateinfo);
}

function showRate(songid)
{
    if(songid != songid2)
    {
        if(songid.indexOf('|')>0)
        {
	        songR = rate.substring(0,rate.lastIndexOf('|'));
    	    songId = rate.substring(rate.lastIndexOf('|')+1);
        	fnt2 = '<a href="javascript:rateSong('+songId+ ')"><img border="0" src="images/'+songR+'_s.gif" alt="'+songR+'"></a>';
	        write_layer('ratealbum', fnt2, 'plain');
    	    fnt2 = '<a  href="javascript:addToPlaylist('+songId+')"><b><font face="Verdana, Arial" color="#000000" size=1>Add to Playlist</font></b></a>';
        	write_layer('Playlist', fnt2, 'plain');

            fnt2 = '<a  href="javascript:mailFriend(0,0,'+songId+',0)"><img src="images/mail.gif" border="0"></a>';
        	write_layer('sendSong', fnt2, 'plain');

	        songid2 = songid;
            showpic(img);

        }

    }
}

function p_debug(msg,fatal) {
	if ( document.playerdebug == 1 && fatal != 1 ) {
		alert("Debug Message : " + msg);
	} else if ( fatal == 1 ) {
		alert("ERROR : " + msg);
	}
}

function p_current_status(msg) {
	write_layer('playerstatus','<img src="player/images/status.gif" width="12" height="12" alt="" border="0" hspace="2" align=middle><b><font face="Verdana, Arial" color="#CCCCCC" size=1>' + msg + '</font></b>','plain');
}

function write_layer(layer,text,base) {
	w_done = 0;
	if (base != 'plain') text = text2imgs(text,base);
	if (navigator.family == 'ie4' ) {
		if ( document.all[layer] ) {
			document.all[layer].innerHTML = text;
			w_done = 1;
		}
	} else 	if (navigator.family == 'nn4' ) {
		lyr = document.layers[layer].document;
		if ( lyr ) {
			lyr.open();
			lyr.write(text);
			lyr.close();
			w_done = 1;
		}
	} else 	if (document.getElementById && document.body.style) {
		over = document.getElementById([layer]);
		if ( over ) {
			range = document.createRange();
			range.setStartBefore(over);
			domfrag = range.createContextualFragment(text);
			while (over.hasChildNodes()) {
				over.removeChild(over.lastChild);
			}
			over.appendChild(domfrag);
			w_done = 1;
		}
	}
	return w_done;
}

function text2imgs (text,base) {
	base = base ? base : 'alpha';
	base = base;
	text = text.replace(/[^a-zA-Z 0-9.]+/g,'');
	text = text.toLowerCase();
	var cut = text.split('');
	var ret = '';
	for ( i=0; i<cut.length; i++ ) {
		if (cut[i] == '.') cut[i]='dot';
		if (cut[i] == ' ') cut[i]='space';
		ret += '<img src="'+ base +'/'+ cut[i] +'.gif">';
	}
	return ret;
}

function getdragPos(layername,objy){
	layerref = objy ? layername : MM_findObj(layername);
	curpos = layerref.MM_LEFTRIGHT ? layerref.MM_LEFTRIGHT : layerref.MM_UPDOWN;
	if ( curpos < 0 ) {
		curpos = (curpos * -1)
	}
	window.status = curpos;
	return curpos;
}

// Below Copyright Macromedia
function MM_reloadPage(intit) {  //reloads the window if Nav4 resized
  if (intit==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_dragLayer(objName,x,hL,hT,hW,hH,toFront,dropBack,cU,cD,cL,cR,targL,targT,tol,dropJS,et,dragJS) { //v4.01
  //Copyright 1998 Macromedia, Inc. All rights reserved.
  var i,j,aLayer,retVal,curDrag=null,curLeft,curTop,IE=document.all,NS4=document.layers;
  var NS6=(!IE&&document.getElementById), NS=(NS4||NS6); if (!IE && !NS) return false;
  retVal = true; if(IE && event) event.returnValue = true;
  if (MM_dragLayer.arguments.length > 1) {
    curDrag = MM_findObj(objName); if (!curDrag) return false;
    if (!document.allLayers) { document.allLayers = new Array();
      with (document) if (NS4) { for (i=0; i<layers.length; i++) allLayers[i]=layers[i];
        for (i=0; i<allLayers.length; i++) if (allLayers[i].document && allLayers[i].document.layers)
          with (allLayers[i].document) for (j=0; j<layers.length; j++) allLayers[allLayers.length]=layers[j];
      } else {
        if (NS6) { var spns = getElementsByTagName("span"); var all = getElementsByTagName("div");
          for (i=0;i<spns.length;i++) if (spns[i].style&&spns[i].style.position) allLayers[allLayers.length]=spns[i];}
        for (i=0;i<all.length;i++) if (all[i].style&&all[i].style.position) allLayers[allLayers.length]=all[i];
    } }
    curDrag.MM_dragOk=true; curDrag.MM_targL=targL; curDrag.MM_targT=targT;
    curDrag.MM_tol=Math.pow(tol,2); curDrag.MM_hLeft=hL; curDrag.MM_hTop=hT;
    curDrag.MM_hWidth=hW; curDrag.MM_hHeight=hH; curDrag.MM_toFront=toFront;
    curDrag.MM_dropBack=dropBack; curDrag.MM_dropJS=dropJS;
    curDrag.MM_everyTime=et; curDrag.MM_dragJS=dragJS;
    curDrag.MM_oldZ = (NS4)?curDrag.zIndex:curDrag.style.zIndex;
    curLeft= (NS4)?curDrag.left:(NS6)?parseInt(curDrag.style.left):curDrag.style.pixelLeft;
    if (String(curLeft)=="NaN") curLeft=0; curDrag.MM_startL = curLeft;
    curTop = (NS4)?curDrag.top:(NS6)?parseInt(curDrag.style.top):curDrag.style.pixelTop;
    if (String(curTop)=="NaN") curTop=0; curDrag.MM_startT = curTop;
    curDrag.MM_bL=(cL<0)?null:curLeft-cL; curDrag.MM_bT=(cU<0)?null:curTop-cU;
    curDrag.MM_bR=(cR<0)?null:curLeft+cR; curDrag.MM_bB=(cD<0)?null:curTop+cD;
    curDrag.MM_LEFTRIGHT=0; curDrag.MM_UPDOWN=0; curDrag.MM_SNAPPED=false; //use in your JS!
    document.onmousedown = MM_dragLayer; document.onmouseup = MM_dragLayer;
    if (NS) document.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  } else {
    var theEvent = ((NS)?objName.type:event.type);
    if (theEvent == 'mousedown') {
      mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft;
      mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop;
      var maxDragZ=null; document.MM_maxZ = 0;
      for (i=0; i<document.allLayers.length; i++) { aLayer = document.allLayers[i];
        var aLayerZ = (NS4)?aLayer.zIndex:parseInt(aLayer.style.zIndex);
        if (aLayerZ > document.MM_maxZ) document.MM_maxZ = aLayerZ;
        var isVisible = (((NS4)?aLayer.visibility:aLayer.style.visibility).indexOf('hid') == -1);
        if (aLayer.MM_dragOk != null && isVisible) with (aLayer) {
          var parentL=0; var parentT=0;
          if (NS6) { parentLayer = aLayer.parentNode;
            while (parentLayer != null && parentLayer.style.position) {
              parentL += parseInt(parentLayer.offsetLeft); parentT += parseInt(parentLayer.offsetTop);
              parentLayer = parentLayer.parentNode;
          } } else if (IE) { parentLayer = aLayer.parentElement;
            while (parentLayer != null && parentLayer.style.position) {
              parentL += parentLayer.offsetLeft; parentT += parentLayer.offsetTop;
              parentLayer = parentLayer.parentElement; } }
          var tmpX=mouseX-(((NS4)?pageX:((NS6)?parseInt(style.left):style.pixelLeft)+parentL)+MM_hLeft);
          var tmpY=mouseY-(((NS4)?pageY:((NS6)?parseInt(style.top):style.pixelTop) +parentT)+MM_hTop);
          if (String(tmpX)=="NaN") tmpX=0; if (String(tmpY)=="NaN") tmpY=0;
          var tmpW = MM_hWidth;  if (tmpW <= 0) tmpW += ((NS4)?clip.width :offsetWidth);
          var tmpH = MM_hHeight; if (tmpH <= 0) tmpH += ((NS4)?clip.height:offsetHeight);
          if ((0 <= tmpX && tmpX < tmpW && 0 <= tmpY && tmpY < tmpH) && (maxDragZ == null
              || maxDragZ <= aLayerZ)) { curDrag = aLayer; maxDragZ = aLayerZ; } } }
      if (curDrag) {
        document.onmousemove = MM_dragLayer; if (NS4) document.captureEvents(Event.MOUSEMOVE);
        curLeft = (NS4)?curDrag.left:(NS6)?parseInt(curDrag.style.left):curDrag.style.pixelLeft;
        curTop = (NS4)?curDrag.top:(NS6)?parseInt(curDrag.style.top):curDrag.style.pixelTop;
        if (String(curLeft)=="NaN") curLeft=0; if (String(curTop)=="NaN") curTop=0;
        MM_oldX = mouseX - curLeft; MM_oldY = mouseY - curTop;
        document.MM_curDrag = curDrag;  curDrag.MM_SNAPPED=false;
        if(curDrag.MM_toFront) {
          eval('curDrag.'+((NS4)?'':'style.')+'zIndex=document.MM_maxZ+1');
          if (!curDrag.MM_dropBack) document.MM_maxZ++; }
        retVal = false; if(!NS4&&!NS6) event.returnValue = false;
    } } else if (theEvent == 'mousemove') {
      if (document.MM_curDrag) with (document.MM_curDrag) {
        mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft;
        mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop;
        newLeft = mouseX-MM_oldX; newTop  = mouseY-MM_oldY;
        if (MM_bL!=null) newLeft = Math.max(newLeft,MM_bL);
        if (MM_bR!=null) newLeft = Math.min(newLeft,MM_bR);
        if (MM_bT!=null) newTop  = Math.max(newTop ,MM_bT);
        if (MM_bB!=null) newTop  = Math.min(newTop ,MM_bB);
        MM_LEFTRIGHT = newLeft-MM_startL; MM_UPDOWN = newTop-MM_startT;
        if (NS4) {left = newLeft; top = newTop;}
        else if (NS6){style.left = newLeft; style.top = newTop;}
        else {style.pixelLeft = newLeft; style.pixelTop = newTop;}
        if (MM_dragJS) eval(MM_dragJS);
        retVal = false; if(!NS) event.returnValue = false;
    } } else if (theEvent == 'mouseup') {
      document.onmousemove = null;
      if (NS) document.releaseEvents(Event.MOUSEMOVE);
      if (NS) document.captureEvents(Event.MOUSEDOWN); //for mac NS
      if (document.MM_curDrag) with (document.MM_curDrag) {
        if (typeof MM_targL =='number' && typeof MM_targT == 'number' &&
            (Math.pow(MM_targL-((NS4)?left:(NS6)?parseInt(style.left):style.pixelLeft),2)+
             Math.pow(MM_targT-((NS4)?top:(NS6)?parseInt(style.top):style.pixelTop),2))<=MM_tol) {
          if (NS4) {left = MM_targL; top = MM_targT;}
          else if (NS6) {style.left = MM_targL; style.top = MM_targT;}
          else {style.pixelLeft = MM_targL; style.pixelTop = MM_targT;}
          MM_SNAPPED = true; MM_LEFTRIGHT = MM_startL-MM_targL; MM_UPDOWN = MM_startT-MM_targT; }
        if (MM_everyTime || MM_SNAPPED) eval(MM_dropJS);
        if(MM_dropBack) {if (NS4) zIndex = MM_oldZ; else style.zIndex = MM_oldZ;}
        retVal = false; if(!NS) event.returnValue = false; }
      document.MM_curDrag = null;
    }
    if (NS) document.routeEvent(objName);
  } return retVal;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}