jQuery(document).ready(function(){
	/* Resize too large images */
	var size = 590;
	var image = jQuery('#content img');
	
	for (i=0; i<image.length; i++) {
		var bigWidth = image[i].width;
		var bigHeight = image[i].height;
	
		if (bigWidth > size) {	
			var newHeight = bigHeight*size/bigWidth;
			image[i].width = size;
			image[i].height = newHeight;
		}
	}
	
	jQuery("#content a:has(img)").css({'padding': '0', 'background': 'none'});
	jQuery("#s:visible").focus();
	if (jQuery("#archives").is(':visible')) {
		jQuery("#toggleArchives").html("&uarr; Archives &uarr;");
	}

	// メールフォームのsubmitをトラッキング
	jQuery("input.wpcf7-submit").click(function() {
		var ckecked = jQuery("input.wpcf7-acceptance").attr('checked');
		if (ckecked) {
			var pq=window.location.search.substring(1);
			var ttl = document.title;
			var l = ttl.split("|");
			var nv=navigator.appName+navigator.appVersion;
			_gaq.push(['_trackPageview','/mailForm/'+pq]);
			_gaq.push(['_trackEvent','contactForm','submit',l[0],nv]);
		}
	});
	
	// ページ内スクロール
	jQuery('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var jQuerytarget = jQuery(this.hash);
			jQuerytarget = jQuerytarget.length && jQuerytarget || jQuery('[name=' + this.hash.slice(1) +']');
			if (jQuerytarget.length) {
				var targetOffset = jQuerytarget.offset().top;
				jQuery('html,body').animate({scrollTop: targetOffset}, 1000);
				return false;
			}
		}
	});
});

function toggleArchives() {
	if (jQuery("#archives").is(':visible')) {
		jQuery("#archives").slideUp();
		jQuery("#toggleArchives").html("&darr; Archives &darr;");
	}
	else {
		jQuery("#toggleArchives").html("&uarr; Archives &uarr;");
		jQuery("#archives").slideDown(function() {
			jQuery("#s").focus();
		});
	}
}
