
$(document).ready(function(){
	//サブナビゲーションの処理
	if(typeof $.slidenav == "function"){
		$.slidenav({
			animspeed: 'medium', //Any of the stanard jQuery animation speed variables, 'medium' by default
			hideonout: 'false' //Either true or false, 'true' by default
		});
	}
	
	//リンク先が外部ならカウンターを呼び出し
	$('a').click(function(){
		if($(this).attr('href').substr(0,7) == "http://"){
			$(this).attr('target', "_blank");
			var img="";
			var url=encodeURIComponent(this.href);
			if($(this).children("img").attr("src")){
				var img=$(this).children("img").attr("src");
			}

			$.get("/php/counter.php", {site: "1", url: url, img: img});
		}
	});

	//携帯メールに送信
	$('a.mobilemail').click(function(){
		//入力ダイアログを表示
		var email = window.prompt("送信先の携帯メールアドレスを入力して下さい。\n（※携帯電話のメールアドレスのみ有効です。）", "");
		var url = $('a.mobilemail').attr("href");
		var title = $('a.mobilemail').attr("title");

		if(email==null){
			return false;
		}

		if(email.match(/([\w\-\.]+)@(docomo|ezweb|[a-z]{1}\.vodafone|softbank|[a-z]{0,3}\.?pdx)(\.ne\.jp)/)){
			if (!Mail_To_Mobile(email, url, title)){
				window.alert(email+"\nにクーポンURLを送信しました。");
			}
			else{
				window.alert("送信失敗しました。");
			}
		}
		else{
			window.alert('メールアドレスを確認して下さい。\n'+email);
		}
		return false;
	});

	//コンテンツページのクーポンポップ
	$("#contents-pop1, #contents-pop2").hover(
		function () { $(this).removeClass("semitransparent")},
		function () { $(this).addClass("semitransparent")}
	);

	$(".close").click(function () {
		$(this).parent().hide("slow");
	});

});

function Mail_To_Mobile(email, url, title){
	$.post("/php/couponmail.php", {email: email, url: url, title: title}, function(rst){
		return rst;
	});
}


function ClickCount(url, img){
	$.get("/php/counter.php", {site: "1", url: url, img: img});
}

function addBookmark(title,url) {
	if (window.sidebar) {
			window.sidebar.addPanel(title, url,"");
	} else if( document.all ) {
			window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
			return true;
	}
}
