window.onload = init;

function init() {
	initRollovers();
	popupWindow(740, 690);
	favorite("fav", "http://www.hiiki.jp", "大塚～鶯谷デリヘル えこ贔屓");
	smartPhoneRedirect();
	eventWin();
}

//-----------------------------------------------
//	西暦表示
//-----------------------------------------------
function setYear() {
	var date = new Date();
	document.write(date.getFullYear());
}

//-----------------------------------------------
//	ロールオーバー
//-----------------------------------------------
function initRollovers() {
	if (!document.getElementById) return;

	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {	
		if (aImages[i].className == 'rollover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			hsrc = src.replace(ftype, '_over'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);

			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;

			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	

			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_over'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

//-----------------------------------------------
//	お気に入り追加
//-----------------------------------------------
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 popupWindow(_width, _height) {
	var options = "width=" + _width + ",height=" + _height + ",scrollbars=no";
	var open = function(url) {
		var newWindow = window.open(url, "popup", options);
		//newWindow = window.open(url,"popup","width=740,height=690,scrollbars=no");
		newWindow.focus();
	}
	
	var links = document.getElementsByTagName("a");
	for(var i = 0; i < links.length; i++) {
		if(links[i].className == "popup") {
			links[i].onclick = function() {
				open(this.getAttribute("href"));
				return false;
			}
		}
	}
}

//-----------------------------------------------
//	ピックアップムービー読み込み
//-----------------------------------------------

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="314" height="293">');
	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('<param name="bgcolor" value="#ffffff" />');
	document.write('<embed src="../ladies/swf/pickupmovie.swf?path=../movie/'+ lady_id +'.flv" quality="high" wmode="transparent" bgcolor="#ffffff" width="314" height="293" name="coverflow" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}


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 smartPhoneRedirect(){

	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(#fff3b9), color-stop(50%,#e6bb00), color-stop(50%,#cd9601), to(#fdf7ce))";
			
			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.style.backgroundPosition = "0 102px";
			document.body.insertBefore(btn,document.body.firstChild);
			
			break;
		}
	}
	return;

}


function eventWin(){

	if(!document.getElementById("campaign")){
		return;
	}
	target = document.getElementById("campaign").getElementsByTagName("a")[0];
	target.url = target.href;
	target.removeAttribute("href");
	target.style.cursor = "pointer";
	target.onclick = function(){
		window.open(this.url,"_blank","width=400,height=400");
	}
}
