$(function() {
	//smartRollover

	var imgCount = 0;
	var images_pre = new Array();
	$('img[src*="_off."],input[src*="_off."]').each (function(){
		images_pre[imgCount] = new Image();
		images_pre[imgCount].src = $(this).attr("src").replace("_off.", "_on.");
		$(this).hover(
			function () {
				$(this).attr("src", $(this).attr("src").replace("_off.", "_on."));
			},
			function () {
				$(this).attr("src", $(this).attr("src").replace("_on.", "_off."));
			}
		);
		imgCount ++;
	});



	// opacity Rollover

	$('img[src*="_op."],input[src*="_op."]').hover(
		function () {
			$(this).css('opacity', 0.7);
		},
		function () {
			$(this).css('opacity', 1);
		}
	);



	// external

	var notBlank = new Array("arcenciel-g.jp");

	var n = "";
	for (var i = 0; i < notBlank.length; i ++) if(notBlank[i]) n += ":not([href*='" + notBlank[i] + "'])";
	if(document.domain) n += ":not([href*='" + document.domain + "'])";

	$("a[rel='external'], a[href$='.pdf']").attr("target", "_blank");
	$("a[href^=http]"+n).attr("target", "_blank");


	$('#house a[href^="/perfectguide/"], #luxe a[href^="/perfectguide/"]').attr("target", "_blank");


	// pop up
	$('a[rel="cm"]').click( function(e){
		e.preventDefault();
		var wo = window.open($(this).attr('href'),'cm','scrollbars=yes,resizable=yes,status=yes,menubar=yes,width=700,height=620');
		wo.focus();
	});
	$('a[rel="story"]').click( function(e){
		e.preventDefault();
		var wo = window.open($(this).attr('href'),'story','scrollbars=yes,resizable=yes,status=yes,menubar=yes,width=700,height=620');
		wo.focus();
	});


	// form pop up
	$('a[rel="form"]').click( function(e){
		e.preventDefault();
		var wo = window.open($(this).attr('href'),'form','scrollbars=yes,resizable=yes,status=yes,menubar=yes,width=720,height=620');
		wo.focus();
	});

	// wedding form pop up
	$('a[rel="w_form"]').click( function(e){
		e.preventDefault();
		var wo = window.open($(this).attr('href'),'form','scrollbars=yes,resizable=yes,status=yes,menubar=yes,width=800,height=620');
		wo.focus();
	});

	// form page link
	$('body#form #contentsFooter a, body#form #footContainer a').attr("target", "_blank");



	// add last
	$(".has_last > *:last-child").addClass("last");



	// smoothScroll

	$('a[href^="#"], a[href^="' + location.pathname + '#"]').each (function(){
		var hash = this.hash;
		if(hash.length > 1 && !this['rel']){
			$(this).click(function() {
				smoothScroll(hash);
				return false;
			})
		}
	});


	// font size
	if(!$.cookie('fontsize')) {
		changeSize(0);
	}else {
		changeSize($.cookie('fontsize'));
	}


	// form
	$('#headContainer input.text').focus( function () {
		$(this).css('background', '#ffffff');
	}).blur( function () {
		if($(this).val() == '') $(this).css('background', 'url(http://www.google.com/cse/intl/ja/images/google_custom_search_watermark.gif)');
	}).trigger('blur');
});

function smoothScroll(hash) {
	var target = $(hash).offset().top;

	$(($.browser.safari) ? 'body' : 'html')
		.animate({scrollTop: target >= 15 ? target - 15 : target}, 600, 'swing', function(){$(this).unbind("mousewheel DOMMouseScroll");})
		.bind("mousewheel DOMMouseScroll",function(){
			$(this).queue([]).stop();
			$(this).unbind("mousewheel DOMMouseScroll");
		})
}

function changeSize(cssNum){
	$('link[title]').each(function(i){
		$(this).attr('disabled', true);
		if($('#fontsize').size() > 0) {
			var img = $('#fontsize li:eq('+(i)+') img');
			if(i == cssNum){
				$(this).attr('disabled', false);
				img.unbind();
				img.css('cursor','default').attr('src', img.attr('src').replace('_off', '_on'));
			}else {
				img.css('cursor','pointer').attr('src', img.attr('src').replace('_on', '_off')).hover(
					function () {
						$(this).attr("src", $(this).attr("src").replace("_off.", "_on."));
					},
					function () {
						$(this).attr("src", $(this).attr("src").replace("_on.", "_off."));
					}
				).click( function(){
					changeSize(i);
					setContentsHeight();
				});
			};
		}
	});
	$.cookie('fontsize',cssNum,{expires:30,path:'/'});
}

// pngfix
if($.browser.msie && $.browser.version < 7) DD_belatedPNG.fix('#contentsInner, #helpNavi img, #footContainer img');


// for print
function setContentsHeight(){
	if($('#contentsArea').size() > 0) {
		var prop = $.browser.msie && $.browser.version < 7 ? "height" : "min-height";
		$('#contentsArea').css(prop, 0).css(prop, $('#contentsArea').height());
	}
}

jQuery.event.add(window, "load", function(){
	setContentsHeight();
});


var _gaq = _gaq || [];
_gaq.push(

// turbine
['_setAccount', 'UA-20213569-1'],
['_trackPageview'],

// dimension
['b._setAccount', 'UA-24667896-1'],
['b._trackPageview']
);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0];
	s.parentNode.insertBefore(ga, s);
})();










