// Corner

$(function(){
	$('div.corner_h1').corner("6px");
	$('div.corner_dt').corner("8px");
	$('.corner').corner("8px");
});


// Jumptop

var __scroll = {sp:6, fps:16, timer:0};
function setScrollSp(sp) {
	if(typeof sp == "number") {
		this.__scroll.sp = sp;
	}
}
function setScrollFps(fps) {
	if(typeof fps == "number") {
		this.__scroll.fps = fps;
	}
}
function scrollToTop() {
	pageScroll(0, 0);
}
function getScrollLeft() {
	if(navigator.userAgent.indexOf("MSIE") != -1) {
		return (document.compatMode=="CSS1Compat")?document.documentElement.scrollLeft:document.body.scrollLeft;
	} else {
 	 return (window.pageXOffset) ? window.pageXOffset : 0;
 }
}
function getScrollTop() {
	if(navigator.userAgent.indexOf("MSIE") != -1) {
		return (document.compatMode=="CSS1Compat")?document.documentElement.scrollTop:document.body.scrollTop;
	} else {
 	 return (window.pageYOffset) ? window.pageYOffset : 0;
 }
}
function pageScroll(toX, toY, cuX, cuY) {
	clearTimeout(this.__scroll.timer);
	toX = (!toX || toX < 0) ? 0 : toX;
	toY = (!toY || toY < 0) ? 0 : toY;
	cuX = (!cuX) ? 0 + getScrollLeft() : cuX;
	cuY = (!cuY) ? 0 + getScrollTop() : cuY;
	cuX += (toX - getScrollLeft()) / this.__scroll.sp;
	cuY += (toY - getScrollTop()) / this.__scroll.sp;
	if(cuX < 0) { cuX = 0; }
	if(cuY < 0) {	cuY = 0;	}
	window.scrollTo(Math.floor(cuX), Math.floor(cuY));
	if(Math.floor(cuX) != toX || Math.floor(cuY) != toY) {
		this.__scroll.timer = setTimeout("pageScroll("+toX+","+toY+"," +cuX+","+cuY+")",this.__scroll.sp);
	}
}



// pulldown
  $(document).ready(function(){
		$("#nav-one li").hover(
			function(){ $("ul", this).fadeIn("fast"); },
			function() { }
		);
	if (document.all) {
			$("#nav-one li").hoverClass ("sfHover");
		}
  });

	$.fn.hoverClass = function(c) {
		return this.each(function(){
			$(this).hover(
				function() { $(this).addClass(c);  },
				function() { $(this).removeClass(c); }
			);
		});
	};


// Searchbox

$(document).ready(function() {
	$('input[title]').each(function() {
		if($(this).val() === '') {
			$(this).val($(this).attr('title'));
		}

		$(this).focus(function() {
			if($(this).val() == $(this).attr('title')) {
				$(this).val('').addClass('focused');
			}
		});
		$(this).blur(function() {
			if($(this).val() === '') {
				$(this).val($(this).attr('title')).removeClass('focused');
			}
		});
	});
});


// smartRollover

function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");

		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_off."))
			{
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
				}
			}
		}
	}
}

if(window.addEventListener) {
	window.addEventListener("load", smartRollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", smartRollover);
}


// styleswih
(function($)
{
	$(document).ready(function() {
		$('.large,.small').click(function()
		{
			switchStylestyle(this.getAttribute("rel"));
			return false;
		});
		var c = readCookie('style');
		if (c) switchStylestyle(c);
	});

	function switchStylestyle(styleName)
	{
		$('link[@rel*=style][title]').each(function(i)
		{
			this.disabled = true;
			if (this.getAttribute('title') == styleName) this.disabled = false;
		});
		createCookie('style', styleName, 365);
	}
})(jQuery);
// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}


// openfold

$(document).ready(function(){
$(".hide").css("display","none");
$("#btn_key").click(function () { $(".hide").slideToggle(); } );
$("#btn_key").click(function () { $(".btn_toggle").toggle(); } );
});

//Popup

function popWin()
{
   var p=popWin.arguments;//　引数の配列オブジェクトをｐに代入
   var n=p.length;//　引数の数を取得
   if(n==1){window.open(p[0]);}
   if(n==3){window.open(p[0],"","width="+p[1]+",height="+p[2]);}
   if(n==5){window.open(p[0],"","width="+p[1]+",height="+p[2]+",left="+p[3]+",top="+p[4]);}
   if(n==6){window.open(p[0],"","width="+p[1]+",height="+p[2]+",left="+p[3]+",top="+p[4]+","+p[5]);}
}

//Tooltip

(function($){
	// ここからツールチッププラグイン
	$.fn.coopToolTip = function(options)
	{
		$(this).filter(function()
		{
			// titleかaltを持っているものだけに絞る
			return this.title || this.alt;
		})
		.each(
			function()
			{
				if ('' == $(this).attr('title'))
				{
					$(this).attr('title', $(this).attr('alt'));
				}
			});
	}
})(jQuery);

$(document).ready(function($){
	// ツールチップの実行
	$("#entry img, #page img").coopToolTip();
});



// Redirect
var setRedirect	= function(destination, delay)
{
	if (delay == null)
	{
		delay	= 3;
	}

	$(document).ready(function(){
		setTimeout(
			function(){
				window.location = destination;
			}, delay*1000);

		$('#contents').html('<div id="redirect-message">'
				+ 'ご指定のコンテンツは以下のURLへ移動しましたので新しいURLへ転送します。<br />'
				+ '自動的に切り替わらに場合は<a href="'
				+ destination
				+ '">こちらをクリック</a>して移動してください。</div>');
	});
}

//RedirectOut
var setRedirectOut	= function(destination, delay, other)
{
//	$('#contents').html('');

	if (delay == null)
	{
		delay	= 3;
	}

	$(document).ready(function(){
		setTimeout(
			function(){
				if ( other == null ){
					window.location = destination;
				} else {
					window.open(destination);
				}
			}, delay*1000);

	});
}


// google map rendering helper yoshii@sonicnoise.org
var renderMap = function(options)
{
	if (options.mode === 'latlng')
	{
	  $(document).ready(function(){
		  	if (options.zoom === null)
	  		{
		  		options.zoom	= 15;
	  		}
		  	var pos	= new google.maps.LatLng(options.lat, options.lng);
		    var mopt = {
		      zoom: options.zoom,
		      center: pos,
		      mapTypeId: google.maps.MapTypeId.ROADMAP
		    };
		    var map = new google.maps.Map(document.getElementById(options.targetid), mopt);
			var mmaker = new google.maps.Marker({
				position:	pos,
				map:	map,
				icon:	'/img/common/mapicon.png'
			});
	  });
	}

	if (options.mode === 'address')
	{
		var geocoder = new google.maps.Geocoder();
		geocoder.geocode(
			{'address': options.address},
			function(results, status)
			{
				if (status === google.maps.GeocoderStatus.OK)
				{
				  	var pos	= results[0].geometry.location;
				    var mopt = {
				      zoom: options.zoom,
				      center: pos,
				      mapTypeId: google.maps.MapTypeId.ROADMAP
				    };
				    var map = new google.maps.Map(document.getElementById(options.targetid), mopt);
					var marker = new google.maps.Marker({
						map: map,
						position: pos,
						icon:	'/img/common/mapicon.png'
					});
				}
			});
	}
}
