var AFL_currentScript = (function (e) { if(e.nodeName.toLowerCase() == 'script') return e; return arguments.callee(e.lastChild) })(document);
if(typeof Affilet == "undefined"){
var Affilet = {
	Domain : "http://affilet.jp",
	Init : function() {
		var scripts = document.getElementsByTagName('script');
		for(var i=0, len = scripts.length ; i < len ; i++) {
			var src = scripts[i].src;
			if(src.indexOf("affilet") != -1 && src.indexOf("http://") != -1) this.Domain = src.match(/http:\/\/[^\/]+/)[0];
		}
	},
	
	GetSize : function() {
		var size = {};
		
		size.winWidth = document.documentElement.clientWidth || document.body.clientWidth || window.innerWidth;
		size.winHeight = document.documentElement.clientHeight || document.body.clientHeight || window.innerHeight;
		size.scrollY = document.body.scrollTop  || document.documentElement.scrollTop;
		if (document.compatMode == 'CSS1Compat') {
			size.pageWidth = (document.documentElement.scrollWidth > size.winWidth)?  document.documentElement.scrollWidth : size.winWidth;
			size.pageHeight = (document.documentElement.scrollHeight > size.winHeight)?  document.documentElement.scrollHeight : size.winHeight;
		} else {
			size.pageWidth = (document.body.scrollWidth > size.winWidth)?  document.body.scrollWidth : size.winWidth;
			size.pageHeight = (document.body.scrollHeight > size.winHeight)?  document.body.scrollHeight : size.winHeight;
		}
		
		return size;
	},

	EditorPopup : function(url) {
		var size = Affilet.GetSize();
		
		Affilet.VisibleSwfs(false);
		var el = document.body.appendChild(document.createElement('div'));
		el.id = "affileteditor";
	
		el.innerHTML = '<div style="background-color:#ffffff;filter:Alpha(opacity=80);opacity:0.8;position:absolute;left:0px;top:0px;width:'+size.winWidth+'px;height:' + size.pageHeight +'px;z-index:1000;cursor:pointer;" onclick="Affilet.ClosePopup(' + "'affileteditor'" + ');"></div><div id="indicator" style="background-color:#ffffff;text-align:center;margin:-50px 0 0 -100px; padding: 5px width: 201px;height:101px;position: absolute;top: ' + (size.scrollY + size.winHeight/2) + 'px;left: 50%;z-index:1001;"><img width=162 height=60 border=0 src="'+this.Domain+'/img/logo.gif" /><p style="margin-top:10px">アフィレットエディタを表示中です。<br/>クリックすると元に戻ります<p></div>';
		var open = function() {
			if(!window.open(url,'_blank','toolbar=no,location=yes,resizable=yes,scrollbars=yes,status=yes,width=820,height=640')) window.open(url,'_blank');
		}
		
		// escape popup block
		if(/Firefox/.test(navigator.userAgent)) setTimeout(open, 0);
		else open();
	},

	ClosePopup : function(id) {
		var el = document.getElementById(id);
		if(el) {
			document.body.removeChild(el);
			Affilet.VisibleSwfs(true);
		}
	},

	SizePreview : function(f, w, h, ho, id, fg, bg) {
		var size = Affilet.GetSize();
		
		Affilet.VisibleSwfs(false);
		var el = document.body.appendChild(document.createElement('div'));
		el.id = "affilet-size-preview";
		el.innerHTML = '<div style="background-color:#ffffff;filter:Alpha(opacity=80);opacity:0.8;position:absolute;left:0px;top:0px;width:'+size.winWidth+'px;height:' + size.pageHeight +'px;z-index:1000;cursor:pointer;" onclick="Affilet.ClosePopup(' + "'affilet-size-preview'" + ');"></div><div style="position:absolute;top:' + (size.scrollY + (size.winHeight - h)/2) + 'px;left:'+ (size.winWidth - w)/2 +'px;z-index:1002"><p><a href="javascript:Affilet.ClosePopup(' + "'affilet-size-preview'" + ');">もどる</a></p><div id="affilet-preview-'+id+'"></div></div>';
		SetAffilet(f, w, h, ho, id, 'present_full', fg, bg, 'preview-', true);
	},

	VisibleSwfs : function(state) {
		var swfs = document.getElementsByTagName('embed');
		if(swfs.length == 0) swfs = document.getElementsByTagName('object');
		if(swfs.length > 0) for(var i=0, len=swfs.length ; i < len ; i++) swfs[i].style.visibility = state ? 'visible' : 'hidden';
	}
};

Affilet.Init();

function SetAffilet(f, w, h, ho, id, sm, fg, bg, suf, noref, ver, mm) {
	if(!ver) {
		var AFL_p = AFL_currentScript.nextSibling || AFL_currentScript.parentNode.nextSibling;
		if(AFL_p) {
			while(AFL_p && AFL_p.nodeName.toLowerCase() != 'script') {
  	  	if(AFL_p.nodeName.toLowerCase() == 'img' && AFL_p.src.indexOf('affiliate.recruit.jp') != -1) AFL_p.src = "";
	  	  AFL_p = AFL_p.nextSibling || AFL_currentScript.parentNode.nextSibling;
			}
		} else {
			var images = document.getElementsByTagName('img');
			for(var i=0, len = images.length ; i < len ; i++) if(images[i].src.indexOf('affiliate.recruit.jp') != -1) images[i].src = "";
		}
	}
	if(!suf) suf = "";
	var el = document.getElementById("affilet-"+ suf + id);
	if(el) {
		el.style.background = "";
		el.style.width = w + 'px';
		el.style.height = h + 'px';
		var aswfo = new SWFObject("http://"+f, "affiletswf"+suf+id, w, h, "8", el.parentNode.style.bgColor);
		aswfo.addParam('allowScriptAccess', 'always');
		if(suf == '') aswfo.addParam('wmode', 'transparent');
		aswfo.addVariable("host", "http://"+ho);
		aswfo.addVariable("id", id);
		if(f.indexOf("sugo_map") != -1) {
		  aswfo.addParam('menu', 'false');
  		aswfo.addVariable("map_mode", mm);		  
		} else {
   		aswfo.addVariable("sheet_mode", sm);
  		aswfo.addVariable("fgcolor", fg);
      aswfo.addVariable("bgcolor", bg)
	 	}
		if(!noref) aswfo.addVariable("ref", encodeURIComponent(location.href));
		aswfo.write("affilet-"+ suf + id);
	}
}
}
