if (!document.TBPlayer) {

	function TBPlayerClass() {

		this.strMp3 = "";
		this.strMp3Status = "init";
		this.strMp3Id = "";
		this.strMp3AutoFile="";
		this.strMp3AutoID="";
		this.arrSwfPlayers=new Array();

		this.initMediaPlay = function(strSWF, w, h, strDivContId, strUrl, fAuto) {
			try {
			    var divCont =  document.getElementById(strDivContId);
			    if (!divCont) return alert('no div with id'+strDivContId);
			    var plyId= (strDivContId=='container')? 'jstest': 'swfp'+strDivContId; // swf obj id. Historicly jstest.
			    this.arrSwfPlayers[this.arrSwfPlayers.length]=plyId;
			    var soPlay = new SWFObject(strSWF, plyId, w, h, '8');
			    //alert('initMediaPlay '+strSWF+"-"+plyId);
			    if (fAuto) { soPlay.addVariable('autostart', 'true'); this.strMp3Status='playing';}
			    with (soPlay) {
				    addParam('allowscriptaccess','sameDomain');
				    addParam('allowfullscreen','false');
				    addVariable('width',w);
				    addVariable('height',h);
				    addVariable('volume', 100);
				    if (strUrl) addVariable('file', strUrl);
				    addVariable('javascriptid','swfp'+strDivContId);
				    addVariable('enablejs','true');
				    write(strDivContId);
			    }
			} catch (e) { if (document.getElementById("debuglineLog")) alert('imp'+e); }
		};

		this.initMP3Play = function(strTBP) {
			try {
				if (strTBP && strTBP.length>8) window.TBSRVPATH = strTBP;
				else strTBP = window.TBSRVPATH;
				var o = document.getElementById('containerAll');
				if (o) try{ document.body.removeChild(o);} catch (e){;};

				var o = document.getElementById('container');
				if (o) try{ document.body.removeChild(o);} catch (e){;};

				var o2=document.createElement("div")
				o2.setAttribute("id", "container");

				var o=document.createElement("div")
				o.setAttribute("id", "containerAll");
				o.style['display'] = 'block';
				o.style['overflow'] = 'hidden';
				o.style['width'] = '1px';
				o.style['height'] = '1px';
				o.style['visibility'] = 'hidden';
				o.appendChild(o2);
				document.getElementsByTagName("body")[0].appendChild(o);

				var f5=false;
				var o3=document.createElement("audio")
				if (o3 && o3.canPlayType && o3.canPlayType('audio/mpeg')) {
					document.TBPlayer.replaceMP3AudioTag('');
					f5 = true;
				}
				if (!f5) {
					document.TBPlayer.initMediaPlay(strTBP+'/3rdParty/mediaplayer/mediaplayer.swf', 1, 1, 'container', '', false);
				}
			} catch (e) { if (document.getElementById("debuglineLog")) alert('initMP3Pl'+e.toString()); }
			return true;
		};

		this.replaceMP3AudioTag = function(strFile) {
			var o = document.getElementById('containerAll');
			if (!o) return;
			if (strFile && strFile!='') o.tbMp3Src = strFile;

			var o3 = document.getElementById('containerAA');
			if (o3) try{o.removeChild(o3);} catch (e){;};

			o3=document.createElement("audio");
			o3.setAttribute("id", "containerAA");
			o3.setAttribute("controls", "");
			o3.onabort = function(){document.TBPlayer.ebyMp3Stop(0);};
			o3.src = o.tbMp3Src;
			o.appendChild(o3);
			return o3;
		};

		this.sendEvent = function(swf,typ,prm) {
			document.TBPlayer.thisMovie(swf).sendEvent(typ,prm);
		};

		this.thisMovie = function(swf) {
		    if(navigator.appName.indexOf("Microsoft") != -1) {
		        return window[swf];
		    } else {
		        return document[swf];
		    }
		};

		this.loadFile = function(swf,obj) {
			try {
				document.TBPlayer.thisMovie(swf).loadFile(obj);
			} catch (e) {
			    if(document.getElementById("debuglineLog")) alert('lf'+e.toString());
			}
		};

		this.ebyMp3Play = function(x) {
			try {
		    	var html5Obj = document.getElementById('containerAA');
		    	if (html5Obj) {
		    		html5Obj = document.TBPlayer.replaceMP3AudioTag('');
		    		html5Obj.play();
		    	} else document.TBPlayer.sendEvent('jstest','playpause');

			    this.strMp3Status='playing';
			    this.strMp3Id = x;
			    document.getElementById(x).innerHTML='<img src="'+document.TBPlayer.tradebitURL2('')+'/img/play_mp3a.gif" alt="playing" title="playing" border="0">';
			} catch (e) {
			    if(document.getElementById("debuglineLog")) alert('empl'+e.toString()+" x"+x);
			}
		};


		this.ebyMp3Stop = function(x) {
			try {
				for (var i=0; i<this.arrSwfPlayers.length; i++) document.TBPlayer.sendEvent(this.arrSwfPlayers[i],'stop');
				var html5Obj = document.getElementById('containerAA');
		    	if (html5Obj) {
		    		html5Obj.pause();
		    		html5Obj.src = "";
		    	}
			    this.strMp3Status='stop';
			    if (this.strMp3Id) // if a GIF is 'Playing', change it to 'play start'
			    	document.getElementById(this.strMp3Id).innerHTML='<img src="'+document.TBPlayer.tradebitURL2('')+'/img/play_mp3.gif" alt="play" title="play" border="0">';
			} catch (e) {
		        if(document.getElementById("debuglineLog")) alert('emst'+e);
		    }
		};

		this.ebyMp3Auto = function(strFile, x) {
			this.strMp3AutoFile=strFile;
			this.strMp3AutoID=x;
		};

		this.ebyMp3 = function(strFile, x) {
		    try {
		        if (strFile!=this.strMp3) {
		        	document.TBPlayer.ebyMp3Stop(x);
		        	var html5Obj = document.getElementById('containerAA');
		        	if (html5Obj) document.TBPlayer.replaceMP3AudioTag(strFile);
		        	else 		  document.TBPlayer.loadFile('jstest', {file: strFile});
		            this.strMp3 = strFile;
		            document.TBPlayer.ebyMp3Play(x);
		        } else if (this.strMp3Status=='playing') {
		        	document.TBPlayer.ebyMp3Stop(x);
		        } else {
		        	document.TBPlayer.ebyMp3Stop(x); document.TBPlayer.ebyMp3Play(x);
		        }
		    } catch (e) {
		        if(document.getElementById("debuglineLog")) alert('em'+e);
		    }
		};

		this.tradebitURL2 = function() {
			return window.TBSRVPATH? window.TBSRVPATH: 'http://www.tradebit.com';
		};

		this.ebyMp3ActivateThePlayButtonsOnPage = function(strCartTxt) {
			try {
			    var strPath=document.TBPlayer.tradebitURL2(), uc=ucntr(), arrD=getHdnData();
				var arrPlayB = document.getElementsByTagName("img");
				var str="";
				for(var lastOutI='', subItmCnt=0, i=arrPlayB.length-1; i>=0; i--) {
		            if (arrPlayB[i].alt=="play button") {
						var aParent = arrPlayB[i].parentNode;
						aParent.style.visibility = 'visible';
						var arrRec = aParent.title.split(",");

						if (arrRec.length>2 && arrRec.length<7) {
							var outI = arrRec[0];
							var idvVid = arrRec[1];
							var tagId = arrRec[2];
							var strUrl = arrRec[3];
							var strShowCart = arrRec.length>5? arrRec[4]: 'y'; // allowed y,n,ck
							var strPriceTxt = arrRec.length>6? ' '+arrRec[5]: '';
							var strHtml =  "" ;
							if (lastOutI==outI) subItmCnt++; else {subItmCnt=0; lastOutI=outI;}
							if (strUrl.length>0) {
							   strHtml =  "\n<a href=\"javascript:document.TBPlayer.ebyMp3('"+strUrl+"','"+ tagId +"')\" style=\"text-decoration: none; border:0;\"><span id=\""+tagId+"\">"
										   + aParent.innerHTML
										   + "</span></a>\n";
							} else {
							   strHtml =  "\n<span id=\""+tagId+"\" style=\"font-size: 11px; color: #020A02;\">"
							               + aParent.innerHTML.replace(/<img.*>/gi, '')
							               + "</span>\n";
							}

							//if (str=='') { alert('strCartTxt'+strCartTxt); str='1'; }
							var flyId = outI+'-'+subItmCnt;
							if (strShowCart=='ck' && uc!='') {
								for (var obj, n=0, nMax=(arrD?arrD.length:0); n<nMax; n++) if (((obj=arrD[n]).i+'')==(''+outI) && (!obj.c || obj.c.indexOf(uc)>=0)) {strShowCart='y'; break;}
							}

							if (strCartTxt && strShowCart=='y')  {
							   strHtml = "<a href=\"javascript:addToBasket('"+flyId+"','"+idvVid+"')\" id=\"slidingProduct"+flyId+"\" style=\"font-size: 10px; display: none; background-color: #F6F6F6;\" title=\"add to cart\">["+strCartTxt+strPriceTxt+"]</a>"
							   		   + "<a href=\"javascript:addToBasket('"+flyId+"','"+idvVid+"')\" title=\"add to cart"+strPriceTxt+"\"><img src=\""+strPath+"/img/smallcart.gif\" width=\"24\" height=\"18\" alt=\"c\" style=\"border:none;\"></a>"
							   		   + strHtml;
							   aParent.onmouseover = new Function('document.getElementById("slidingProduct'+flyId+'").style.display="inline";' );
							   aParent.onmouseout = new Function('document.getElementById("slidingProduct'+flyId+'").style.display="none"' );
							} else if (strCartTxt && strShowCart=='ck')  {
							   strHtml = "<a href=\"javascript:addToBasket('"+flyId+"','"+idvVid+"')\" id=\"slidingProduct"+flyId+"\" style=\"font-size: 10px; visibility: hidden; display: none; background-color: #F6F6F6;\" title=\"add to cart\">["+strCartTxt+strPriceTxt+"]</a>"
							   		   + "<a href=\"javascript:addToBasket('"+flyId+"','"+idvVid+"')\" style=\"visibility: hidden\" title=\"add to cart"+strPriceTxt+"\"><img src=\""+strPath+"/layout-graphics/minicart.gif\" width=\"24\" height=\"18\" alt=\"c\" style=\"border:none;\"></a>"
							           + strHtml;
							   aParent.onmouseover = new Function('document.getElementById("slidingProduct'+flyId+'").style.display=(document.body.getAttribute("basket")=="n")?"none":"inline";' );
							   aParent.onmouseout = new Function('document.getElementById("slidingProduct'+flyId+'").style.display="none"' );
							}
							aParent.innerHTML = strHtml;
							aParent.title = '';
				        }
				    }
				}
				if (this.strMp3AutoFile && this.strMp3AutoID) ebyMp3(this.strMp3AutoFile, this.strMp3AutoID);

			} catch (e) { if (document.getElementById("debuglineLog")) alert('tp '+e); }
		}
	}
	try {
		TBPlayer = new TBPlayerClass();
		document.TBPlayer = TBPlayer;
		if (window.TBDOMP3INIT) {
			document.TBPlayer.initMP3Play(document.TBPlayer.tradebitURL2());
		}
	} catch (tbexception) {if (document.getElementById("debuglineLog")) alert('tbp '+tbexception+' '+document.TBPlayer);}

	function initMediaPlay(strSWF, w, h, strDivContId, strUrl, fAuto) {return document.TBPlayer.initMediaPlay(strSWF, w, h, strDivContId, strUrl, fAuto);}
	function initMP3Play(strTBP,strCartTxt) {document.TBPlayer.initMP3Play(strTBP); document.TBPlayer.ebyMp3ActivateThePlayButtonsOnPage(strCartTxt); return true;}
	function ebyMp3(strFile, x) {return document.TBPlayer.ebyMp3(strFile, x); }
	function ebyMp3Auto(strFile, x) {return document.TBPlayer.ebyMp3Auto(strFile, x);}
	function ebyMp3ActivateThePlayButtonsOnPage(strCartTxt) {if(0 && document.getElementById("debuglineLog")) alert('please remove ebyMp3ActivateThePlayButtonsOnPage() call'); return true;}
}
if (window.TBDOMP3INIT) {
	try {document.TBPlayer.initMP3Play(document.TBPlayer.tradebitURL2());} catch (tbexception) {if (document.getElementById("debuglineLog")) alert('tbp '+tbexception+' '+document.TBPlayer);}
}
