/*//////////////////////////////////////////////////////////
//
//  # Functions
//
//  - Auth: ekkun.com [eiji@ekkun.com]
//  - 2011-11-24 (Thu)
//
//////////////////////////////////////////////////////////*/

//$(function(){
jQuery(document).ready(function(){

	// Scroll Parallax
	jQuery('body').scrollParallax({
		'speed': 0.02
	});
	jQuery('#baselayerA').scrollParallax({
		'speed': 0.05
	});
	jQuery('#baselayerB').scrollParallax({
		'speed': 0.10
	});

	// Scroll Flow
//	$("#header h4").hide();
	jQuery('#header h4').css({ 'left': '-135px', 'opacity': '0' });
	jQuery(window).scroll(function() {
		if (jQuery(this).scrollTop() > 140) {
//			jQuery('#gnavi').fadeIn();
			jQuery('#header').css({ 'position': 'fixed', 'top': '0px', 'opacity': '1.0' });
			jQuery('#header').addClass('box_shadow');
			jQuery('#header h5').stop().animate({ 'left': '135px' }, 300);
			jQuery('#header h4').show();
			jQuery('#header h4').stop().animate({ 'left': '0px', 'opacity': '1' }, 300);
		} else {
//			jQuery('#gnavi').fadeOut();
			jQuery('#header').css({ 'position': 'relative', 'top': '0px', 'opacity': '1' });
			jQuery('#header').removeClass('box_shadow');
			jQuery('#header h5').stop().animate({ 'left': '0px' }, 300);
//			jQuery('#header h4').stop().animate({ 'left': '-135px', 'opacity': '0' }, 300);
			jQuery('#header h4').stop().animate({ 'left': '-135px', 'opacity': '0' }, { 'duration': '300', 'complete': function() { jQuery('#header h4').css({ 'display': 'none' }); }});
		}
	});

	// Lightbox
	jQuery('.lightbox').lightbox();

	// Smooth Scroll
	jQuery('a[href="#top"]').easingScroll({
		easing:		'easeInOutExpo',
		duration:	1200
	});
	jQuery('a[rel="comments"]').easingScroll({
		easing:		'easeInOutExpo',
		duration:	1200
	});

	// Ajax Lazyload
/*	jQuery('#container img').lazyload({
		placeholder : '/wp/wp-content/themes/ekkun.com/images/blank.gif',
		effect      : 'fadeIn'
	});*/

	// Auto Pager
	jQuery('#loader').hide();
/*	jQuery.autopager({
		content: '.contents',
		link: '#next a',
		start: function(current, next) {
			jQuery('#loader').fadeIn();
		},
		load: function(current, next) {
			jQuery('#loader').fadeOut('slow');
			jQuery("#loader").hide();
		}
	});*/
	jQuery.autopager({
		autoLoad: false,
		content: '.contents',
		link: '#next a',
		start: function(current, next) {
			jQuery('#loader').fadeIn();
		},
		load: function(current, next) {
/*			if (next.url == '') {
				var nexturl = next.url;
				jQuery('#next').addClass(nexturl);
			}*/
			jQuery('#loader').fadeOut('slow');
			jQuery('#loader').hide();
		}
	});
	jQuery('#next a').click(function() {
		jQuery.autopager('load');
		return false;
	});

	// Focus to Search Window
	var initText = 'Google Search';
	jQuery('#q').focus(function() {
		if (jQuery('#q').val() == initText) {
			jQuery('#q').val('');
			jQuery('#q').css('color','#f17686');
		}
	});
	jQuery('#q').blur(function() {
		if (jQuery('#q').val() == '') {
			jQuery('#q').val(initText);
			jQuery('#q').css('color','#fff');
		}
	});
	jQuery('#btnG').click(function() {
		if (jQuery('#q').val() == initText) {
			jQuery('#q').val('');
			jQuery('#q').css('color','#fff');
		}
		return true;
	});
	if (jQuery('#q').val() == initText) {
		jQuery('#q').css('color','#fff');
	}
	if (jQuery('#q').val() == '') {
		jQuery('#q').val(initText);
		jQuery('#q').css('color','#fff');
	}

	// 慣性スクロール
	$(function() {
		var scrolly = 1;
		var speed = 500;
		$('html').mousewheel(function(event, mov) {
			if(jQuery.browser.webkit){
				if (mov > 0) scrolly =  $('body').scrollTop() - speed;
				else if (mov < 0) scrolly =  $('body').scrollTop() + speed;
			} else {
				if (mov > 0) scrolly =  $('html').scrollTop() - speed;
				else if (mov < 0) scrolly =  $('html').scrollTop() + speed;
			}
			$('html,body')
				.stop()
				.animate({scrollTop: scrolly}, 'slow',$.easie(0,0,0,1));
				//イージングプラグイン使わない場合
				//.animate({ scrollTop: scrolly }, 'normal');
			return false;
		});
	});

});

// Tooltip
var tooltip=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 90;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();

// Comment Facebook
/*(function(d, s, id) {
	var js, fjs = d.getElementsByTagName(s)[0];
	if (d.getElementById(id)) {return;}
	js = d.createElement(s); js.id = id;
	js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=191825747531551";
	fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));*/


