
/*
 *1 site
 */
var site = {
	isLogined : false,
	analytics : '',
	//2	setting
	setting : {
		page : {},
		user : {}
	},
	//2	page
	page : {
		init : {
			run : function(){}
		},
		sessionLoaded : {
			run : function(json){}
		}
	},
	pages : {},
	common : {},
	parts : {},
	user : {userNo : 0},
	//2	replaceLoading
	replaceLoading : function(target){
		jQuery(target).find('*').unbind();
		jQuery(target)
		.empty()
		.html(funcs.string.loading());
	},
	funcs : {
		colors : function(dt, cName){
			var second = funcs.string.datetimeAgo(dt);
			if (second < 600){
				return cName + '0';
			} else if (second < 1800){
				return cName + '1';
			} else if (second < 3600){
				return cName + '2';
			} else if (second < (3600 * 24)){
				return cName + '3';
			} else {
				return cName + '4';
			}
		}
	},
	loadScript : function(src){
    var script = document.createElement('scr'+'ipt')
    script.src = src;
    document.body.appendChild(script);
	}
};

jQuery(document).ready(function(){
	
	jQuery('form.aulta-form').aultaFormAddEvent();
	
	jQuery('#primary')
	.mouseleave(function(){jQuery('#menu-top-hidden').show(0);})
	.mouseenter(function(){jQuery('#menu-top-hidden').hide(0);});
	
	jQuery('#main')
	.append(
		jQuery('<a>')
		.attr('href', '#branding')
		.attr('id', 'main-footer-pagetop')
		.text('▲ページの上部へ')
	);
	
	jQuery('a')
	.each(function(){
		var a = jQuery(this)
			, href = a.attr('href');
		if (href.substr(0, 1) == '#'){
			a
			.click(function(){
				var href = jQuery(this).attr('href')
					, target = document.getElementById(href.substr(1));
				if (target){
					jQuery('html,body').animate({ scrollTop: jQuery(target).offset().top }, 'slow', null);
				}
				return false;
			});
		}
	});
	
	(function(){
		var pathname = document.location.pathname;
		jQuery('#secondary a[href="' + document.location.href + '"]').parent().addClass('stay');
		jQuery('#secondary a[href="' + pathname + '"]').parent().addClass('stay');
		if (document.location.search){
			pathname += document.location.search;
			jQuery('#secondary a[href="' + pathname + '"]').parent().addClass('stay');
		}
	})();
	
	(function(){
		if (document.getElementById('auto-scroller')) return;
		jQuery('body')
		.append(
			jQuery('<div>')
			.attr('id', 'auto-scroller')
			.addClass('cbox')
			.append(
				jQuery('<a>').text('▲')
				.click(function(){
					jQuery('html,body').animate({ scrollTop: 0 }, 'slow', null);
				})
			)
			.append(
				jQuery('<a>').text('top')
				.click(function(){
					document.location.href = 'http://aulta.jp/';
				})
			)
			.append(
				jQuery('<a>').text('▼')
				.click(function(){
					jQuery('html,body').animate({ scrollTop: jQuery('#colophon').offset().top - 800 }, 'slow', null);
				})
			)
		);
		jQuery(window)
		.scroll(function(){
			if ( ! document.getElementById('auto-scroller')) return;
			var as = jQuery('#auto-scroller');
			if (as.css('display') == 'none') return;
			as.hide();
			setTimeout(function(){
				var w = jQuery(window);
				as
				.css('top', w.scrollTop() + (w.height() - 130) / 2)
				.show();
			}, 700)
		});
		(function(){
			if ( ! document.getElementById('auto-scroller')) return;
			var w = jQuery(window);
			jQuery('#auto-scroller')
			.css('top', w.scrollTop() + (w.height() - 130) / 2)
			.show(200);
		})();
	})();
	
});



