function popWin(data,targetname,w,h ) {
	msgWindow=window.open(data,targetname,'width='+w+',height='+h+',status=no,scrollbars=no,resizable=no,toolbar=no,location=no,directories=no');
	msgWindow.focus();
}
function popWin2(data,targetname,w,h ) {
	msgWindow=window.open(data,targetname,'width='+w+',height='+h+',status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no');
	msgWindow.focus();
}

function fitListHeight(){
	if(!document.getElementById) return false;
	var docHeight,listStart,listHeight;
	var headerHeight = 0;
	var footerHeight = 25;
	var selector = "#SETAGAYAARTMUSEUMPOPUP #CONTENTS div.list";
	var sheets=document.styleSheets;

	if(document.all){
		docHeight = document.documentElement.clientHeight;
	}else{
		docHeight = self.innerHeight;
	}

	listStart = document.getElementById("LISTSTART");
	headerHeight += new Number(listStart.offsetTop);
	if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.topMargin != 'undefined') {
		headerHeight += new Number(document.body.topMargin);
	}

	listHeight = "height:" + (docHeight-headerHeight-footerHeight) + "px;";


	if(sheets){
		var tSheet=sheets[sheets.length-1];
		if(document.all){
			tSheet.addRule(selector,listHeight);
		}else{
			tSheet.insertRule(selector+"{"+listHeight+"}",tSheet.cssRules.length);
		}
	}
	if(navigator.userAgent.indexOf("Safari")!=-1){
		var contents = document.getElementById("CONTENTS");
		var divs = contents.getElementsByTagName('DIV');
		for(i=0;i<divs.length;i++){
			if(divs[i].className=="list"){
				divs[i].style.height = (docHeight-headerHeight-footerHeight-10) + "px";
			}
		}
	}
}

var docWidth;
function setAutoListHeight(){
	document.documentElement.style.overflow = "hidden";
	window.onload = function(){
		fitListHeight();
		docWidth = document.documentElement.clientWidth;
	}

	window.onresize = function(){
		var docHeight;
		if(document.all){
			window.resizeEnd = (window.resizeEnd ==null)?(new Object()):window.resizeEnd;
			clearTimeout(window.resizeEnd);
			window.resizeEnd = setTimeout(fitListHeight,1);
		}else{
			fitListHeight();
		}
	}
}

function setDetailHeight(){
	if(!document.getElementById) return false;
	var offSetHeight;
	var docWidth = 570;
	var os = navigator.userAgent.toUpperCase();
	if(os.indexOf("MAC")!=-1){
		offSetHeight = 40;
	}else if(os.indexOf("WIN")!=-1){
		offSetHeight = 45;
	}

	if(document.all){
		docHeight = document.body.clientHeight+offSetHeight;
	}else{
		docHeight = document.body.clientHeight+offSetHeight;
	}
	window.resizeTo(docWidth,docHeight);
}
function setAutoDetailHeight(){
	document.documentElement.style.overflow = "hidden";
	window.onload = function(){
		setDetailHeight();
	}
}



/*---------------------------------------------------------------*/
var global = new Object();
global.requiredSwfVer = 8;
global.swfGecko = navigator.plugins && navigator.mimeTypes.length>0 && navigator.plugins["Shockwave Flash"];
global.swfIe = window.ActiveXObject;
global.swfExec = swfPlayerExecCheck();
global.swfVer = swfPlayerVerCheck();
var navi=navigator.userAgent;
if(navi.indexOf("MSIE")!=-1 && navi.indexOf("Mac")!=-1) global.macIe = true;
/*---------------------------------------------------------------*/

/*---------------------------------------------------------------*/

document.getElementsByClassName = function(ClassName,tagName){
	if(!(this.all || this.getElementsByTagName)) return false;
	var elements=new Array();
	var allElements,i,len;

	if(tagName) allElements= this.getElementsByTagName(tagName) || this.all.tags(tagName);
	else allElements=this.all || this.getElementsByTagName("*");
	for(i=0,len=allElements.length; i<len; i++){
		if(allElements[i].className==ClassName) elements[elements.length]=allElements[i];
	}
	return elements;
}

/*---------------------------------------------------------------*/

function insertCSSRule(selector,styleSet){
	if(!document.getElementById) return false;
	var stlSht=document.styleSheets;
	var lastSht;
	if(stlSht.length){
		lastSht=stlSht[stlSht.length-1];
		if(global.macIe){
			document.write('<style type="text/css">');
			document.write(selector+'{'+styleSet+'}');
			document.write('</style>');
			document.createStyleSheet('extrastyle.css');
		}else if(document.all){
			lastSht.addRule(selector,styleSet);
		}else{
			lastSht.insertRule(selector+"{"+styleSet+"}",lastSht.cssRules.length);
		}
	}
}

/*---------------------------------------------------------------*/

if(global.swfExec && global.swfVer>=global.requiredSwfVer){

	insertCSSRule('#CONTENTS p.podcastMP3 *','display:none;');
	insertCSSRule('#CONTENTS p.podcastMP3 object','display:block;');
	insertCSSRule('#CONTENTS p.podcastMP3 embed','display:block;');
	if(document.all) insertCSSRule('#CONTENTS p.podcastMP3','height:67px;');
	else insertCSSRule('#CONTENTS p.podcastMP3','min-height:67px;');
}

function setPodCastSwf(){
	if(!document.getElementById) return false;
	var divMovie = document.getElementsByClassName("podcastMP3");
	var i,imgSrc,swfVar,swfcode;
	var len=divMovie.length;
	var chImg = new Array();
	var swfObj = new Object();

	if(!len) return false;
	for(i=0;i<len;i++){
		swfObj.id = "pdcst"+i;
		swfObj.width = "358";
		swfObj.height = "67";
		swfObj.swf = "podcast.swf";
		swfObj.flashvars = divMovie[i].title;
		swfObj.loop = "false";
		swfObj.menu = "false";
		swfObj.quality = "high";
		swfObj.bgcolor = "#FFFFFF";
		swfcode = swfDetect(swfObj);
		if(!swfcode) return false;
		divMovie[i].innerHTML = swfcode;
		divMovie[i].title = "";
	}
}

function swfDetect(swfObj){
	if(!global.swfExec || global.swfVer<global.requiredSwfVer) return false;
	
	var objcode = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
	objcode += ' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"';
	objcode += ' width="'+swfObj.width+'"';
	objcode += ' height="'+swfObj.height+'"';
	objcode += ' id="'+swfObj.id+'">';
	objcode += '<param name="allowScriptAccess" value="sameDomain">';
	objcode += '<param name="movie" value="'+swfObj.swf+'?'+swfObj.flashvars+'">';
	objcode += '<param name="loop" value="'+swfObj.loop+'">';
	objcode += '<param name="menu" value="'+swfObj.menu+'">';
	objcode += '<param name="quality" value="'+swfObj.quality+'">';
	objcode += '<param name="bgcolor" value="'+swfObj.bgcolor+'">';
	objcode += '<param name="flashvars" value="'+swfObj.flashvars+'">';

	objcode += '<embed type="application/x-Shockwave-flash" pluginspage="http://www.macromedia.com/jp/shockwave/download/?P1_Prod_Version=ShockwaveFlash"';
	objcode += ' width="'+swfObj.width+'"';
	objcode += ' height="'+swfObj.height+'"';
	objcode += ' name="'+swfObj.id+'"';
	objcode += ' allowScriptAccess="sameDomain"';
	objcode += ' src="'+swfObj.swf+'?'+swfObj.flashvars+'"';
	objcode += ' loop="'+swfObj.loop+'"';
	objcode += ' menu="'+swfObj.menu+'"';
	objcode += ' quality="'+swfObj.quality+'"';
	objcode += ' bgcolor="'+swfObj.bgcolor+'"';
	objcode += ' FlashVars="'+swfObj.flashvars+'">';
	objcode += '<\/embed>';
	objcode += '<\/object>';
	
	return objcode;
}

function swfPlayerExecCheck(){
	var exec = false;
	if(global.swfGecko){
		exec = true;
	}else if(global.swfIe){
		/*@cc_on
		@if(@_jscript_version >= 5.0)
		try{
			var player = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			exec = true;
		}catch(e){}
		@end @*/
	}
	return exec;
}

function swfPlayerVerCheck(){
	var ver,player;
	
	if(global.swfExec){
		if(global.swfGecko){
			player = navigator.plugins["Shockwave Flash"];
			if(player.description.match(/([0-9]+)\.([0-9]+)\s+r([0-9]+)/)!=null){
				ver = RegExp.$1;
			}
		}else if(global.swfIe){
			/*@cc_on
			@if(@_jscript_version >= 5.0)
			try{
				player = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				ver = Math.floor(player.FlashVersion()/ 0x10000);
			}catch(e){}
			@end @*/
		}
	}
	return ver;
}

/*---------------------------------------------------------------*/

function addEvent(obj,handle,lstnr) {
	if(obj.addEventListener){
		obj.addEventListener(handle,lstnr,false);
	}else if(obj.attachEvent){
		handle = "on" + handle;
		var oldfunc = obj[handle];
		if(typeof oldfunc != "function"){
			obj[handle] = lstnr;
		}else{
			obj.attachEvent(handle,lstnr);
		}
	}else{ // MacIE
		handle = "on"+handle;
		var oldfunc = obj[handle];
		if(typeof oldfunc != "function"){
			obj[handle] = lstnr;
		}else{
			obj[handle] = function(){oldfunc();lstnr();};
		}
	}
}
window.addOnload = function(lstnr){
	addEvent(window,'load',lstnr);
}
window.addOnload(setPodCastSwf);
/*---------------------------------------------------------------*/
