  var _timer;
  var oxml = new oxml();
  oxml.init();
  
  function windowOpen(url, width, height) {
  	document.getElementsByTagName('html')[0].style.overflow = 'hidden';
  	hiddenSelectTag();
	setDivArea(url, width, height);
	increaseAlpha();
	observeWindowSize(width, height);	
  }
  
  function initRealIframe(url, width, height) {  	
  	clearTimeout(_timer);
  	setDivArea(url, width, height);
  	observeWindowSize(width, height);  	  
  }
  
  function mask(width, height) {  	
    //hiddenSelectTag();    
    document.getElementById('overlayTable').style.height = height + 'px';
    document.getElementById('overlayTable').style.width = width + 'px';
  	document.getElementById('overlay2').style.display = '';
  }
  
  function resizeIframe(width, height) {    	  	 
  	initRealIframe('', width, height);  	  
  }
  
  function fixLayerHeight() {
  	if(parseInt(document.documentElement.clientWidth) < parseInt(document.documentElement.scrollHeight)) {
  		document.getElementById('overlayTable').style.height = document.documentElement.scrollHeight + 'px';  		
  	} 
  }
  
  function closeOpenIframe() {
  	
  }
  
  function setDivArea(url, width, height) {  		
  	
	if(document.getElementById('closeTable') == null) {
		document.getElementById('iframeWindow').innerHTML = '<table id="closeTable" border="0" cellpadding="0" cellspacing="0" width="'+width+'"><tr><td align="right"><img src="../../images/closebtn.gif" style="cursor:pointer;" onclick="closeWindow();" />&nbsp;</td></tr></table>'	
		+ '<iframe id="realIframe" src="'+encodeURI(url)+'" width="'+width+'" height="'+height+'" frameborder="0" onload="showIframeWindow(); onResizeIframe();"  />';
	}
	document.getElementById('closeTable').width = width;	
	//if(url != '') {	
	//	document.getElementById('realIframe').src = encodeURI(url);
	//}
	document.getElementById('realIframe').width = width;
	document.getElementById('realIframe').height = height;
	document.getElementById('overlay').style.display = '';  	
  }
  
  function showIframeWindow() {
  	document.getElementById('iframeWindow').style.display = '';
  }
  
  function hideIframeWindow() {  	
  	document.getElementById('iframeWindow').style.display = 'none';
  }
  
  function onResizeIframe() {
  	
  	var width = document.getElementById('realIframe').clientWidth;
  	var height = document.getElementById('realIframe').clientHeight;
  	
  	resizeIframe(width, height);
  }
  
  function increaseAlpha() {
  	document.getElementById('alpha').style.filter = 'alpha(opacity=60)';  	
  	document.getElementById('overlay').style.display = '';  
  	document.getElementById('iframeWindow').style.display = '';  	
  }   
  
  function decreaseAlpha() {  	
  	document.getElementById('alpha').style.filter = 'alpha(opacity=0)';  	
  	document.getElementById('overlay').style.display = 'none';
  	document.getElementById('iframeWindow').style.display = 'none';  	
  }   
  
  function observeWindowSize(width, height) {  	
	var windowWidth = document.documentElement.scrollWidth;
	var windowHeight = document.documentElement.scrollHeight;
	var windowWidth2 = document.documentElement.clientWidth;
	var windowHeight2 = document.documentElement.clientHeight;
	
	document.getElementById('overlayTable').style.width = windowWidth + 'px';	
	document.getElementById('iframeWindow').style.left = (parseInt(windowWidth2)/2-(parseInt(width)/2)) + 'px';
	
	document.getElementById('overlayTable').style.height = windowHeight + 'px';
	document.getElementById('iframeWindow').style.top = (parseInt(windowHeight2)/2-(parseInt(height)/2)) + 'px';
		
	fixLayerHeight();
	parent.scroll(1, 1);
	hiddenSelectTag();
		
	_timer = setTimeout("observeWindowSize("+width+", "+height+")", 500);
  }

  function closeWindow() {
  	document.getElementById('iframeWindow').innerHTML = '';
  	decreaseAlpha();  	
  	clearTimeout(_timer);
  	showSelectTag();
  	document.getElementsByTagName('html')[0].style.overflow = 'auto';
  }

  function showSelectTag() {
  	var selectTags = document.getElementsByTagName('select');
  	for(i = 0 ; i < selectTags.length ; i++) {
  		selectTags[i].style.visibility = 'visible';
  	}
  }
  
  function hiddenSelectTag() {
  	var selectTags = document.getElementsByTagName('select');
  	for(i = 0 ; i < selectTags.length ; i++) {
  		selectTags[i].style.visibility = 'hidden';
  	}
  }
  
  function windowOpenOxml(url) {
  	var html = oxml.getQueryData(url);	  	
  	
	document.getElementById("iframeWindow").innerHTML= html;
	document.getElementsByTagName('html')[0].style.overflow = 'hidden';  
	hiddenSelectTag();
	setDivAreaOxml(html);
	increaseAlpha();
	observeWindowSizeOxml();	
  }
  
  function closeWindowOxml() {
  	stop();
  	document.getElementById('iframeWindow').innerHTML = '';
  	decreaseAlpha();  	
  	clearTimeout(_timer);
  	showSelectTag();  	
  	document.getElementsByTagName('html')[0].style.overflow = 'auto';  	
  }
  
  function setDivAreaOxml(html) {  			  	
	document.getElementById('iframeWindow').innerHTML = html;			
  }
  
  function observeWindowSizeOxml() {  	
	var windowWidth = document.documentElement.scrollWidth;
	var windowHeight = document.documentElement.scrollHeight;
	var windowWidth2 = document.documentElement.clientWidth;
	var windowHeight2 = document.documentElement.clientHeight;
	
	document.getElementById('overlayTable').style.width = windowWidth + 'px';	
	document.getElementById('iframeWindow').style.left = (parseInt(windowWidth2)/2-(parseInt(500)/2)) + 'px';
	
	document.getElementById('overlayTable').style.height = windowHeight + 'px';
	document.getElementById('iframeWindow').style.top = (parseInt(windowHeight2)/2-(parseInt(370)/2)) + 'px';
		
	fixLayerHeight();
	parent.scroll(1, 1);
		
	_timer = setTimeout("observeWindowSizeOxml(500, 370)", 500);
  }
  
  	 function initPlayer(url) {		
  	 	stop();  	 
  	 	
  	 	if(navigator.userAgent.toLowerCase().indexOf('window') > -1) {
	  	 	if(document.getElementById('Player') == null) {
		     	var html = '';	     	
		     	html += '<OBJECT id="Player"';
		     	if(-1 != navigator.userAgent.indexOf("MSIE")) {               
		          html += ' classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"';
		        } else if(-1 != navigator.userAgent.indexOf("Firefox")) {      
		          html += ' type="application/x-ms-wmp"';  
		        }  
		        html += ' width=0 height=0> \n';
		        html += '<param name="uiMode" value="Invisible"> \n';        
		        html += '<PARAM name="autoStart" value="false"/> \n';
		        html += '<PARAM name="url" value="'+url+'"/> \n';
		        html += '</OBJECT> \n';
		        
		        document.getElementById('mediaPlayer').innerHTML = html; 
			} else {			
				document.getElementById('Player').URL = url;
			}
		} else {
			var html = '<object id="ffPlayer" type="audio/x-mpeg" data="'+url+'" width="1" height="1">';
	        html += '<param name="src" value="'+url+'" />';
	        html += '<param name="controller" value="false" />';
	        html += '<param name="autoplay" value="true" />';
	        html += '<param name="autostart" value="0" />';
	        html += '<param name="pluginurl" value="http://www.apple.com/quicktime/download/" />';
	        html += '</object>';
	       
	        document.getElementById('playerHome2').innerHTML = html;
		}
     }
     
     function playInBox(url) {
     	initPlayer(url);
     	play();
     }
     
     function play() {       
     	if(navigator.userAgent.toLowerCase().indexOf('window') > -1) {
     		if(document.getElementById('Player') != null) {      	
	     		document.getElementById('Player').settings.invokeURLs = false;
				document.getElementById('Player').controls.play();
			}
		} else {
			document.getElementById('playerHome').innerHTML = document.getElementById('playerHome2').innerHTML;
     		document.getElementById('playerHome2').innerHTML = '';
		}
     }
     
     function pause() {
     	if(navigator.userAgent.toLowerCase().indexOf('window') > -1) {
     		if(document.getElementById('Player') != null) {
	     		document.getElementById('Player').controls.pause();
     		}
     	} else {
     		document.getElementById('playerHome2').innerHTML = document.getElementById('playerHome').innerHTML;
        	document.getElementById('playerHome').innerHTML = '';
     	}
     }
     
     function stop() {
     	if(navigator.userAgent.toLowerCase().indexOf('window') > -1) {
     		if(document.getElementById('Player') != null) {
	     		document.getElementById('Player').controls.stop();
     		}
     	} else {
     		document.getElementById('playerHome').innerHTML = '';
     	}
     }
     
     function addVol() {
     	document.getElementById('Player').settings.volume = document.getElementById('Player').settings.volume + 1;
     }
     
     function plusVol() {
     	document.getElementById('Player').settings.volume = document.getElementById('Player').settings.volume - 1;
     }
     
     function setVol(vol) {
     	if(vol >= 0 && vol <= 100) {
     		document.getElementById('Player').settings.volume = vol;
     	}
     }
     
     function getCurrentPosition() {
     	if(navigator.userAgent.toLowerCase().indexOf('window') > -1) {
     		return document.getElementById('Player').controls.currentPosition;
     	} else {
     		return 0;
     	}
     }
     
     function getTotalPosition() {
     	if(navigator.userAgent.toLowerCase().indexOf('window') > -1) {
     		return document.getElementById('Player').currentMedia.duration;
     	} else {
     		return 50;
     	}
     }
     
     function setStatus() {
     	document.getElementById('status').innerHTML = getStatus();     	
     }
     
     //1停止 2暫停 3播放 6緩衝處理中 9連線至媒體 10就緒
     function getStatus() {
     	if(navigator.userAgent.toLowerCase().indexOf('window') > -1) {
     		return document.getElementById('Player').playState;
     	} else {
     		return 3;
     	}        
     }
     
     function trylisten(url) {
  		var html = oxml.getQueryData(url);	
  		html = html.replace(/^\s+|\s+$/g,'');
  		
  		if(html != '') {	
	  		playInBox(html);
	  	} else {
	  		alert('找不到歌曲');
	  	}		
  	}
  	
  	function windowOpenAgain(url) {
  		closeWindow();  	
  		windowOpen(url, '660', '560');
  	}
  
  