//////////////////////////////////////////////////////////////////////////////////////////

	Function.prototype.applyTimeout = function(ms, self, args)
	{
	  	var f = this;
		var args = args || [];//ie用
		
		return setTimeout(function () {f.apply(self, args);},ms);
	};

	Function.prototype.applyInterval = function (ms, self, args) 
	{
		var f = this;
		var args = args || [];//ie用
		return setInterval(function () {f.apply(self, args);},ms);
	};
	
	//Imageオブジェクト付加系関数群///////////////////////////////////////////////////////////////////////
	
	var imgProtoApplyObj = {
								bigImage	:	"",
								sourceLink	:	"",
								permaLink	:	"",
								reblogLink	:	"",
								likeData	:	"",
								siteName	:	"this tumblr"
							};
	
	function imgProtoLoadAndPush(_imgObj,_siteName,_size,_uniqueId)
	{
		this.src = _imgObj["photo-url-"+_size];
		this.alt = this.title =  imgFilterTitle(_imgObj["photo-caption"]);
		this.applyObj = 
		{
			bigImage	:	_imgObj["photo-url-500"],
			sourceLink	:	_imgObj["photo-link-url"]	||	_imgObj["url"],
			permaLink	:	_imgObj["url"],
			reblogLink	:	"http://www.tumblr.com/reblog/"+_imgObj["id"]+"/"+_imgObj["reblog-key"],
			likeData	:	"post-id="+_imgObj["id"]+"&reblog-key="+_imgObj["reblog-key"],
			siteName	:	_siteName
		}
		this.uniqueId = _uniqueId;
		
		this.timeoutId;
		this.intervalCount = _size/2;
		this.imgProtoCheckLoadImg();
	};
	
	function imgProtoCheckLoadImg()
	{
		if(this.complete && TumblrApiManager.uniqueId == this.uniqueId)
		{			
			TumblrImgPutManager.loadedList.push(this);
			clearTimeout(this.timeoutId);
			
			this.timeoutId = 
			this.intervalCount =
			this.uniqueId = null;
		}
		else if(this.intervalCount<0)
		{
			clearTimeout(this.timeoutId);
			TumblrImgLoadManager.imgCount--;
			
			this.src = "./img/null.gif";
			this.alt = this.title = "";
			this.applyObj = 
			this.timeoutId = 
			this.intervalCount = null;
			
		}
		else
		{
			clearTimeout(this.timeoutId);
			this.intervalCount--;
			this.timeoutId = arguments.callee.applyTimeout(200,this);
		}
	};
	
	function imgFilterTitle(c)
	{
			var tmp = document.createElement("div");
			tmp.innerHTML = c;
			tmp = tmp.getElementsByTagName("a");
			if(!tmp.length){return "no title";}
			tmp = tmp[tmp.length-1];
			if(!tmp.firstChild){return "no title";}
			tmp = tmp.firstChild.nodeValue;
			return tmp;
	}
	
	var browserType	=	(function()
						{
							var r = navigator.userAgent;
							
							r = r.indexOf("MSIE") != -1	?	"IE"
							:	r.indexOf("iPhone") != -1	?	"iPhone"
							:	r.indexOf("Safari") != -1	?	"Safari"
							:	r.indexOf("Opera") != -1	?	"Opera"
							:	r.indexOf("Firefox") != -1	?	"Firefox"
							:	"Other";
							
							return r;
						})();
						
	
	var safeDocument	=	browserType == "Safari"	?	document.body
													:	document.documentElement;
	
	var cookieManager =
	{
		cookieObj	:	{},
		setFavLists	:	function()
						{
							var lists = this.cookieObj.favorite.lists;
							for(var i=0,l=lists.length;i<l;i++)
							{
								headerPanel.addFavList(unescape(lists[i].name));
							}
							
							i = this.cookieObj.favorite.select < l	?	this.cookieObj.favorite.select	:	0	;
							headerPanel.loadFavList(i);
						},
		setDefCookie:	function()
						{
							this.cookieObj = {};
							
							this.cookieObj.ver = 2.5;
							
							this.cookieObj.favorite = {};
							this.cookieObj.favorite.select = 0;
							this.cookieObj.favorite.lists = [];
							this.cookieObj.favorite.lists[0] = {name:"TempList",list:[{id:"proto-jp",num:50}]};
							
							this.cookieObj.directory = {};
							this.cookieObj.directory.select = "";
							
							this.cookieObj.setting = {};
							this.cookieObj.setting.imageSize = 100;
							this.cookieObj.setting.imageNum = 50;
							this.cookieObj.setting.email = "";
							this.cookieObj.setting.password = "";
							this.cookieObj.setting.zoomImageType = "500";
							this.cookieObj.setting.randomType = "ALL";
						},
	oldCookieCheck	:	function(_cookie)
						{
							var i,a=[], o={}, c = eval("(" + _cookie +")");
							
							o.ver = 2.5;
							o.favorite = {};
							o.favorite.select = 0;
							o.favorite.lists = [];
							
							if(c[0].idList.length)
							{
								for(i=0;i<c[0].idList.length;i++)
								{
									a.push({id:c[0].idList[i].name,num:50});
								}
								o.favorite.lists[0] = {name:"TempList",list:a};
							}
							else
							{
								o.favorite.lists[0] = {name:"TempList",list:[{id:"proto-jp",num:50}]};
							}
							
							o.directory = {};
							o.directory.select = "";
							
							o.setting = {};
							o.setting.imageSize = 100;
							o.setting.imageNum = 50;
							o.setting.email = "";
							o.setting.password = "";						
							o.setting.zoomImageType = "500";
							o.setting.randomType = "ALL";
							
							
							
							this.cookieObj = o;
							this.saveCookie();
						},			
		loadCookie	:	function()
						{
							if($.cookie("_tmvProtoJp_2"))
							{
								this.cookieObj = eval("(" + $.cookie("_tmvProtoJp_2") +")");
								
								if(this.cookieObj.ver == 2)
								{
									this.cookieObj.ver = 2.5;
									
									this.cookieObj.directory = {};
									this.cookieObj.directory.select = "";
									
									this.cookieObj.setting.email = "";
									this.cookieObj.setting.password = "";
									
									this.saveCookie();
								};
							}
							else if($.cookie("_tmvProtoJpVale"))
							{
								this.oldCookieCheck($.cookie("_tmvProtoJpVale"));
							}
							else
							{
								this.setDefCookie();
								this.saveCookie();
							}
							
							delete this.setDefCookie;
							delete this.oldCookieCheck;
						},
		saveCookie	:	function()
						{
							$.cookie("_tmvProtoJp_2",JSON.Encode(this.cookieObj),{expires:99999});
						}
	}
	cookieManager.loadCookie();
	
	
	var spriteBtns = 
	{
		bgImg		:	"./img/SpriteBtns.gif",
		hoverRoll	:	function(_target)
						{
							$(_target).hover
							(
								function()
								{
								
									if(this.className.indexOf("locked") != -1 || this.className.indexOf("over") != -1)return;
									
									this.className += " over";
																			
									var s = this.style.backgroundPosition.split(" ");
									this.style.backgroundPosition = (parseInt(s[0]) - parseInt(this.style.width)) + "px " + s[1];
								},
								function()
								{
								
									if(this.className.indexOf("locked") != -1 || this.className.indexOf("over") == -1)return;

									this.className = this.className.replace("over","");
									
									var s = this.style.backgroundPosition.split(" ");
									this.style.backgroundPosition = (parseInt(s[0]) + parseInt(this.style.width)) + "px " + s[1];
								}
							);
						},
		init		:	function()
						{
							with(new Image()){src = this.bgImg};/*dummyでimgロード	*/
						}
	}
	spriteBtns.init();
	
	
	var layerManager = 
	{
		alphaBg		:	document.createElement("div"),
		enable		:	false,
		resize		:	function()
						{
							
							this.alphaBg.style.width = safeDocument.scrollWidth + "px";
							this.alphaBg.style.height = safeDocument.scrollHeight + "px";
						},
		argElems	:	[],
		setLayer	:	function()
						{	
							this.argElems = arguments || [];
							
							for(var i=0;i<this.argElems.length;i++)
							{
								this.alphaBg.appendChild(this.argElems[i]);
							}
							
							this.resize();
							this.alphaBg.style.display = "block";
							this.enable = true;
						},
		close		:	function()
						{
							this.alphaBg.style.display = "none";
							this.closeListener();
								
							for(var i=0;i<this.argElems.length;i++)
							{
								this.alphaBg.removeChild(this.argElems[i]);
							}
							
							this.argElems = null;
							this.closeListener = function(){};
							this.enable = false;
						},
		closeListener:	function(){},
		init		:	function()
						{
							
							with(this.alphaBg.style)
							{
								position = "absolute";
								top = 0;
								backgroundImage = "url(./img/alpha50.gif)";
								zIndex = 20;
								display = "none";
							}
							
							$(this.alphaBg).click(function(e){if(e.target.className.indexOf("notClose") == -1)layerManager.close();});
							document.body.appendChild(this.alphaBg);
						}
	}
	layerManager.init();
	
	
	var zoomImgManager = 
	{
		selectImg	:	{},
		bgImg		:	spriteBtns.bgImg,
		lowResImg	:	new Image(),
		highResImg	:	new Image(),
		btnPrev		:	document.createElement("a"),
		btnNext		:	document.createElement("a"),
		btnSource	:	document.createElement("a"),
		btnLike		:	document.createElement("a"),
		btnReblog	:	document.createElement("a"),
		uiLink		:	document.createElement("a"),
		uiArea	 	:	document.createElement("div"),
		uiTitle		:	document.createElement("div"),
		uiBg		:	document.createElement("div"),
		photoFrame	:	document.createElement("div"),
		frameW		:	6,
		popup		:	function(_targetImg)
						{
							this.selectImg = _targetImg;

							var scrollWidth = safeDocument.scrollWidth;
							var scrollHeight = safeDocument.scrollHeight;
							var clientHeight = window.innerHeight || safeDocument.clientHeight;							
							var scrollTop = safeDocument.scrollTop;
							
							
							!layerManager.enable	? layerManager.setLayer(this.uiArea,this.photoFrame)	:	null;
							
							
							var tmpImgH = _targetImg.height * 5;
							tmpImgH = tmpImgH < 168	?	168	
													:	tmpImgH > 700	?	700
																		:	tmpImgH;
							
							this.photoFrame.style.height = (tmpImgH + this.frameW*2) + "px";
							this.photoFrame.style.left = (scrollWidth - parseInt(this.photoFrame.style.width)) /2 + "px";
							this.photoFrame.style.top = (clientHeight - parseInt(this.photoFrame.style.height)) /2 + scrollTop +"px";
							
							this.lowResImg.style.top = this.lowResImg.style.left = this.frameW+"px";
							this.lowResImg.style.display = "block";
							this.lowResImg.src = _targetImg.src;
							this.lowResImg.style.height = tmpImgH + "px";
							
							
							this.uiTitle.innerHTML = _targetImg.alt;
							this.uiLink.innerHTML = _targetImg.applyObj.siteName;
							this.uiLink.href = _targetImg.applyObj.permaLink;
							
							this.uiArea.style.display = "block";
							this.uiArea.style.left = parseInt(this.photoFrame.style.left)-20 + "px";
							this.uiArea.style.top = (parseInt(this.photoFrame.style.height)-180)/2 + parseInt(this.photoFrame.style.top) +"px";
							
							this.btnReblog.setAttribute("onclick", "javascript:selectImageManager.reblogThis('"+_targetImg.applyObj.reblogLink+"');return false;");
							this.btnReblog.href = _targetImg.applyObj.reblogLink;
							this.btnSource.href = _targetImg.applyObj.sourceLink;
							this.btnLike.href = "javascript:selectImageManager.likeThis('"+_targetImg.applyObj.likeData+"')";
							
							this.visibleUi(false);
							
							
							//<--IE対策のため常にnewする
							this.highResImg.src = null;
							this.photoFrame.removeChild(this.highResImg);
							this.highResImg = new Image();
							with(this.highResImg.style) 
							{
								top = left = this.frameW+"px";
								position = "absolute";
								display = "none";
								zIndex = 25;
							}
							$(this.highResImg).hover
							(
								function(e){zoomImgManager.visibleUi(true)},
								function(e){zoomImgManager.visibleUi(false)}
							);
							this.photoFrame.appendChild(this.highResImg);
							//IE対策のため常にnewする//end-->
							this.highResImg.src = _targetImg.applyObj.bigImage;
							this.highResImg.style.top = this.highResImg.style.left = this.frameW+"px";
							this.highResImg.onload ="";
							this.highResImg.onload = function(e)
							{
								var fMargin = 6;
								
								this.style.display = "block";
								
								this.style.left = this.width < 500	?	(500-this.width)/2+fMargin + "px"
																	:	fMargin+ "px";								
								
								var fHeight = parseInt(zoomImgManager.photoFrame.style.height) - fMargin*2;
								this.style.top = fHeight > this.height	?	(fHeight-this.height)/2+fMargin+ "px"
																		:	fMargin+ "px";
																				
								this.style.display = "none";
																																
								
								$(this).fadeIn("normal",zoomImgManager.visibleUi(false));
								
								if (this.height < fHeight || this.width < 500)
								{
									$(zoomImgManager.lowResImg).fadeOut("slow");
								}
							}
						},
		changePhoto	:	function(_type)
						{
							var num = parseInt(this.selectImg.id.replace("imgID_",""));
							var iCount = contentMosaic.imgCount-1;
							
							
							num = _type=="next"	?	num == iCount	?	0
																	:	num+1
												:	num == 0	?	iCount
																:	num-1;
																			
							this.popup(document.getElementById("imgID_"+num));
							
							selectImageManager.imgFocus(document.getElementById("imgID_"+num));
							
							this.visibleUi(true);
						},				
		visibleUi	:	function(_bool)
						{
							this.uiBg.style.display = 
							this.btnSource.style.display = 
							this.btnLike.style.display = 
							this.btnReblog.style.display =
							this.uiTitle.style.display = 
							this.uiLink.style.display = _bool	?	"block"	:	"none";
						},
		init		:	function()
						{							
							with(this.lowResImg.style)
							{
								width = "500px";
								position = "absolute";
								top = left = this.frameW+"px";
								zIndex = 24;
							}
							$(this.lowResImg).hover
							(
								function(e){zoomImgManager.visibleUi(true)},
								function(e){zoomImgManager.visibleUi(false)}
							);
							this.photoFrame.appendChild(this.lowResImg);
							
							
							this.photoFrame.appendChild(this.highResImg);

							
							with(this.uiArea.style)
							{
								width = 540 + this.frameW*2 +"px";
								height = "180px";
								display = "none";
								position = "absolute";
								overflow = "hidden";
								zIndex = 26;
							}
							$(this.uiArea).mouseover(function(e){zoomImgManager.visibleUi(true)});
							$(this.uiArea).mouseout(function(e){zoomImgManager.visibleUi(false)});
							
							
							with(this.uiBg.style)
							{
								width = 500 + this.frameW*2 + "px";
								height = "180px";
								position = "absolute";
								left = "20px";
								backgroundColor = "#fff";
							}
							$(this.uiBg).css("opacity",0.6);
							this.uiArea.appendChild(this.uiBg);
							
							
							with(this.uiTitle.style)
							{
								top = "10px";
								left = "36px";
								width = "480px";
								height = "auto";
								position = "absolute";
								fontSize = "150%";
							}
							this.uiTitle.className = "notClose";
							this.uiArea.appendChild(this.uiTitle);
							
							
							with(this.uiLink.style)
							{
								top = "122px";
								left = "36px";
								position = "absolute";
								color = "#0ff";
							}
							this.uiLink.className = "notClose";
							this.uiLink.target = "_blank";
							$(this.uiLink).hover
							(
								function(){this.style.color = "#f00";},
								function(){this.style.color = "#0ff";}
							)
							this.uiArea.appendChild(this.uiLink);
							
							
							with(this.btnSource.style)
							{
								position = "absolute";
								top = "122px";
								left = "328px";
								width = height = "48px";
								backgroundImage = "url("+this.bgImg+")";
								backgroundPosition = "-80px -96px";
							}
							this.btnSource.title = "JUMP TO SOURCE";
							this.btnSource.target = "_blank";
							this.btnSource.className = "notClose";
							this.uiArea.appendChild(this.btnSource);
							spriteBtns.hoverRoll(this.btnSource);
							
							
							with(this.btnLike.style)
							{
								position = "absolute";
								top = "122px";
								left = "386px";
								width = height = "48px";
								backgroundImage = "url("+this.bgImg+")";
								backgroundPosition = "-80px -48px";
							}
							this.btnLike.title = "LIKE THIS";
							this.btnLike.className = "notClose";
							this.uiArea.appendChild(this.btnLike);
							spriteBtns.hoverRoll(this.btnLike);
							
							
							with(this.btnReblog.style)
							{
								position = "absolute";
								top = "122px";
								left = "444px";
								width = "72px";
								height = "48px";
								backgroundImage = "url("+this.bgImg+")";
								backgroundPosition = "-80px 0";
							}
							this.btnReblog.title = "REBLOG THIS";
							this.btnReblog.className = "notClose";
							this.uiArea.appendChild(this.btnReblog);
							spriteBtns.hoverRoll(this.btnReblog);
							
							
							with(this.btnPrev.style)
							{
								position = "absolute";
								top = left = 0;
								width = "20px";
								height = "180px";
								backgroundImage = "url("+this.bgImg+")";
								backgroundPosition = "0 0";
							}
							this.btnPrev.title = "PREV";
							this.btnPrev.href = "javascript:zoomImgManager.changePhoto('prev');";
							this.btnPrev.className = "notClose";
							this.uiArea.appendChild(this.btnPrev);
							spriteBtns.hoverRoll(this.btnPrev);
							
							
							with(this.btnNext.style)
							{
								position = "absolute";
								top = 0;
								left = "532px";
								width = "20px";
								height = "180px";
								backgroundImage = "url("+this.bgImg+")";
								backgroundPosition = "-40px 0";
							}
							this.btnNext.title = "NEXT";
							this.btnNext.href = "javascript:zoomImgManager.changePhoto('next');";
							this.btnNext.className = "notClose";
							this.uiArea.appendChild(this.btnNext);
							spriteBtns.hoverRoll(this.btnNext);
							
							
							with(this.photoFrame.style)
							{
								position = "relative";
								backgroundColor = "#fff";
								width = "512px";
								height = "512px";
							}
							$(this.photoFrame).mouseover(function(e){zoomImgManager.visibleUi(true)});
							$(this.photoFrame).mouseout(function(e){zoomImgManager.visibleUi(false)});
						}
	}
	zoomImgManager.init();

	
	var headerPanel = 
	{
		fukidasi	:	new Image(),
		mainFrame	:	document.createElement("div"),
		mainArea 	:	document.createElement("div"),
		favFrame	:	document.createElement("div"),
		favSetBtn	:	document.createElement("a"),		
		favList		:	document.createElement("ul"),
		favListIndex:	0,
		addFavList	:	function(_name)
						{
							var l = document.createElement("li");
							var a = document.createElement("a");
							var t = document.createTextNode(_name);
							
							l.id = "favID_" + this.favListIndex;
							l.style.cssText = "float:left;margin:0 30px 10px 0;";
							
							$(l).hover
							(
								function()
								{
									this.appendChild(headerPanel.favSetBtn);
									var index = parseInt(this.id.slice(6));
									var pos = $(headerPanel.favSetBtn).position();
									
									headerPanel.favSetBtn.href = "javascript:settingUiManager.settingList('"+ index +"',"+pos.top+","+pos.left+")";
								},
								function()
								{
									this.removeChild(headerPanel.favSetBtn);
								}
							);
							
							with(a.style)
							{
								position = "relative";
								padding = "0 4px";
								color = "#f00";
								fontSize = "80%";
								verticalAlign = "top";
								backgroundImage = "url(null)";
							}
							a.onclick = function(){headerPanel.changeFavList(this.parentNode.id.slice(6));return false;};
							a.href = "javascript:void(0)";
							a.appendChild(t);
							l.appendChild(a);
							this.favList.appendChild(l);
							
							this.favListIndex++;
						},	
		changeFavList:	function(_index)
						{								
							
							scrollManager.allowScroll(true);
							document.getElementById("tmvContent").innerHTML = "";
							TumblrApiManager.List.innerHTML = "";
							contentMosaic.imgCount = 0;
							
							this.loadFavList(_index);
							cookieManager.cookieObj.favorite.select = _index;
							cookieManager.saveCookie();
							
							
							TumblrImgLoadManager.imgSize = 
							contentMosaic.imgWidth = parseInt(cookieManager.cookieObj.setting.imageSize);
							
							TumblrApiManager.refresh();
							TumblrImgLoadManager.refresh();
							TumblrImgPutManager.refresh();
							selectImageManager.refresh();
						},
		loadFavList	:	function(_index)
						{
							var target = cookieManager.cookieObj.favorite.lists[_index].list;
							for(var i=0,l=target.length;i<l;i++)
							{/*実際のmosaic viewに登録*/
								TumblrApiManager.addHtmlList(target[i].id,target[i].num);
							}
							
							for(var i=0,l=this.favList.childNodes.length;i<l;i++)
							{
								target = this.favList.childNodes[i].firstChild;
								if(i==_index)
								{
									target.className = "selected";
									target.style.color = "#fff";
									target.style.backgroundColor = "#f00";
									target.style.textDecoration = "none";
								}
								else
								{
									target.className = "";
									target.style.color = "#f00";
									target.style.backgroundColor = "#fff";
								}
							}
							
							this.mainArea.appendChild(this.favFrame);
							$(this.mainFrame).css("opacity",1);
						},
		resize		:	function()
						{
							this.mainArea.style.width = $('body').innerWidth() - 290 + "px";
						},
		refresh		:	function()
						{
							this.mainArea.firstChild	?	this.mainArea.removeChild(this.mainArea.firstChild)	:	null;
							this.favList.innerHTML = "";
							this.favListIndex = 0;
							$(this.mainFrame).css("opacity",0.3);
						},			
		init		:	function(_SB)
						{
							with(this.mainFrame.style)
							{
								position = "absolute";
								
								top = "10px";
								width = "auto";
								height = "180px";
								margin = "0px 10px 0 280px";
								
								backgroundImage = "url(./img/ichimatsu_f00.gif)";
								border = "solid 1px transparent";
							}
							
							with(this.mainArea.style)
							{
								height = "100%";
								overflowY = "auto";
								overflowX = "hidden";
								backgroundColor = "#fff";
							}
							
							this.fukidasi.src = "./img/panelFukiDasi.gif";
							with(this.fukidasi.style)
							{
								position="absolute";
								display = "none";
								top = "191px";
								zIndex = 19;
							}
							
							
							var titleFav = document.createElement("div");
							with(titleFav.style)
							{
								position  ="relative";
								height = "28px";
								width = "200px";
								marginTop = "10px";
								backgroundImage = "url(./img/ichimatsu_fcc.gif)";
							}
							
							var imgFav = new Image();
							imgFav.src = "./img/title_favorite.gif";
							with(imgFav.style)
							{
								position = "absolute";
								top = "5px";
								left = "8px";
							}
							
							var addBtn = document.createElement("a")
							with(addBtn.style)
							{
								top = "4px";
								left = "176px";
								position = "absolute";
								width = height =  "20px";
								backgroundImage = "url("+_SB.bgImg+")";
								backgroundPosition="-176px -96px";
							}
							addBtn.title="ADD NEW LIST";
							addBtn.href = "javascript:settingUiManager.makeNewList();";
							
							_SB.hoverRoll(addBtn);
							
							
							with (this.favList.style) 
							{
								listStyleType = "none";
								width = height = "auto";
								verticalAalign = "bottom";
								padding = 0;
								margin ="10px";
							}
							
							titleFav.appendChild(imgFav);
							titleFav.appendChild(addBtn);
							this.favFrame.appendChild(titleFav);
							this.favFrame.appendChild(this.favList);
							this.mainArea.appendChild(this.favFrame);
							
							this.mainFrame.appendChild(this.mainArea);
							document.getElementById("tmvheader").appendChild(this.mainFrame);
							document.getElementById("tmvheader").appendChild(this.fukidasi);
							
							
							with(this.favSetBtn.style)
							{
								position = "absolute";								
								width = height = "20px";
								backgroundImage = "url("+_SB.bgImg+")";
								backgroundPosition="-176px -136px";
							}
							this.favSetBtn.href = "#";
							this.favSetBtn.title="LIST SETTING";
							
							this.resize();
							_SB.hoverRoll(this.favSetBtn);
						}
	}
	headerPanel.init(spriteBtns);


	
	var formManager = 
	{
		submit		:	function()
						{
							scrollManager.allowScroll(true);
							TumblrApiManager.filterList(document.getElementById("searchBox").value,"");
						}
	}
	
	var settingUiManager = 
	{
		lists		:	document.createElement("div"),
		eList		:	document.createElement("div"),
		eListName	:	document.createElement("input"),
		eListIndex	:	document.createElement("input"),
		eListFrame	:	document.createElement("form"),
		newList		:	document.createElement("form"),
		addList		:	document.createElement("div"),
		btnOkArea	:	document.createElement("div"),
		PDnums		:	[25,50,75,100,150,200,250,300,350,400,450,500],
		ArrayInsert	:	function(_obj, _index, _targetArr)
						{
							 var newArr = _targetArr.slice(0, _index);
							 newArr.push(_obj);
							 newArr = newArr.concat(_targetArr.slice(_index , _targetArr.length));
							 
							 return newArr;
						},
		ArrayOmit	:	function(_index,_targetArr)
						{
							return _targetArr.slice(0, _index).concat(_targetArr.slice(_index + 1, _targetArr.length));	
						},
		makePDnums	:	function(_defValue,_name)
						{
							var o,p = this.PDnums,s = document.createElement("select");
							for(var i=0;i<p.length;i++)
							{
								o = document.createElement("option");
								o.className = "notClose";
								o.value = p[i];
								o.appendChild(document.createTextNode(p[i]));
								_defValue == p[i]	?	o.selected = true	:	null;
								
								s.appendChild(o)
							}
							s.name = _name;
							with(s.style)
							{
								margin = padding = 0;
								width = "60px";
							}
							return s;
						},
		makeList	:	function(_listObj)
						{							
							this.eList.innerHTML = "";
							
							var i,d,n;
							for(i=0;i<_listObj.list.length;i++)
							{
								d = document.createElement("div");
								d.id = "Id_" + i;
								d.className = "notClose";
								d.style.position = "relative";
								
								$(d).hover
								(
									function()
									{
										this.style.backgroundColor = "#f00";
									},
									function()
									{
										this.style.backgroundColor = "#fff";
									}
								);
								
								n = document.createElement("input");
								n.className = "notClose";
								n.name = "id_" + i;
								n.type = "text";
								n.value = _listObj.list[i].id;
								
								with(n.style)
								{
									width = "100px";
									margin = "5px";
								};
								
								d.appendChild(n);
								
								var p = this.makePDnums(_listObj.list[i].num, "num_"+i);
								p.className = "notClose";
								d.appendChild(p);
								
								
								n = document.createElement("input");
								n.className = "notClose";
								n.type = "button";
								n.value = " ";
								n.title = "ADD ID";
								n.onmouseover = function()
								{
									this.style.backgroundImage = "url(./img/SpriteBtns.gif)";
									this.style.backgroundPosition="-196px -96px";	
								};
								n.onmouseout = function()
								{
									this.style.backgroundImage = "url(./img/SpriteBtns.gif)";
									this.style.backgroundPosition="-176px -96px";
								};
								n.onclick = function()
								{
									settingUiManager.addList(parseInt(this.parentNode.id.slice(3)));
								};
								with(n.style)
								{
									marginLeft = "5px";
									width = height = "20px";
									border = "none";
									//fontWeight = "bolder";
									backgroundImage = "url(./img/SpriteBtns.gif)";
									backgroundPosition="-176px -96px";
								}
								d.appendChild(n);
								
								
								n = document.createElement("input");
								n.className = "notClose";
								n.type = "button";
								n.value = " ";
								n.title = "DELETE ID";
								n.onmouseover = function()
								{
									this.style.backgroundImage = "url(./img/SpriteBtns.gif)";
									this.style.backgroundPosition="-196px -116px";	
								};
								n.onmouseout = function()
								{
									this.style.backgroundImage = "url(./img/SpriteBtns.gif)";
									this.style.backgroundPosition="-176px -116px";
								};
								n.onclick = function()
								{
									settingUiManager.delList(parseInt(this.parentNode.id.slice(3)));
								};
								with(n.style)
								{
									marginLeft = "1px";
									width = height = "20px";
									border = "none";
									backgroundImage = "url(./img/SpriteBtns.gif)";
									backgroundPosition="-176px -116px";
								}
								d.appendChild(n);
								
								this.eList.appendChild(d);
							}
							
							return this.eList;
						},
		addList		:	function(_index)
						{
							var newId = prompt("Input tumblr ID","");
							if(!newId || newId.length<2)return;
							
							var target = cookieManager.cookieObj.favorite.lists[this.eListIndex.value];
							target.list = this.ArrayInsert({id:newId,num:50},_index+1,target.list);
							this.makeList(target);
							
							cookieManager.saveCookie();
						},
		delList		:	function(_index)
						{
							var target = cookieManager.cookieObj.favorite.lists[this.eListIndex.value];
							
							if(target.list.length==1){alert("This is last ID. can't delete.");return;}
							
							if(confirm("Delete this ID?"))
							{
								target.list = this.ArrayOmit(_index,target.list);
								this.makeList(target);
								cookieManager.saveCookie();
							}
						},				
		makeFavList	:	function(_listObj,_index)
						{
							this.eListIndex.value = _index;
							this.eListName.value = unescape(_listObj.name);
							
							this.eListFrame.appendChild(this.makeList(_listObj));
							this.eListFrame.appendChild(this.btnOkArea);
							
							layerManager.setLayer(this.eListFrame);/*背景アルファ呼び出し	*/
						},
		settingList	:	function(_favListIndex, _top, _left)
						{
							
							var left = _left + 210 + 240 > $("body").innerWidth()	?	$("body").innerWidth()	-	250
																					:	_left + 170;
							this.eListFrame.style.top = _top + 30 + "px";
							this.eListFrame.style.left = left + "px";
							
							var target = cookieManager.cookieObj.favorite.lists[_favListIndex];
							this.makeFavList(target,_favListIndex);
						},			
		makeNewList	:	function()
						{
							layerManager.setLayer(this.newList);
							this.newList.listName.focus();
						},
		saveNewList	:	function()
						{
							var _name = escape(settingUiManager.newList.listName.value);
							var _id = settingUiManager.newList.firstId.value;
							var _num = settingUiManager.newList.imgNum.value;
							
							if (!_name || _id.length < 2){alert("Please input");return;};
							
							
							cookieManager.cookieObj.favorite.lists.push({name:_name,list:[{id:_id,num:_num}]});
							cookieManager.saveCookie();
							
							headerPanel.addFavList(unescape(_name));
							
							layerManager.close();
						},
		saveFavList	:	function()				
						{
							this.eListName.value = escape(this.eListName.value);
										
							var s,i,o={},h=$(settingUiManager.eListFrame).serialize().split("&");
							
							for(i in h) 
							{
								s = h[i].split("=");
								o[s[0]] = s[1];
							}
							
							document.getElementById("favID_"+settingUiManager.eListIndex.value).firstChild.firstChild.nodeValue
							= unescape(unescape(o["listName"]));
							s = {name:unescape(o["listName"]),list:[]};
							
							i = 0;
							while(o["id_"+i])
							{
								s.list.push({id:o["id_"+i],num:o["num_"+i]})
								i++;
							}
							
							
							cookieManager.cookieObj.favorite.lists[o["listIndex"]] = s;
							cookieManager.saveCookie();
							
							layerManager.close();
						},
		delFavList	:	function()
						{
							if(cookieManager.cookieObj.favorite.lists.length==1)
							{
								alert("This is last list. can't delete.");return;
							}
							
							if(confirm("Delete this list?"))
							{								
								
								cookieManager.cookieObj.favorite.lists
								= settingUiManager.ArrayOmit(parseInt(settingUiManager.eListIndex.value),cookieManager.cookieObj.favorite.lists);
								cookieManager.saveCookie();
								
								
								headerPanel.favList.removeChild(document.getElementById("favID_"+settingUiManager.eListIndex.value));
								
								var i,lis = headerPanel.favList.getElementsByTagName("li");
								for(i=0;i<lis.length;i++)
								{
									lis[i].id = "favID_" + i;
								}
								
								layerManager.close();
							}
						},
		init		:	function(_SB)
						{
							
							this.newList.action = "javascript:settingUiManager.saveNewList();";
							this.newList.className = "notClose";
							with(this.newList.style)
							{
								position = "absolute";
								top = "50px";
								left = "348px";
								width = "240px";
								height = "auto";
								fontSize = "80%";
								color = "#f00";
								backgroundImage = "url(./img/ichimatsu_fcc.gif)";
								backgroundColor = "#fff";
								border = "solid 1px #F88";
								/*display = "none";/★★あとでくる*/
								zIndex = 30;
							}
							/*LIST NAME*/
							var d = document.createElement("div");
							d.style.margin = "10px 0 0 10px";
							var i = document.createElement("input");
							i.name = "listName";
							i.type = "text";
							i.className = "notClose";
							with(i.style)
							{
								margin = padding = 0;
								width = "215px";
							}
							
							d.appendChild(document.createTextNode("LIST NAME"));
							d.appendChild(document.createElement("br"));
							d.appendChild(i);
							this.newList.appendChild(d);
							
							/*FIRST TUMBLER ID*/
							d = document.createElement("div");
							d.style.cssText = "float:left;margin:10px 0 0 10px;width:150px";
							i = document.createElement("input");
							i.name = "firstId";
							i.type = "text";
							i.className = "notClose";
							with(i.style)
							{
								margin = padding = 0;
								width = "150px";
							}
							
							d.appendChild(document.createTextNode("FIRST TUMBLER ID"));
							d.appendChild(document.createElement("br"));
							d.appendChild(i);
							this.newList.appendChild(d);
							
							
							d = document.createElement("div");
							d.style.cssText = "float:left;margin:10px 0 0 10px;";
							i = this.makePDnums(50);
							i.name = "imgNum";
							i.className = "notClose";
							
							d.appendChild(document.createTextNode("IMAGES"));
							d.appendChild(document.createElement("br"));
							d.appendChild(i);
							this.newList.appendChild(d);
							
							
							i = document.createElement("input");
							i.type = "submit";
							i.value = "OK";
							i.title = "OK";
							i.onmouseover = function(){this.style.color = '#ff0'};
							i.onmouseout = function(){this.style.color = '#fff'};
							i.className = "notClose";
							with(i.style)
							{
								width = "220px";
								margin = "20px 0 10px 10px";
								color = "#fff";
								backgroundColor = "#f00";						
							}
							this.newList.appendChild(i);
							
							
							this.eListFrame.action = "javascript:settingUiManager.saveFavList();";
							
							with(this.eListFrame.style)
							{
								position = "absolute";
								top = left = 0;
								width = "240px";
								height = "240px";
								backgroundColor = "#fff";
								
								border = "solid 1px #F88";
							}
							
							
							this.eListIndex.name = "listIndex";
							this.eListIndex.type = "hidden";
							this.eListFrame.appendChild(this.eListIndex);
							
							
							d = document.createElement("div");
							d.className = "notClose";
							with(d.style)
							{
								width = "240px";
								height = "40px";
								backgroundImage = "url(./img/ichimatsu_fcc.gif)";
							}
							
							i = this.eListName;
							i.type = "text";
							i.name = "listName";
							i.value = "";
							i.className = "notClose";
							with(i.style)
							{
								cssText = "float:left;";
								width = "170px";
								margin = "10px 0 0 5px";
								color = "#f00";
								fontWeight = "bolder";
								border = "dotted 1px #fff";
								backgroundColor = "#fdd";
							}
							d.appendChild(i);
							
							i = document.createElement("input");
							i.onclick = this.delFavList;
							i.onmouseover = function(){this.style.backgroundColor = '#ff0'};
							i.onmouseout = function(){this.style.backgroundColor = '#fff'};
							i.type = "button";
							i.value = "DEL";
							i.title="DELETE LIST";
							i.className = "notClose";
							with(i.style)
							{
								cssText = "float:right;";
								width = "40px";
								margin = "8px 10px 0 0";
								fontWeight = "bolder";
								color = "#f00";
								backgroundColor = "#fff";
							}
							d.appendChild(i);
							this.eListFrame.appendChild(d);
							
							
							with(this.eList.style)
							{
								width = "240px";
								height = "160px";
								overflow = "auto";
							}
							this.eListFrame.appendChild(this.eList);
							
							
							this.btnOkArea.className = "notClose";
							with(this.btnOkArea.style)
							{
								width = "240px";
								height = "40px";
								backgroundImage = "url(./img/ichimatsu_fcc.gif)";
							}
							i = document.createElement("input");
							i.type = "submit";
							i.value = "OK";
							i.title="OK";
							i.className = "notClose";
							i.onmouseover = function(){this.style.color = '#ff0'};
							i.onmouseout = function(){this.style.color = '#fff'};
							with(i.style)
							{
								width = "220px";
								margin = "10px 0 0 10px";
								fontWeight = "bolder";
								color = "#fff";
								backgroundColor = "#f00";							
							}
							this.btnOkArea.appendChild(i);
							this.eListFrame.appendChild(this.btnOkArea);
							
						}
	}
	settingUiManager.init(spriteBtns);
		
	
	var menuUiManager = 
	{
		btnID		:	["btn_favorite","btn_directory","btn_random","btn_about"],
		menu		:	document.getElementById("tmvMenu"),	
		searchBox	:	document.getElementById("searchBox"),
		settingArea	:	document.createElement("div"),
		List		:	document.createElement("ul"),
		searchTab	:	document.createElement("ul"),
		searchTabF	:	document.createElement("div"),
		searchBtn	:	document.createElement("a"),
		fukidasi	:	headerPanel.fukidasi,
		setView		:	function(_id)
						{
							var d = document.getElementById("btn_"+_id);
							
							
							if(d && d.className.indexOf("locked") != -1)return;
							
							for(var i=0;i<this.btnID.length;i++)
							{
								var b = document.getElementById(this.btnID[i]);
								if(b.className.indexOf("locked") != -1)
								{
									b.style.backgroundPosition = "-224px " + i*-36 + "px";
									b.className = "";
									break;
								}
							}
							
							if(d)
							{
								d.className = "locked";
								this.fukidasi.style.left = parseInt(d.style.left) + 37 + "px";
								
								
								var s = d.style.backgroundPosition.split(" ");
								d.style.backgroundPosition = "-324px " + s[1];
							}
							
							
							_id == "favorite" || _id == "directory"	?	this.fukidasi.style.display = "block"
																	:	this.fukidasi.style.display = "none";
						},
		select		:	function(_id)
						{
							location.hash = "p="+_id;
							_id =="random"	?	urlHashManager.refreshPage()	:	null;
						},
		tabIndex	:	0,
		sTabIndex	:	function(_n,_nonToggle)		
						{
							this.tabIndex = _n;
							var cn = menuUiManager.searchTab.childNodes;
							for(var i=0;i<cn.length;i++)
							{
								cn[i].style.backgroundColor = "#fff";
								cn[i].firstChild.style.color = "#f00";
							}
							
							cn[_n].style.backgroundColor = "#f00";
							cn[_n].firstChild.style.color = "#fff";
							
							this.submit = this.submitFncs[_n];
							
							this.searchBox.value = this.sTabNames[_n];
							this.searchBox.style.color = "#900";
							
							!_nonToggle	?	this.toggleTab()	:	null;
						},
		sTabNames	:	["TUMBLR ID","FILTER TAG","FILTER WORD"],
		submitFncs	:	[
							function()
							{
								location.hash = "id="+document.getElementById("searchBox").value;
							},
							function(){scrollManager.allowScroll(true);TumblrApiManager.filterList(document.getElementById("searchBox").value,"");},
							function(){scrollManager.allowScroll(true);TumblrApiManager.filterList("",document.getElementById("searchBox").value);}
						],
		submit		:	function(){},
		toggleTab	:	function()
						{
							var s = this.searchTabF.style;
							s.display = s.display == "none"	?	"block"	:	"none";
						},
		setNameTab	:	function(_id)
						{
							this.sTabIndex(0,true);
							location.hash = "id="+_id;
						},
		setSmallTab	:	function(_id)
						{
							
							var cStyle = document.getElementById("tmvContent").style;
							var bl = document.getElementById("btnList");
							var bs = document.getElementById("btnSetting");
							var al = menuUiManager.List;
							var as = menuUiManager.settingArea;
							
							
							al.style.display = as.style.display = "none";
							cStyle.marginTop = "0px";
							
							if(_id == "btnList")
							{
								if(bl.className.indexOf("locked")==-1)
								{
									cStyle.marginTop = "240px";
									bl.className += " locked";
									al.style.display = "block";
									
									if(bs.className)
									{
										bs.style.backgroundPosition = "-128px -168px";
										bs.className = "";
									}
								}
								else
								{
									bl.className = bl.className.replace("locked","");
								}
								
							}
							else
							{
								if(bs.className.indexOf("locked")==-1)
								{
									
									cookieManager.cookieObj.setting.imageSize == 250	
									?	document.getElementById("sis1").checked = true
									:	document.getElementById("sis0").checked = true;
									
									var i,c = document.getElementById("sdi").childNodes;
									for(i=0;i<c.length;i++)
									{
										cookieManager.cookieObj.setting.imageNum == parseInt(c[i].value)
										?	c[i].selected = true
										:	null;
									}					
									
									cStyle.marginTop = "80px";
									bs.className += "locked";
									as.style.display = "block";
																	
									if(bl.className)
									{
										bl.style.backgroundPosition = "-80px -168px";
										bl.className = "";
									}
								}
								else
								{
									bs.className = bs.className.replace("locked","");
								}					
							}
						},
		refresh		:	function()
						{
							this.searchBox.value = menuUiManager.sTabNames[menuUiManager.tabIndex];
							menuUiManager.searchBox.style.color = "#900";
						},			
		init		:	function(_SB)
						{
							this.menu.style.zIndex = 18;
							
							
							var btn = {};
							for(var i=0;i<this.btnID.length;i++ )
							{
								btn = document.getElementById(this.btnID[i]);
								with(btn.style)
								{
									top = "4px";
									left = 280 + i*99 + "px";
									width = "100px";
									height = "36px";
									backgroundImage = "url("+_SB.bgImg+")";
									backgroundPosition="-224px " + i*-36 + "px";
								}
								btn.href = "javascript:menuUiManager.select('"+btn.id.slice(4)+"');";
								_SB.hoverRoll(btn);
							}
							
							
							btn = document.getElementById("btnList");
							with(btn.style)
							{
								top = "15px";
								left = "246px";
								width = height = "24px";
								backgroundImage = "url("+_SB.bgImg+")";
								backgroundPosition="-80px -168px";
							}
							btn.title = "VIEW LIST";
							this.menu.appendChild(btn);
							
							_SB.hoverRoll(btn);
							btn.href = "javascript:menuUiManager.setSmallTab('"+btn.id+"')";
							
							
							with(this.List.style)
							{
								display = "none";
								position = "absolute";
								top = "240px";
								width = "100%";
								height = "240px";
								margin= padding = 0;
								listStyleType = "none";
								overflowY = "scroll";
								backgroundColor="#fff";
								borderBottom = "solid 1px #F00";
								zIndex = 18;
							}
							document.body.appendChild(this.List);
							
							
							btn = document.getElementById("btnSetting");
							with(btn.style)
							{
								top = "15px";
								left = "216px";
								width = height = "24px";
								backgroundImage = "url("+_SB.bgImg+")";
								backgroundPosition="-128px -168px";
							}
							btn.title="SETTING";
							this.menu.appendChild(btn);
							
							_SB.hoverRoll(btn);
							btn.href = "javascript:menuUiManager.setSmallTab('"+btn.id+"')";
							
							
							var l,j,i = new Image(),d = document.createElement("div");
							i.src="./img/title_setting.gif";
							with(i.style)
							{
								cssText = "float:left";
								width = "120px";
								height = "30px";
								margin = "25px 0 25px 10px";
							}
							this.settingArea.appendChild(i);
							
							
							with(d.style)
							{
								cssText = "float:left";
								height = "60px";
								width = "auto";
								margin = "10px";
								padding = "0 20px";
								color = "#f00";
								borderLeft = "solid 1px #F00";
							}
							
							this.settingArea.appendChild(d);
							j = document.createElement("div");
							j.style.margin = "4px 0";
							j.appendChild(document.createTextNode("IMAGE SIZE"))
							d.appendChild(j);
							
							i = document.createElement("input");
							j = document.createElement("input");
							j.type = i.type = "radio";
							j.name = i.name = "settingImageSize";
							i.id = "sis0";
							j.id = "sis1";
							i.value = 100;
							j.value = 250;
							
							i.onclick = j.onclick = function()
							{
								
								cookieManager.cookieObj.setting.imageSize = this.value;
								cookieManager.saveCookie();
								
								if(pageManager.nowPage == "id" && this.value == 250)
								{
									var lh = location.hash;
									lh = lh.replace(/&imageSize=250/g,"");
									lh+="&imageSize=250";
									location.hash = lh;
								}
							};
							
							
							l = document.createElement("label");
							l.appendChild(i);
							l.appendChild(document.createTextNode(i.value));
							d.appendChild(l);
							
							l = document.createElement("label");
							l.appendChild(j);
							l.appendChild(document.createTextNode(j.value));
							d.appendChild(l);

							
							d = document.createElement("div");
							with(d.style)
							{
								cssText = "float:left";
								height = "60px";
								width = "auto";//auto
								margin = "10px";
								padding = "0 20px";
								color = "#f00";
								borderLeft = "solid 1px #F00";
							}
							this.settingArea.appendChild(d);
							
							j = document.createElement("div");
							j.style.margin = "4px 0";
							j.appendChild(document.createTextNode("DEFAULT IMAGES"))
							d.appendChild(j);
							
							i = settingUiManager.makePDnums(0,"sdi");
							i.id = "sdi";
							i.onchange = function()
							{
								cookieManager.cookieObj.setting.imageNum = this.value;
								cookieManager.saveCookie();	
							};
							d.appendChild(i);
							
							
							d = document.createElement("div");
							with(d.style)
							{
								cssText = "float:left";
								height = "60px";
								width = "auto";//auto
								margin = "10px 0";
								padding = "0 0 0 20px";
								color = "#f00";
								borderLeft = "solid 1px #F00";
							}
							this.settingArea.appendChild(d);
							
							j = document.createElement("div");
							j.style.margin = "4px 0";
							j.appendChild(document.createTextNode("E-MAIL"))
							d.appendChild(j);
							
							i = document.createElement("input");
							i.id = "eMailInput";
							i.type = "text";
							i.style.width = "150px";
							i.value = cookieManager.cookieObj.setting.email;
							i.onblur = function()
							{
								cookieManager.cookieObj.setting.email = this.value;
								cookieManager.saveCookie();
							};
							d.appendChild(i);
							
							
							d = document.createElement("div");
							with(d.style)
							{
								cssText = "float:left";
								height = "60px";
								width = "auto";//auto
								margin = "10px 0";
								padding = "0 0 0 10px";
								color = "#f00";
							}
							this.settingArea.appendChild(d);
							
							j = document.createElement("div");
							j.style.margin = "4px 0";
							j.appendChild(document.createTextNode("PASSWORD"))
							d.appendChild(j);
							
							i = document.createElement("input");
							i.type = "password";
							i.style.width = "80px";
							i.value = cookieManager.cookieObj.setting.password;
							i.onblur = function()
							{
								cookieManager.cookieObj.setting.password = this.value;
								cookieManager.saveCookie();
							};
							d.appendChild(i);
							
							with(this.settingArea.style)
							{
								display = "none";
								position = "absolute";
								top = "240px";
								width = "100%";
								height = "80px";
								margin= padding = 0;
								overflowY = "auto";
								backgroundColor="#fff";
								borderBottom = "solid 1px #F00";
								fontSize = "90%"
								zIndex = 18;
							}
							document.body.appendChild(this.settingArea);
							
							
							with(this.searchBtn.style)
							{
								top = "15px";
								left = "6px";
								width = height = "20px";
								backgroundImage = "url("+_SB.bgImg+")";
								backgroundPosition="-176px -156px";
							}
							
							_SB.hoverRoll(this.searchBtn);
							
							this.searchBtn.title = "INPUT TYPE";
							this.searchBtn.href = "javascript:menuUiManager.toggleTab();";
							this.menu.appendChild(this.searchBtn);
							
							
							with(this.searchBox.style)
							{
								position = "absolute";
								top = "14px";
								left = "30px";
								height = "18px";
								width = "170px";
								margin = padding = 0;
								paddingLeft = "2px";
								border = "1px dashed #fff";
								color = "#ff0";
								backgroundColor = "#f00";
							}
							this.searchBox.onfocus = function()
							{
								this.style.color = "#ff0";
								this.style.border = "1px solid #ff0";
								
								this.value = this.value == menuUiManager.sTabNames[menuUiManager.tabIndex]	?	""	:	this.value;
							}
							this.searchBox.onblur = function()
							{
								this.style.color = "#ff0";
								this.style.border = "1px dashed #fff";
								
								if(this.value == "")
								{
									this.value = menuUiManager.sTabNames[menuUiManager.tabIndex];
									menuUiManager.searchBox.style.color = "#900";
								}
							}
														
							
							with(this.searchTab.style)
							{
								position = "absolute";
								width = height = "auto";
								margin = "10px";
								padding = "5px";
								border = "solid 1px #f00";
								backgroundColor = "#fff";
								zIndex = 18;
							}
							
							
							i = new Image();
							i.src = "./img/searchFukiDasi.gif";
							with(i.style)
							{
								position = "absolute";
								zIndex = 19;
								margin = "3px 0 0 15px";
							}
							this.searchTabF.appendChild(i);
							this.searchTabF.appendChild(this.searchTab);
							document.body.appendChild(this.searchTabF);
							
							var a,t;
							for(i=0;i<this.sTabNames.length;i++)
							{
								l = document.createElement("li");
								a = document.createElement("a");
								t = document.createTextNode(this.sTabNames[i]);
								
								with(l.style)
								{
									width = "auto";
									height = "20px";
									lineHeight = "20px";
									overflow = "hidden";
									backgroundColor = "#f00";
								}
								
								a.href = "javascript:menuUiManager.sTabIndex("+ i +")";
								a.style.fontSize = "80%";
								a.style.padding = "0 5px";
								
								a.appendChild(t);
								l.appendChild(a);
								this.searchTab.appendChild(l);
							}
							this.sTabIndex(0);
						}
	}
	menuUiManager.init(spriteBtns);
	
	var TumblrApiManager = 
	{
		limit		:	12,
		loadFlg		:	true,
		errorCount	:	15,
		ObjList		:	[],
		ListPoint	:	0,
		List		:	menuUiManager.List,
		addHtmlList	:	function(_id,_num)
						{
							var l = document.createElement("li");
							var a = document.createElement("a");
							var t = document.createTextNode(_id);
							
							l.style.cssText = "width:10%;height:30px;line-height:30px;float:left;overflow:hidden";
							l.className="c0";
							
							a.setAttribute("onclick", "javascript:menuUiManager.setNameTab('"+_id+"');return false;");
							a.href = "./#id="+_id;
							a.className = "num_" + _num;
							a.style.fontSize = "80%";
							a.style.paddingLeft = "2px";
							a.style.color = "#00f";
							
							a.appendChild(t);
							l.appendChild(a);
							this.List.appendChild(l);
						},
		attackLimit	:	12,
		attackCount	:	0,
		attackCheck	:	function()
						{
							if(this.attackCount > this.attackLimit)
							{
								scrollManager.allowScroll(false);
								this.limit = this.attackCount = 0;
							}
							else
							{
								this.attackCount++;
							}
						},
		watchers	:	{},
		uniqueId	:	0,
		makeWatcher	:	function(_tag,_search)
						{
							
							this.uniqueId = +new Date();
							this.watchers["no_"+this.uniqueId] = new apiLoadWatcher("no_"+this.uniqueId,_tag,_search);
						},
		dumyCallBack:	{callBack:new Function()},					
		delWatcher	:	function()
						{
							if(!this.watchers["no_"+this.uniqueId])return;
							
							clearTimeout(this.watchers["no_"+this.uniqueId].checkLoopId);
							delete this.watchers["no_"+this.uniqueId];
							this.watchers["no_"+this.uniqueId] = this.dumyCallBack;
						},
		filterList	:	function(_tag,_search)
						{
							this.ObjList = null;
							this.ObjList = [];
							this.ListPoint = 0;
							this.limit = this.attackLimit = 12;
													
							this.delWatcher();
							this.makeWatcher(_tag,_search);
							
							
							contentMosaic.imgCount = 0;
							document.getElementById("tmvContent").innerHTML = "";
							
							TumblrImgLoadManager.refresh();
							TumblrImgPutManager.refresh();
							selectImageManager.refresh();
						},
		refresh		:	function()					
						{
							this.ObjList = null;
							this.ObjList = [];
							this.ListPoint = 0;
							this.limit = this.attackLimit = 12;
							
							this.delWatcher();
							this.makeWatcher();
						}
	}
	
	function apiLoadWatcher(_fncHash, _tag, _search)
	{
		this.name;
		this.totalNum = 0;
		this.hash = _fncHash;
		
		
		this.start;
		this.num;
		this.callback = "TumblrApiManager.watchers."+_fncHash+".callBack";
		this.tagged = _tag	?	_tag	:	"";
		this.search = _search	?	_search	:	"";
		
		this.checkLoopFlg;
		this.checkLoopCount;
		this.checkLoopId;
		
		this.init();
		this.checkLoop();
	}
	
	apiLoadWatcher.prototype.init = function()
	{
		apiLoadWatcher.prototype.aList = menuUiManager.List.getElementsByTagName("a");
		
		this.start = 0;
		this.num = 0;
		this.checkLoopFlg = true;
		this.checkLoopCount = 10;
		
		
		if(!this.aList.length)return;
			
		this.name = this.aList[TumblrApiManager.ListPoint].firstChild.nodeValue;
		this.totalNum = this.aList[TumblrApiManager.ListPoint].className.match(/num_[0-9]*/).toString();
		this.totalNum = parseInt(this.totalNum.replace(/num_/,""));
		
		this.tagged = this.tagged;
		this.search = this.search;
		
		TumblrApiManager.ListPoint++;
	};
	
	apiLoadWatcher.prototype.loadCheck = function()
	{
		this.checkLoopCount--;
		
		if(this.checkLoopCount<0)
		{
			this.checkLoopFlg = true;
			this.checkLoopCount = 10;
		}
	};
	
	apiLoadWatcher.prototype.checkLoop = function()
	{
		if(	TumblrApiManager.ObjList.length < TumblrApiManager.limit
			&& this.checkLoopFlg)
		{
			var gap = this.totalNum - this.start;
						
			if (gap > 0)
			{
				var query=
				{
					start	:	this.start,
					num		:	gap < 50	?	gap	:	50,
					type	:	"photo",
					callback:	this.callback,
					tagged	:	this.tagged,
					search	:	this.search
				};
				
				GetReadApi(this.name,query);
				
				this.start += 50;
				this.checkLoopFlg = false;
			}
			else if(this.aList.length > TumblrApiManager.ListPoint && pageManager.nowPage != "id")
			{
				this.init();
			}
		}
		
		!this.checkLoopFlg	?	this.loadCheck()	:	this.checkLoopCount = 5;
		
		this.checkLoopId = arguments.callee.applyTimeout(600,this);
	};
	
	apiLoadWatcher.prototype.callBack = function(o)
	{
		if (o.posts.length) 
		{
			TumblrApiManager.ObjList.push(o);
			TumblrApiManager.attackCount = 0;
			
			for (var i = 0, l = o.posts.length; i < l; i++) 
			{
				this.getTumblrId(o.posts[i]["photo-caption"]);
			}
			o["posts-total"] < this.totalNum ? this.totalNum = o["posts-total"]	:	null;
		}
		else
		{
			TumblrApiManager.attackCheck();
			this.start = this.totalNum;
		}
		
		this.checkLoopFlg = true;
	};
	
	apiLoadWatcher.prototype.getTumblrId = function(a)
	{
		if(!a)return;
		
		var arr = a.match(/http:\/\/[\w|-]+\.tumblr\.com/g);
		if(!arr)return;
		
		arr = arr.toString();
		arr = arr.replace(/http:\/\//g,"");
		arr = arr.replace(/.tumblr\.com/g,"");
		arr = arr.replace(/media|data|www/g,"");
		arr = arr.split(",");
		
		var tmp =[];
		for(var i=0,l=arr.length; i<l; i++)
		{
			var f = true;
			for(var j=0,m=this.aList.length; j<m; j++)
			{
				if(arr[i] == this.aList[j].firstChild.nodeValue)
				{
					
					var cn = parseInt(this.aList[j].parentNode.className.slice(1));
					this.aList[j].parentNode.className = cn < 29	?	"c"+(cn+1).toString()
																	:	"c29";
					f = false;
					break;
				}				
			}
			
			f && arr[i]	?	tmp.push(arr[i])	:	null;
		};
		
		if(tmp.length)
		{
			for(var i=0,l=tmp.length;i<l;i++)
			{
				TumblrApiManager.addHtmlList(tmp[i],cookieManager.cookieObj.setting.imageNum);
			};
		};
		
	};
	
	var TumblrImgLoadManager =
	{
		limit		:	50,
		imgCount	:	0,
		imgSize		:	parseInt(cookieManager.cookieObj.setting.imageSize),
		loadFlg		:	true,
		TUMOList	:	TumblrApiManager.ObjList,
		checkLoop	:	function()
						{
							if(this.imgCount < this.limit
								&&	this.TUMOList.length
								&&	this.loadFlg)
							{
								this.loadFlg = false;
								for(var i=0,l=this.TUMOList[0].posts.length;i<l;i++)
								{
									this.imgCount++;
									
										var tmp = new Image();
										
										
										/*tmp.applyObj = 
										{
											bigImage: "",
											sourceLink: "",
											permaLink: "",
											siteName: "this tumblr"
										};*/
										
										tmp.applyObj = imgProtoApplyObj;
										tmp.imgProtoCheckLoadImg = imgProtoCheckLoadImg;
										//tmp.filterTitle = filterTitle;
										tmp.imgProtoLoadAndPush = imgProtoLoadAndPush;
										
										tmp.imgProtoLoadAndPush(this.TUMOList[0].posts[i], 
															this.TUMOList[0].tumblelog.title,
															this.imgSize,
															TumblrApiManager.uniqueId
															);
															
															
								}
								this.TUMOList.shift();
								this.loadFlg = true;
							}
						},
		refresh		:	function()
						{
							this.imgCount = 0;
							this.loadFlg = true;
							
							this.TUMOList =	TumblrApiManager.ObjList;
						}
	};

	var TumblrImgPutManager = 
	{
		loadedList	:	[],
		remainFlg	:	true,
		ajaxLoader	:	document.createElement("div"),
		checkLoop	:	function()
						{
							if(this.loadedList.length && this.remainFlg)
							{
									TumblrImgLoadManager.imgCount--;
									contentMosaic.putImage(this.loadedList.shift());
							}
						},
		checkAjaxImg:	function()
						{
							if(!document.getElementById("tmvContent").getElementsByTagName("img").length)
							{
								setTimeout(arguments.callee,480);
							}
							else
							{
								TumblrImgPutManager.ajaxLoader.style.display = "none";
							}
						},
		resize		:	function()
						{
							var rn = contentMosaic.getReturnNum();
							if(contentMosaic.returnNum == rn || rn < 2 || contentMosaic.imgCount > 2560)return;
							
							remainFlg = false;
							
							selectImageManager.beforeWash(selectImageManager.selectImg);
							contentMosaic.init();
							var tmp = document.getElementById("tmvContent").getElementsByTagName("img");
							for(var i=0,l=tmp.length; i<l; i++)
							{
								contentMosaic.putImageLoaded(tmp[i]);
							}
							remainFlg = true;
						},
		refresh		:	function()
						{
							this.loadedList = null;
							this.loadedList =[];
							
							this.remainFlg = true;
							contentMosaic.init();
							
							
							if (pageManager.nowPage == "directory" || pageManager.nowPage == "about") 
							{
								this.ajaxLoader.style.display = "none";
								return;
							}
							
							this.ajaxLoader.style.display = "block";
							this.checkAjaxImg();
						},
		init		:	function()
						{
							with(this.ajaxLoader.style)
							{
								top = "350px";
								width = height = "100px";
								margin ="1px";
								backgroundImage = "url(./img/ajax-loader.gif)";
								backgroundRepeat ="no-repeat";
							}
							document.body.appendChild(this.ajaxLoader);
							
							this.checkAjaxImg();
						}
	}
	TumblrImgPutManager.init();
	
	var mosaicView = function(_targetId,_idFrontText,_size)
	{
		this.imgBlank = 1;
		this.imgWidth = _size;
		
		this.imgPoints;
		this.putPoint;
		this.returnNum = 0;
		
		this.IdText = _idFrontText;
		this.imgCount = 0;
		
		this.targetElem	= document.getElementById(_targetId);
		this.targetId	= _targetId;
		
		this.init();
	}
	
	mosaicView.prototype.init = function()
	{
		this.imgPoints	=	[];
		this.putPoint	=	0;
		
		this.returnNum = this.getReturnNum();
		
		for(var i=0;i<this.returnNum;i++)
		{
			this.imgPoints[i] = new point((this.imgWidth+this.imgBlank)*i+this.imgBlank,0);
		}
		function point(_x,_y){this.x=_x; this.y=_y;};
	}
	
	mosaicView.prototype.getReturnNum = function()
	{
		var a = $(this.targetElem).innerWidth()-this.imgBlank;
		var b = this.imgBlank+this.imgWidth;
		var c = a%b > this.imgWidth*0.8	?	1	:	0;
		
		return Math.floor(a/b)+c;
	}
	
	mosaicView.prototype.putImage = function(_img)
	{
		if(pageManager.nowPage == "about")return;
		
		this.putPoint = this.getMinPoint();
		
		_img.id = this.IdText + this.imgCount;
		_img.style.position = "absolute";
		_img.style.left = this.imgPoints[this.putPoint].x+ "px";
		_img.style.top = this.imgPoints[this.putPoint].y+ "px";
		_img.style.width = this.imgWidth + "px";
		_img.style.height = _img.height + "px";
		
		titleManager.titleAttach(this.imgCount++);
		
		$(_img).hide();
		this.targetElem.appendChild(_img);		
		$(_img).fadeIn("slow");
		
		this.imgPoints[this.putPoint].y += _img.height + this.imgBlank;
		
		layerManager.resize();
	}

	mosaicView.prototype.putImageLoaded = function(_img)
	{
		_img.style.left = this.imgPoints[this.putPoint].x + "px";
		_img.style.top = this.imgPoints[this.putPoint].y + "px";
		
		this.imgPoints[this.putPoint].y += _img.height + this.imgBlank;
		this.putPoint > this.imgPoints.length-2	?	this.putPoint = 0	:	this.putPoint++;
	}
	
	mosaicView.prototype.getMinPoint = function()
	{
		var tmp = this.imgPoints.slice(0);
		tmp.sort(function(a,b){return a.y - b.y;});
		
		for(var i=0,l=this.imgPoints.length;i<l;i++)
		{
			if(tmp[0].x == this.imgPoints[i].x){return i;}
		}
	}
	
	var contentMosaic = new mosaicView("tmvContent","imgID_",parseInt(cookieManager.cookieObj.setting.imageSize));
	
	function GetReadApi(_name,_query)
	{
		var script = document.createElement( 'script' );
	    script.charset = 'utf-8';
	    script.type	=	'text/javascript';
	    script.src	=	domainFormat(_name) + decQuery(_query);
	   
	    document.lastChild.appendChild( script );

		function domainFormat(_name)
		{
			var r = _name;
			if(_name.indexOf(".")!=-1)
			{
				r = "/" != r.slice(r.length-1)	?	r + "/"	:	r;
				r = r.indexOf("http")==-1	?	"http://"+r	:	r;			
			}
			else
			{
				r = "http://"+ r +".tumblr.com/";
			}
			return r;
		}
		
		function decQuery(_query)
		{
			var r ="api/read/json?";
			var amp = ""
			for(var i in _query)
			{
				r+=amp + i +"="+ _query[i];
				amp = '&';
			}
			
			return r;
		}
	}
	
	
	var selectImageManager = 
	{
		selectImg	:	{},
		selectBtns	:	document.createElement("div"),
		btnReblog	:	document.createElement("a"),
		btnLike		:	document.createElement("a"),
		btnSource	:	document.createElement("a"),
		linkElem	:	document.createElement("a"),
		frameW		:	6,
		beforeWash	:	function (_bImg)
						{
							if(_bImg.style)
							{
								with(_bImg.style)
								{
									top = parseInt(top) + this.frameW + "px";
									left = parseInt(left) + this.frameW + "px";
									zIndex = 5;
									border="none";
									padding = 0;
									backgroundImage = "url(null)";
								}
							}
							
							this.linkElem.firstChild	?	contentMosaic.targetElem.appendChild(this.linkElem.firstChild)	:	null;
						},
		surroundLink:	function(_tImg)
						{
							
							if (this.linkElem.firstChild)this.beforeWash(this.linkElem.firstChild);
							
							_tImg.style.top = parseInt(_tImg.style.top) - this.frameW + "px";
							_tImg.style.left = parseInt(_tImg.style.left) - this.frameW + "px";
							_tImg.style.zIndex = 6;
							_tImg.style.padding = this.frameW-1+"px";
							_tImg.style.border = "solid 1px #F00";
							_tImg.style.borderBottom = "none";
							_tImg.style.backgroundImage = "url(./img/ichimatsu_f00.gif)";
							
							this.linkElem.appendChild(_tImg);
							this.linkElem.href = _tImg.applyObj.bigImage;
						},				
		imgFocus	:	function(_targetImg)
						{
							if(this.selectImg == _targetImg)return;
							
							this.selectImg = _targetImg;
							this.surroundLink(_targetImg);
							
							
							var ts =_targetImg.style;
							
							this.btnReblog.setAttribute("onclick", "javascript:selectImageManager.reblogThis('"+_targetImg.applyObj.reblogLink+"');return false;");
							this.btnReblog.href = _targetImg.applyObj.reblogLink;
							this.btnLike.href = "javascript:selectImageManager.likeThis('"+_targetImg.applyObj.likeData+"')";
							this.btnSource.href = _targetImg.applyObj.sourceLink;
							
							
							this.selectBtns.style.top = parseInt(ts.top)+ _targetImg.height+(this.frameW*2-1)+ "px";
							this.selectBtns.style.left = parseInt(ts.left) + "px" ;
							this.selectBtns.style.display = "block";
						},
		reblogThis	:	function(_url)
						{
							var h = safeDocument.clientHeight > 980	?	980	:	490;
							
							window.open(_url+"?redirect_to=http%3A%2F%2Ftmv.proto.jp%2FreblogClose.html","_blank","width=980,height="+h
							+",scrollbars=1,locationbar=0,menubar=0,resizable=1,status=1,toolbar=0,directories=0");
						},
		likeThis	:	function(_data)
						{
							
							if(_data != this.selectImg.applyObj.likeData || document.getElementById(this.selectImg.id + "_"))return;
							
							if(!cookieManager.cookieObj.setting.email || !cookieManager.cookieObj.setting.password)
							{
								if(window.confirm("Invalid function! Please input your Tumblr email and password."))
								{
									var bs = document.getElementById("btnSetting");
									
									if(bs.className.indexOf("locked")==-1)
									{
										bs.className += " over";
										bs.style.backgroundPosition = "-152px -168px";
										menuUiManager.setSmallTab("btnSetting");
									}
									
									if(layerManager.enable)layerManager.close();
									document.getElementById("eMailInput").focus();
									$(window).scrollTop(0);
								}
								return;
							}
							
							$(this.selectImg).css("opacity",0.6);
							document.getElementById("tmvContent").appendChild
							(
								this.likeLoadIcon(this.selectImg.id+"_LoadIcon",parseInt(this.selectImg.style.top)+this.frameW*1.5+"px", parseInt(this.selectImg.style.left)+this.frameW*1.5+"px")
							);
							
							
							var iF = document.createElement("iframe");
							iF.id = this.selectImg.id + "_";
							iF.src = "http://www.tumblr.com/api/like?" + _data + "&email=" + cookieManager.cookieObj.setting.email + "&password=" + cookieManager.cookieObj.setting.password;
							iF.style.display = "none";
							iF.width = iF.height = 0;
							$(iF).load(function()
							{
								$("#"+this.id.slice(0,-1)).css("opacity",1);
								var LI = document.getElementById(this.id+"LoadIcon");
								LI	?	LI.parentNode.removeChild(LI)	:	null;
								
								browserType == "Firefox"	
								?	(function(){this.parentNode.removeChild(this)}).applyTimeout(100,this)
								:	this.parentNode.removeChild(this);
							});
							
							document.body.appendChild(iF);
						},			
		send		:	function()
						{
							zoomImgManager.popup(this.selectImg);
						},
		likeLoadIcon:	function(_id,_top,_left)
						{
							var l = document.createElement("div");
							l.id = _id;
							with(l.style)
							{
								position = "absolute";
								top = _top;
								left = _left;
								width = height = 24 + "px";
								margin = padding = 0;
								backgroundImage = "url(./img/ajax-loader_l.gif)";
								zIndex = 0;
							}
							
							return l;
						},					
		init		:	function(_SB)
						{							
							
							with(this.selectBtns.style)
							{
								position = "absolute";
								width = 98 + this.frameW*2 + "px";
								height = 24 + this.frameW + "px";
								margin = padding = 0;
								backgroundImage = "url(./img/ichimatsu_f00.gif)";
								//backgroundColor = "#fff";
								border = "solid 1px #F00";
								borderTop = "none";
								zIndex = 9;
								display = "none";
							}
							
							with(this.btnReblog.style)
							{
								position = "absolute";
								display = "block";
								top = 0;
								left = 46 + this.frameW*2 - 1 + "px";
								width = "48px";
								height = "24px";
								backgroundImage = "url("+_SB.bgImg+")";
								backgroundPosition = "-80px -144px";
							}
							this.btnReblog.title = "REBLOG THIS";
							this.selectBtns.appendChild(this.btnReblog);
							_SB.hoverRoll(this.btnReblog);
							
							with(this.btnLike.style)
							{
								position = "absolute";
								display = "block";
								top = 0;
								left =23 + 3 + this.frameW - 1 + "px";
								width = "23px";
								height = "24px";
								backgroundImage = "url("+_SB.bgImg+")";
								backgroundPosition = "-176px -48px";
							}
							this.btnLike.title = "LIKE THIS";
							//this.btnLike.target = "_blank";
							this.btnLike.href = "javascript:void(0);"
							this.selectBtns.appendChild(this.btnLike);
							_SB.hoverRoll(this.btnLike);
							
							with(this.btnSource.style)
							{
								position = "absolute";
								display = "block";
								top = 0;
								left = this.frameW - 1 + "px";
								width = "23px";
								height = "24px";
								backgroundImage = "url("+_SB.bgImg+")";
								backgroundPosition = "-176px -72px";
								zIndex = 9;
							}
							this.btnSource.target = "_blank";
							this.btnSource.title = "JUMP TO SOURCE";
							this.selectBtns.appendChild(this.btnSource);
							_SB.hoverRoll(this.btnSource);
							contentMosaic.targetElem.appendChild(this.selectBtns);
							
							
							this.linkElem.setAttribute("onclick", "selectImageManager.send();return false;");
							contentMosaic.targetElem.appendChild(this.linkElem);
							
							if(browserType == "Opera")
							{
								document.getElementById("tmvMenu").style.marginTop = "-16px";
								this.selectBtns.style.marginTop = "-10px";
							}
						},
		refresh		:	function()
						{
							if (this.linkElem.firstChild)this.linkElem.removeChild(this.linkElem.firstChild);
							if(!this.selectBtns.innerHTML)
							{
								this.selectBtns.appendChild(this.btnReblog);
								this.selectBtns.appendChild(this.btnLike);
								this.selectBtns.appendChild(this.btnSource);
							}
							
							contentMosaic.targetElem.appendChild(this.selectBtns);
							contentMosaic.targetElem.appendChild(this.linkElem);
							this.selectBtns.style.left = "-999px";
						}								
	}
	selectImageManager.init(spriteBtns);
	
	
	$(window).resize(function()
	{
		headerPanel.resize();
		layerManager.resize();
		if(layerManager.enable)return;
		TumblrImgPutManager.resize();
	});
	
	$("#tmvContent").mouseover(function(e)
	{
		
		e.target.tagName == "IMG"	?	selectImageManager.imgFocus(e.target)	:	null;
	});
	
	
	var randomManager = 
	{
		ids			:	[],
		idLength	:	250,
		loadNum		:	5,
		jsonPath	:	["./json/TOP500_US.js","./json/TOP500_JP.js","./json/TOP500_PH.js","./json/TOP500_GB.js","./json/TOP500_AU.js"],
		arrayShuffle:	function(_targetArr, _shuffleNum)
						{
							var i,c,r0,r1,r=_targetArr,l=_targetArr.length;
							
							for(i=0;i<_shuffleNum;i++)
							{
								r0 = parseInt(Math.random()*(l-1));
								r1 = parseInt(Math.random()*(l-1));
								
								c = r[r0];
								r[r0] = r[r1];
								r[r1] = c;
							}
							
							return r;
						},
		pushIds		:	function(_idArr)
						{
							this.arrayShuffle(_idArr,500);
							var i,l=this.idLength/this.loadNum;
							for(i=0;i<l;i++)
							{
								this.ids.push(_idArr[i]);
							}
							
							_idArr = null;
						},
		getRandomIds:	function(_num)
						{
							var i,r=[],num = _num	|| 10;
							
							for(i=0;i<num;i++)
							{
								r.push(this.ids[parseInt(Math.random()*(this.ids.length-1))]);
							}
							
							return r;
						},
		init		:	function()
		{
			for(var i=0;i<this.jsonPath.length;i++)
			{
				
				$.getJSON(this.jsonPath[i], function(json)
				{
					randomManager.pushIds(json);
					json = null;
				});
			}
		}
	}
	randomManager.init();
	
	var scrollManager =	
	{
		scroll		:	true,
		scrollValue	:	browserType =="Safari"	?	1200	:	600,
		endOfScroll	:	document.createElement("div"),
		allowScroll	:	function(_bool)
						{
							this.scroll = _bool;
							this.endOfScroll.style.display = "none";
							
							if(!_bool)
							{
								with(this.endOfScroll.style)
								{
									display = "block";
									top = safeDocument.scrollHeight + 80 + "px";
								}
							}
						},
		init		:	function()
						{
							(function()
							{
								TumblrImgPutManager.remainFlg 
								=	safeDocument.scrollHeight - safeDocument.clientHeight - safeDocument.scrollTop < scrollManager.scrollValue && scrollManager.scroll
								?	true	:	false;
								setTimeout(arguments.callee,500);
							})();
							
							with(this.endOfScroll.style)
							{
								position = "absolute";
								width = "100%";
								height =  "80px";
								backgroundImage = "url(./img/stripe64.gif)";
								display = "none";
							}
							
							var d = document.createElement("div");
							with(d.style)
							{
								position = "absolute";
								top = "64px";
								width = "100%";
								height =  "16px";
								backgroundImage = "url(./img/endofscroll.gif)";
							}
							
							this.endOfScroll.appendChild(d);
							document.body.appendChild(this.endOfScroll);
						}
	}
	scrollManager.init();
	
	
	var pageManager = 
	{
		nowPage		:	"",
		select		:	function(_pageName,_option)
						{
							this.nowPage = _pageName;
							
							
							TumblrApiManager.delWatcher();
							TumblrApiManager.List.innerHTML = "";
							document.getElementById("tmvContent").innerHTML = "";
							contentMosaic.imgCount = 0;
							scrollManager.allowScroll(true);
							menuUiManager.refresh();
							headerPanel.refresh();
							
							
							TumblrImgLoadManager.imgSize = 
							contentMosaic.imgWidth = parseInt(cookieManager.cookieObj.setting.imageSize);
							
							_option.imageSize == 	"250"	?	TumblrImgLoadManager.imgSize = contentMosaic.imgWidth = 250	:	null;
							
							switch (this.nowPage)
							{
								case	"directory"	:
								
										TumblrApiManager.refresh();
										TumblrImgLoadManager.refresh();
										TumblrImgPutManager.refresh();
										selectImageManager.refresh();
										
										document.getElementById("tmvContent").innerHTML = "Under Construction";
										
										break;
										
								case	"random"	:
								
										(function()
										{
											if (randomManager.ids.length)
											{
												var i, ids = randomManager.getRandomIds();
												
												for (i = 0; i < ids.length; i++) 
												{
													TumblrApiManager.addHtmlList(ids[i], 50);
												}
												
												TumblrApiManager.refresh();
												TumblrImgLoadManager.refresh();
												TumblrImgPutManager.refresh();
												selectImageManager.refresh();
											}
											else
											{
												setTimeout(arguments.callee,500);
											}											
										})();							
								
										break;

								case	"about"		:
										
										TumblrApiManager.refresh();
										TumblrImgLoadManager.refresh();
										TumblrImgPutManager.refresh();
										selectImageManager.refresh();
										
										document.getElementById("tmvContent").innerHTML 
										='<div style="margin:20px 30px">'
										+'Contact'
										+"<a title=\"proto.jp_Gmail\" style=\"background-image:url(./img/gmail.gif);width:145px;height:21px;display:block;\" onclick=\"window.open('http://mailhide.recaptcha.net/d?k=01Zy3vyE5SnRB0hcpP1O28Sg==&amp;c=fbza9AsKQEQbIFch04WKNga9qy6S2SO7frImKtxheko=', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" href=\"http://mailhide.recaptcha.net/d?k=01Zy3vyE5SnRB0hcpP1O28Sg==&amp;c=fbza9AsKQEQbIFch04WKNga9qy6S2SO7frImKtxheko=\">"
										+'</a>'
										+'<div>';
										
										break;
										
								case	"id"		:
										
										TumblrApiManager.addHtmlList(_option.target,9999999);
										
										TumblrApiManager.refresh();
										TumblrImgLoadManager.refresh();
										TumblrImgPutManager.refresh();
										selectImageManager.refresh();
										
										with(menuUiManager.searchBox)
										{
											value = _option.target;
											style.color = "#ff0";
										}
										
										break;
										
								default				:		//favorite
										
										
										cookieManager.setFavLists();
										
										TumblrApiManager.refresh();
										TumblrImgLoadManager.refresh();
										TumblrImgPutManager.refresh();
										selectImageManager.refresh();
										
										this.nowPage = "favorite";
										break;
							}
							menuUiManager.setView(this.nowPage);
							selectImageManager.selectBtns.style.display = "none";
							titleManager.refresh();
						}
	};
	
	var urlHashManager = 
	{
		getHashObj	:	function()
						{
							var r = {};
							if (location.hash) 
							{
								var s,i,o={},h=location.hash.slice(1).split("&");
								for(i in h) 
								{
									s = h[i].split("=");
									o[s[0]] = s[1];
								}
								r =o;
							}
							return r;
						},
		refreshPage	:	function()
						{
						
							var page,option={},hashObj = this.getHashObj();
							
							
							if(hashObj["id"])
							{
								page = "id";
								option.target = hashObj["id"];
							}
							else if(hashObj["p"])
							{
								page = hashObj["p"];
							}
							
							
							/*option.search = hashObj["search"];★★未対応*/
							option.imageSize = hashObj["imageSize"];
							
							pageManager.select(page,option);
						},
		beforeHash	:	location.hash,				
		hashWatcher	:	function()
						{
							this.beforeHash != location.hash	?	this.refreshPage()	:	null;
							this.beforeHash = location.hash;
							
							arguments.callee.applyTimeout(250,this);
						}
	}
	urlHashManager.hashWatcher();
	
	var titleManager = 
	{
		loopId		:	0,
		checkLoop	:	function()
						{
							!TumblrImgPutManager.remainFlg	?	document.title = "TUMBLR MOSAIC VIEWER - 10,000 images in 1 page!"
															:	null;							
							
							pageManager.nowPage == "id"	?	document.title = "TUMBLR MOSAIC VIEWER - "+ menuUiManager.List.getElementsByTagName("a")[0].firstChild.nodeValue
														:	contentMosaic.imgCount<9999	?	this.loopId = setTimeout(arguments.callee,1000)	
																						:	null;														
						},
		titleAttach	:	function(_count)
						{
							
							pageManager.nowPage != "id"	?	document.title = "TUMBLR MOSAIC VIEWER - now "+ _count +" images in 1 page!"
														:	null;
						},
		refresh		:	function()
						{
							clearTimeout(titleManager.loopId);
							this.checkLoop();
						}
	}
	titleManager.checkLoop();
	
	var INIT = function()
	{
		
		urlHashManager.refreshPage();
		TumblrImgPutManager.checkLoop.applyInterval(50,TumblrImgPutManager);
		TumblrImgLoadManager.checkLoop.applyInterval(333,TumblrImgLoadManager);
	}();
	