/* スマートフォン版へ */

var Smartphone = function() {
	this.isSmartphone = false;
	this.device = "PC";
	this.url = "http://www.bitcash.jp/lite/";
	this.targetId = "#container"; // ボタンを挿入する場所
	this.init();
	this.setUrl();

}

Smartphone.prototype = {
	init: function() {
		var ua = navigator.userAgent;
		if(ua.indexOf('iPhone') > 0) {
			this.isSmartphone = true;
			this.device = "iPhone";
		}
		/*
		if(ua.indexOf('iPad') > 0) {
			this.isSmartphone = true;
			this.device = "iPad";
		}
		*/
		if(ua.indexOf('iPod') > 0) {
			this.isSmartphone = true;
			this.device = "iPod";
		}
		if(ua.indexOf('Android') > 0) {
			this.isSmartphone = true;
			this.device = "Android";
		}
		
	},
	setUrl: function() {
		var nowUrl = document.URL;
		var afterUrl = "";
		var regMy = new RegExp("(bitcash\.jp\/my\/)+", "gi");
		var regCheckout = new RegExp("(bitcash\.jp\/checkout\/)+", "gi");
		var regWww = new RegExp("(bitcash\.jp\/)+", "gi");
		var regUrlAfter = "$1lite/";
		
		if(nowUrl.match(regMy)){
			afterUrl = nowUrl.replace(regMy, regUrlAfter);
			
		}else if(nowUrl.match(regCheckout)){
			afterUrl = nowUrl.replace(regCheckout, regUrlAfter);
			
		}else if(nowUrl.match(regWww)){
			afterUrl = nowUrl.replace(regWww, regUrlAfter);
			
		}else{
			afterUrl = nowUrl;
			
		}
		this.url = afterUrl;
	},
	showButton: function() {
		if(this.isSmartphone && (document.cookie.indexOf("view_pc") >= 0)) {
			$(this.targetId).before("<div id=\"forSmartphone\"><a href=\"" + this.url + "\">スマートフォン版へ</a></div>");
			$("#forSmartphone").css({
				background: "#515151",
				textAlign: "center",
				paddingTop: "30px",
				paddingBottom: "23px",
				height: "70px",
				borderBottom: "solid 1px #d6d6d6"
			});
			$("#forSmartphone a").css({
				padding: "15px 20px",
				color: "#333",
				fontWeight: "bold",
				textDecoration: "none",
				background: "-webkit-gradient(linear,left top,left bottom,color-stop(0, #ffffff),color-stop(0.50, #d6d6d6),color-stop(0.50, #bebebe),color-stop(1, #ffffff))",
				webkitBorderRadius: "20px",
				textShadow: "0px 1px 1px #fff",
				marginLeft: "auto",
				marginRight: "auto",
				fontSize: "60px",
				lineHeight: "60px"
			});
		}
	},
	redirect: function() {
		if(this.isSmartphone && (document.cookie.indexOf("view_pc") < 0)) {
			window.location.href = smartphoneObj.url;
		}
	}
}

var smartphoneObj = new Smartphone();

$(function(){
	smartphoneObj.showButton();
});
