function setYear(){
	var d_obj = new Date();
	document.write(d_obj.getFullYear());
}

function swf_object(SWF,WID,HEI){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width='+ WID +' height='+ HEI +'>');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="allowFullScreen" value="false" />');
	document.write('<param name="movie" value="'+ SWF +'.swf" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="bgcolor" value="#ffffff" />');
	document.write('<embed src="'+ SWF +'.swf" quality="high" wmode="transparent" bgcolor="#ffffff" width='+ WID +' height='+ HEI +' name="coverflow" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

function pickupMovie(lady_id){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="240" height="320">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="allowFullScreen" value="false" />');
	document.write('<param name="movie" value="../ladies/swf/pickupmovie.swf?path=../movie/'+ lady_id +'.flv" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="../ladies/swf/pickupmovie.swf?path=../movie/'+ lady_id +'.flv" quality="high" wmode="transparent" width="240" height="320" name="coverflow" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');

}

function init() {
	photoChange();
	smartRollover();
	border_none();
	setPng();
	setPng2();
	setPng3();
	setPng4();
	seedPosition();
	favorite('bookmark','http://www.u-shirousagi.com','PukuPuku白うさぎ');
	blackwindow();
	winClose();
	flashban();
	smartPhoneRedirect();
}
window.onload=init;

function photoChange(){

	if(!document.getElementById("image")){
		return;
	}
	
	
	var base = document.getElementById("image").getElementsByTagName("img")[0];
	base.style.display = "none";

	var imageList = new Array();
	for(i=1;i<=4;i++){
//		//imageList[i] = document.createElement("img");
		tmpImage = new Image();
		tmpImage.src = "pic0"+i+".jpg";
		imageList.push(tmpImage);
	}

	if(imageList[0].width > 300){
		base.style.marginBottom = "-50px";
		base.style.marginTop = "50px";
	}
	base.style.display = "";

	var sumArray = document.getElementsByTagName("img");
	for(i=0;i<sumArray.length;i++){

		if(sumArray[i].className == "thumb"){

			sumArray[i].onmouseover = function(){

				var targetImg = document.getElementById("image").getElementsByTagName("img")[0];

				var tmpSrc = this.src.split("thumb0");
				var tmpNumber = tmpSrc[1].split(".");
				var srcNumber = tmpNumber[0]-1;
				//var targetSrc = "pic"+tmpSrc[1];

				targetImg.src = imageList[srcNumber].src;
				
				if(imageList[srcNumber].height == 300){
					targetImg.style.marginBottom = "-50px";
					targetImg.style.marginTop = "50px";
				}else{
					targetImg.style.marginTop = "0";
				}
			
			}
		
		}
	
	}
}

function setPng(){
	if(!document.getElementById("check") ){
		return false;
	}
	if(navigator.appVersion.indexOf("MSIE 6",0) != -1){
		var alpha_hreat = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src='./images/bookmark.png')";
		var alpha_rabbit = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src='../images/rabbit.png')";
		Png("bookmark",93,80,alpha_hreat);
		Png("character",291,382,alpha_rabbit);
	}
}
function setPng2(){
	if(!document.getElementById("ladies_character") ){
		return false;
	}
	if(navigator.appVersion.indexOf("MSIE 6",0) != -1){
		var alpha_rabbit2 = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src='./images/ladies_rabbit.png')";
		Png("ladies_character",283,391,alpha_rabbit2);
	}
}
function setPng3(){
	if(!document.getElementById("index_character") ){
		return false;
	}
	if(navigator.appVersion.indexOf("MSIE 6",0) != -1){
		var alpha_rabbit2 = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src='./images/index/rabbit.png')";
		Png("index_character",291,382,alpha_rabbit2);
	}
}
function setPng4(){
	if(!document.getElementById("costume_character") ){
		return false;
	}
	if(navigator.appVersion.indexOf("MSIE 6",0) != -1){
		var alpha_rabbit2 = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src='./images/costume_rabbit.png')";
		Png("costume_character",224,307,alpha_rabbit2);
	}
}
function Png(pngID,WIDTH,HEIGHT,ALPHA){
	if(document.all){
		document.getElementById(pngID).style.width = WIDTH+"px";
		document.getElementById(pngID).style.height = HEIGHT+"px";
		document.getElementById(pngID).style.filter = ALPHA;
		document.getElementById(pngID).firstChild.style.display = "none";
	}
}

//ロールオーバーイメージ
function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");

		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_out."))
			{
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_out.", "_over."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_over.", "_out."));
				}
			}
		}
	}
}

function seedPosition(){
	if(!document.getElementById("ladies") ){
		return false;
	}
	var seeds = document.getElementsByTagName("ul");
	for (var i=0; i<seeds.length; i++) {
		if(seeds[i].getAttribute("className") == "seed" || seeds[i].getAttribute("class") == "seed") {
		//seeds[i].cleanWhitespace(seeds[i]);
		//seeds[i].normalize();
		var listLength = seeds[i].getElementsByTagName("li");
		//alert(listLength.length);
			switch(listLength.length){
				case 1:
					seeds[i].style.marginTop = 52+"px";
					break;
				case 2:
					seeds[i].style.marginTop = 26+"px";
					break;
				default:
					seeds[i].style.marginTop = 0+"px";
					break;
			}
		}
	}
}

function border_none(){
	var all_link = document.links;
	for(i=0;i<all_link.length;i++){
		all_link[i].onfocus = function(){
			this.blur();
		}
	}
}
function favorite(markID,markURL,markTitle){
	if(!document.getElementById(markID)){
		 return false;
	}
	var bookmark = document.getElementById(markID);
	if(navigator.userAgent.indexOf("Opera",0) != -1){
		var elem = document.createElement("a");
		elem.href = markURL;
		elem.title = markTitle;
		elem.rel = "sidebar";
		var str = bookmark.ParentNode;
		elem.appendChild(str);
		str.appendChild(elem);
	}
	bookmark.onclick =function(){
	if(navigator.appVersion.indexOf("MSIE",0) != -1){
			window.external.AddFavorite(markURL,markTitle);
		}else if(navigator.userAgent.indexOf("Firefox",0) != -1){
			window.sidebar.addPanel(markTitle,markURL,'');
		}else if(navigator.userAgent.indexOf("Opera",0) != -1){
			return;
		}else{
			alert("WindowsはCtrl+D | MacはCmd+D を押して手動でブックマークして下さい。");
		}
	}
}



function blackwindow(){
	if(!document.getElementById("ladies")){
		return false;
	}
	//divを作成しidをつけ、body直下に設置//
	var element = document.createElement("div");
	element.id = "black";
	document.body.insertBefore(element,document.body.firstChild);
	element.style.display = "none";
	//フレームを含む高さの振り分け//
	
	if(document.all){
		//element.style.height = document.body.scrollHeight;
		theight = document.body.scrollHeight;
	}else{
		//element.style.height = document.documentElement.scrollHeight;
		theight = document.documentElement.scrollHeight;
	}
	
	if(navigator.appVersion.indexOf("MSIE",0) != -1){
		nheight = document.body.clientHeight;
	}else if(navigator.userAgent.indexOf("Firefox",0) != -1){
		nheight = document.documentElement.clientHeight;
		// + window.scrollMaxY +"px";
	}else{
		nheight =  document.body.scrollHeight;
		// +"px";
	}
	if(nheight > theight){
		fHeight = nheight;
	}else{
		fHeight = theight;
	}
	element.style.height = fHeight+"px";


	//divを作成しidをつけ、最初に作ったdivの直下(bodyから2つ目)に設置//
	var iframe = document.createElement("div");
	iframe.id= "ladyWindow";
	document.body.insertBefore(iframe,document.body.firstChild.nextSibling);
	iframe.style.display = "none";
	
	//ladiesの長さ分、リンクを取りに行く//
	var ladies = document.getElementById("ladies");
	var links = ladies.getElementsByTagName("a");
	for(var i=0; i<links.length; i++){
		links[i].onclick =function(ladyName){
			var ladyName = this.getAttribute("href");
			element.style.display = "inline";
			iframe.style.display = "inline";
			if(navigator.appVersion.indexOf("MSIE",0) != -1){
			var iframeData = '<iframe src="'+ ladyName +'" width="840px" height="550px" scrolling="no" frameborder="0" allowtransparency="true">この部分はインラインフレーム対応のブラウザで見てください。</iframe>';
			}else {
			var iframeData = '<iframe src="'+ ladyName +'" width="856px" height="550px" scrolling="no" frameborder="0" allowtransparency="true">この部分はインラインフレーム対応のブラウザで見てください。</iframe>';
			}
			iframe.innerHTML = iframeData;
			//スクロールがでた際のifremeの表示の上余白設定//
			if(document.documentElement.scrollTop){
				newTop = document.documentElement.scrollTop;
			}else{
				newTop = document.body.scrollTop;
			}
			iframe.style.top = newTop + "px" ;
			

			//表示・非表示の実行//
			element.onclick = function(){
				element.style.display = "none";
				iframe.style.display = "none";
				iframe.firstChild.removeAttribute("src");
			}
			iframe.onclick = function(){
				element.style.display = "none";
				iframe.style.display = "none";
				iframe.firstChild.removeAttribute("src");
			}

		return false;
		}
	}
}
function getwindowheight(){
	if(!document.getElementById("black")){
		return false;
	}
	var element = document.getElementById("black");
	
		if(document.all){
		//element.style.height = document.body.scrollHeight;
		theight = document.body.scrollHeight;
	}else{
		//element.style.height = document.documentElement.scrollHeight;
		theight = document.documentElement.scrollHeight;
	}
	
	if(navigator.appVersion.indexOf("MSIE",0) != -1){
		nheight = document.body.clientHeight;
	}else if(navigator.userAgent.indexOf("Firefox",0) != -1){
		nheight = document.documentElement.clientHeight;
		// + window.scrollMaxY +"px";
	}else{
		nheight =  document.body.scrollHeight;
		// +"px";
	}
	if(nheight > theight){
		fHeight = nheight;
	}else{
		fHeight = theight;
	}
	element.style.height = fHeight+"px";
}

window.onresize = getwindowheight;



function winClose(){
	if(!document.getElementById("close")){
		return false;
	}
	var btnClose = document.getElementById("close").firstChild;
	btnClose.onclick = function(){
		if(parent.document.getElementById("black")){
		parent.document.getElementById("black").style.display = "none";
		parent.document.getElementById("ladyWindow").style.display = "none";
		}else{
		window.close();
		}
	}
}

function flashban() {
	if(!document.getElementById("banner")){
		return false;
	}
	var banClick = document.getElementById("banner").getElementsByTagName("a");
	for (var i=0; i<banClick.length; i++) {
		banClick[i].onclick=function(){
			alert("右クリック→保存を選択してください。");
			return false;
		}
	}
}

function magazineWin(){
	window.open("","magazine","width=500,height=400,scrollbars=no");
	
	return true;
}

function smartPhoneRedirect(){

	if(	document.getElementById("image") || document.getElementById("mailmaga")){
		return;
	}

	var career = new Array("iPhone",  			// Apple iPhone
							"iPod", 			// Apple iPod touch
							"incognito", 		// Other iPhone browser
							"webmate", 			// Other iPhone browser
							"Android", 			// 1.5+ Android
							"dream", 			// Pre 1.5 Android
							"CUPCAKE", 			// 1.5+ Android
							"blackberry9500",	// Storm
							"blackberry9530",	// Storm
							"blackberry9520",	// Storm v2
							"blackberry9550",	// Storm v2
							"blackberry 9800",	// Torch
							"webOS",			// Palm Pre Experimental
							"s8000", 			// Samsung Dolphin browser
							"bada",				// Samsung Dolphin browser
							"Googlebot-Mobile"	// the Google mobile crawler
						);

	var user = navigator.userAgent;
	
	for(i=0;i<career.length;i++){
		
		if(user.indexOf(career[i]) != -1){
			
			var btn = document.createElement("div");
			btn.style.fontFamily = 'Meiryo,"ヒラギノ角ゴ Pro W3","Hiragino Kaku Gothic Pro W3","ＭＳ Ｐゴシック",sans-serif';
			btn.style.fontSize = "36px";
			btn.style.cursor = "pointer";
			btn.style.textAlign = "center";
			btn.style.margin = "0";
			btn.style.padding = "0";
			btn.style.fontWeight = "bold";
			btn.style.width = "100%";
			btn.style.height = "100px";
			btn.style.lineHeight = "100px";
			btn.style.color = "#ffffff";
			btn.style.whiteSpace = "nowrap";
			btn.style.textShadow = "0px -1px 1px #000000";
			btn.style.border = "solid 1px #000000";
			btn.style.background = "-webkit-gradient(linear, left top, left bottom, from(#9f0505), to(#ff9899))";
			
			btn.innerHTML = 'スマートフォン版はコチラ';
			
			btn.onclick = function(){
				
				document.cookie = "mode=sp;path=/;";
				
				host_name = location.host;
				now_url = location.href;
				urlArray = now_url.split(host_name);
				spURL = urlArray.join(host_name+"/sp");
				spURL = spURL.replace("link/","");

				location.href = spURL;
			}

			document.body.insertBefore(btn,document.body.firstChild);
			
			break;
		}
	}
	return;

}

