/* ============================================================
 * ndc hara institute
 * Version: 2011-06
 ============================================================ */

function checkWindowSize(){
	if (($(window).width() > 865) && ($(window).height() > 570)){ $('#gNavInner').addClass('large');} else { $('#gNavInner').removeClass('large');}
}
$(function(){
// globalNav gNavInner
	if ($.browser.msie && $.browser.version <= 6){
		$('#gNavInner').addClass('gNavIE6').removeClass('large');
		var name = ".gNavIE6";
		var menuYloc = null;
		menuYloc = parseInt($(name).css('top').substring(0,$(name).css('top').indexOf('px')))
		$(window).scroll(function (){ 
			offset = menuYloc+$(document).scrollTop()+'px';
			$(name).animate({top:offset},{duration:1,queue:false});
		});
	} else {
		checkWindowSize();
		$(window).resize(checkWindowSize);
	}

	var local = $('body.noindexpage #gnav li.active');
	$('#gnav li.active').not(local).each(function(){
		$(this).animate({left: '-=79px'}, 500, function(){
if ($.browser.msie && $.browser.version <= 7){
			$('#localNav').show(1000, function(){
				$(this).children('.active').animate({left: '-=27px'}, 500);
			});
} else {
			$('#localNav').slideDown(1000, function(){
				$(this).children('.active').animate({left: '-=27px'}, 500);
			});
}
		});
	});
	
	$('body.noindexpage #gnav li.active').each(function() {
		$(this).css('margin-left','0');
		$('#localNav').show().children('.active').animate({left: '-=27px'}, 500);
	});

// lang
	$('#lang').not('.homedir').find('li').not('.current').click(function() {
		var str = $(this).children('a').attr('href');
		var strlink = str.split('#');
		var lang = strlink[1];
		var url = document.URL.split('/');
		crtdir = url[5];
		var path = window.location+"";
		//alert(path);
		if ( lang == 'jp') {
			location.href = location.href.replace( '/cn/', '/' );
			return false;
		}
		if ( path.indexOf("/"+lang+"/") == -1 ) {
			location.href = location.href.replace( crtdir, lang );
			return false;
		}
	});

// rollover
	var aPreLoad = new Object();
	$('.btn a img').not('[src*="_crt"], [src*="_ov"]').each(function(i){
		var tsrc = this.src;
		var ftype = this.src.lastIndexOf(".");
		var hsrc = this.src.substr(0, ftype) + "_ov" + this.src.substr(ftype, 4);
		aPreLoad[this.src] = new Image(); aPreLoad[this.src].src = hsrc;
		$(this).hover(function(){ this.src = hsrc; }, function(){ this.src = tsrc; });
	});

// links
	$('a[href*=".pdf"], a[href^="http://"], a[rel="external"]').not('a[rel="sns"], a[href^="http://www.hfgtzy.gov.cn/heavens/"], a[href^="http://www.hfgtzy.gov.cn/heavens/"], a[href^="http://www.hfgtzy.gov.cn/heavens/"]').click(function(){ this.target = '_blank';});
	$('a[rel="sns"]').click(function(){
		var newWin =window.open(this.href,"popwin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=400");
		return false;
	});

// plugins
	$('.pageBooks #oneself li > .list').flatHeights();
	$('.pageBooks #EXHIBITION li > .list').flatHeights();
	$('.pageBooks #collective li > .list').flatHeights();
	$('.pageBooks #Ex-formation li > .list').flatHeights();

// Slides
	$('.photo').hover(function(){
		$('.slide-prev, .slide-next', this).show().css('display', 'block');
	}, function(){
		$('.slide-prev, .slide-next').hide().css('display', 'none');
	});

// tab
	var tabContainers = $('div.tabarea > div');
	tabContainers.hide();
	$('div.tabarea ul.links a').click(function () {
		$('div.tabarea').addClass('active');
if ($.browser.msie && $.browser.version <= 6){ tabContainers.hide().filter(this.hash).show();} else { tabContainers.hide().filter(this.hash).slideDown();}
		$('div.tabarea ul.links a').removeClass('expanded');
		$(this).addClass('expanded');
		return false;
	});

	$('#staff_block img').hide();
	$('#staff_block li').hover(function(){
		$(this).children('img').show();
		var haraph = $(this).attr('class');
		$('#haraPhoto img').attr({src: '/hara/about/img/'+haraph+'.jpg' });
	}, function(){
		$(this).children('img').hide();
		$('#haraPhoto img').attr({src: '/hara/about/img/hara.jpg' });
	});

// etc
	$('img').error(function(){
		$(this).attr('src', '/img/error.gif');
	});
	if (navigator.platform == "iPad" || navigator.platform == "iPhone") { } else {
		$('.pageindex #content img, .entry-list #content img').lazyload({
			effect: "fadeIn",
			placeholder: "/img/grey.gif"
		});
	}
});

/* - end -
 ------------------------------------------------------------ */

/* ============================================================
 * jquery.flatheights.js
 * Version: 2010-09-15

 * Copyright (c) 2007, KITAMURA Akatsuki
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 ============================================================ */
/* $.changeLetterSize.addHandler(func) */
jQuery.changeLetterSize = { handlers : [], interval : 1000, currentSize: 0};
(function($) {
 var self = $.changeLetterSize;
 var ins = $('<ins>M</ins>').css({ display: 'block', visibility: 'hidden', position: 'absolute', padding: '0', top: '0' });
 var isChanged = function() { ins.appendTo('body'); var size = ins[0].offsetHeight; ins.remove(); if (self.currentSize == size) return false; self.currentSize = size; return true; };
 $(isChanged);
 var observer = function() { if (!isChanged()) return; $.each(self.handlers, function(i, handler) { handler(); }); };
 self.addHandler = function(func) { self.handlers.push(func); if (self.handlers.length == 1) { setInterval(observer, self.interval); } };
})(jQuery);

/* $(expr).flatHeights() */
(function($) {
 var sets = [];
 var flatHeights = function(set) { var maxHeight = 0; set.each(function(){ var height = this.offsetHeight; if (height > maxHeight) maxHeight = height; }); set.css('height', maxHeight + 'px'); };
jQuery.fn.flatHeights = function() { if (this.length > 1) { flatHeights(this); sets.push(this); } return this; };
var reflatting = function() { $.each(sets, function() { this.height('auto'); flatHeights(this); }); };
$.changeLetterSize.addHandler(reflatting);
$(window).resize(reflatting);
})(jQuery);

/* ============================================================
 * Slides, A Slideshow Plugin for jQuery
 * Intructions: http://slidesjs.com
 * By: Nathan Searles, http://nathansearles.com
 * Version: 1.1.7
 * Updated: May 2nd, 2011
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ============================================================ */
(function($){$.fn.slides=function(g){g=$.extend({},$.fn.slides.option,g);return this.each(function(){$('.'+g.container,$(this)).children().wrapAll('<div class="slides_control"/>');var d=$(this),control=$('.slides_control',d),total=control.children().size(),width=control.children().outerWidth(),height=control.children().outerHeight(),start=g.start-1,effect=g.effect.indexOf(',')<0?g.effect:g.effect.replace(' ','').split(',')[0],paginationEffect=g.effect.indexOf(',')<0?effect:g.effect.replace(' ','').split(',')[1],next=0,prev=0,number=0,current=0,loaded,active,clicked,position,direction,imageParent,pauseTimeout,playInterval;function animate(a,b,c){if(!active&&loaded){active=true;g.animationStart(current+1);switch(a){case'next':prev=current;next=current+1;next=total===next?0:next;position=width*2;a=-width*2;current=next;break;case'prev':prev=current;next=current-1;next=next===-1?total-1:next;position=0;a=0;current=next;break;case'pagination':next=parseInt(c,10);prev=$('.'+g.paginationClass+' li.'+g.currentClass+' a',d).attr('href').match('[^#/]+$');if(next>prev){position=width*2;a=-width*2}else{position=0;a=0}current=next;break}if(b==='fade'){if(g.crossfade){control.children(':eq('+next+')',d).css({zIndex:10}).fadeIn(g.fadeSpeed,g.fadeEasing,function(){if(g.autoHeight){control.animate({height:control.children(':eq('+next+')',d).outerHeight()},g.autoHeightSpeed,function(){control.children(':eq('+prev+')',d).css({display:'none',zIndex:0});control.children(':eq('+next+')',d).css({zIndex:0});g.animationComplete(next+1);active=false})}else{control.children(':eq('+prev+')',d).css({display:'none',zIndex:0});control.children(':eq('+next+')',d).css({zIndex:0});g.animationComplete(next+1);active=false}})}else{control.children(':eq('+prev+')',d).fadeOut(g.fadeSpeed,g.fadeEasing,function(){if(g.autoHeight){control.animate({height:control.children(':eq('+next+')',d).outerHeight()},g.autoHeightSpeed,function(){control.children(':eq('+next+')',d).fadeIn(g.fadeSpeed,g.fadeEasing)})}else{control.children(':eq('+next+')',d).fadeIn(g.fadeSpeed,g.fadeEasing,function(){if($.browser.msie){$(this).get(0).style.removeAttribute('filter')}})}g.animationComplete(next+1);active=false})}}else{control.children(':eq('+next+')').css({left:position,display:'block'});if(g.autoHeight){control.animate({left:a,height:control.children(':eq('+next+')').outerHeight()},g.slideSpeed,g.slideEasing,function(){control.css({left:-width});control.children(':eq('+next+')').css({left:width,zIndex:5});control.children(':eq('+prev+')').css({left:width,display:'none',zIndex:0});g.animationComplete(next+1);active=false})}else{control.animate({left:a},g.slideSpeed,g.slideEasing,function(){control.css({left:-width});control.children(':eq('+next+')').css({left:width,zIndex:5});control.children(':eq('+prev+')').css({left:width,display:'none',zIndex:0});g.animationComplete(next+1);active=false})}}if(g.pagination){$('.'+g.paginationClass+' li.'+g.currentClass,d).removeClass(g.currentClass);$('.'+g.paginationClass+' li:eq('+next+')',d).addClass(g.currentClass)}}}function stop(){clearInterval(d.data('interval'))}function pause(){if(g.pause){clearTimeout(d.data('pause'));clearInterval(d.data('interval'));pauseTimeout=setTimeout(function(){clearTimeout(d.data('pause'));playInterval=setInterval(function(){animate("next",effect)},g.play);d.data('interval',playInterval)},g.pause);d.data('pause',pauseTimeout)}else{stop()}}if(total<2){return}if(start<0){start=0}if(start>total){start=total-1}if(g.start){current=start}if(g.randomize){control.randomize()}$('.'+g.container,d).css({overflow:'hidden',position:'relative'});control.children().css({position:'absolute',top:0,left:control.children().outerWidth(),zIndex:0,display:'none'});control.css({position:'relative',width:(width*3),height:height,left:-width});$('.'+g.container,d).css({display:'block'});if(g.autoHeight){control.children().css({height:'auto'});control.animate({height:control.children(':eq('+start+')').outerHeight()},g.autoHeightSpeed)}if(g.preload&&control.find('img').length){$('.'+g.container,d).css({background:'url('+g.preloadImage+') no-repeat 50% 50%'});var f=control.find('img:eq('+start+')').attr('src')+'?'+(new Date()).getTime();if($('img',d).parent().attr('class')!='slides_control'){imageParent=control.children(':eq(0)')[0].tagName.toLowerCase()}else{imageParent=control.find('img:eq('+start+')')}control.find('img:eq('+start+')').attr('src',f).load(function(){control.find(imageParent+':eq('+start+')').fadeIn(g.fadeSpeed,g.fadeEasing,function(){$(this).css({zIndex:5});$('.'+g.container,d).css({background:''});loaded=true;g.slidesLoaded()})})}else{control.children(':eq('+start+')').fadeIn(g.fadeSpeed,g.fadeEasing,function(){loaded=true;g.slidesLoaded()})}if(g.bigTarget){control.children().css({cursor:'pointer'});control.children().click(function(){animate('next',effect);return false})}if(g.hoverPause&&g.play){control.bind('mouseover',function(){stop()});control.bind('mouseleave',function(){pause()})}if(g.generateNextPrev){$('.'+g.container,d).after('<a href="#" class="'+g.prev+'">Prev</a>');$('.'+g.prev,d).after('<a href="#" class="'+g.next+'">Next</a>')}$('.'+g.next,d).click(function(e){e.preventDefault();if(g.play){pause()}animate('next',effect)});$('.'+g.prev,d).click(function(e){e.preventDefault();if(g.play){pause()}animate('prev',effect)});if(g.generatePagination){if(g.prependPagination){d.prepend('<ul class='+g.paginationClass+'></ul>')}else{d.append('<ul class='+g.paginationClass+'></ul>')}control.children().each(function(){$('.'+g.paginationClass,d).append('<li><a href="#'+number+'">'+(number+1)+'</a></li>');number++})}else{$('.'+g.paginationClass+' li a',d).each(function(){$(this).attr('href','#'+number);number++})}$('.'+g.paginationClass+' li:eq('+start+')',d).addClass(g.currentClass);$('.'+g.paginationClass+' li a',d).click(function(){if(g.play){pause()}clicked=$(this).attr('href').match('[^#/]+$');if(current!=clicked){animate('pagination',paginationEffect,clicked)}return false});$('a.link',d).click(function(){if(g.play){pause()}clicked=$(this).attr('href').match('[^#/]+$')-1;if(current!=clicked){animate('pagination',paginationEffect,clicked)}return false});if(g.play){playInterval=setInterval(function(){animate('next',effect)},g.play);d.data('interval',playInterval)}})};$.fn.slides.option={preload:false,preloadImage:'/img/loading.gif',container:'slides_container',generateNextPrev:false,next:'next',prev:'prev',pagination:true,generatePagination:true,prependPagination:false,paginationClass:'pagination',currentClass:'current',fadeSpeed:350,fadeEasing:'',slideSpeed:350,slideEasing:'',start:1,effect:'slide',crossfade:false,randomize:false,play:0,pause:0,hoverPause:false,autoHeight:false,autoHeightSpeed:350,bigTarget:false,animationStart:function(){},animationComplete:function(){},slidesLoaded:function(){}};$.fn.randomize=function(c){function randomizeOrder(){return(Math.round(Math.random())-0.5)}return($(this).each(function(){var $this=$(this);var $children=$this.children();var a=$children.length;if(a>1){$children.hide();var b=[];for(i=0;i<a;i++){b[b.length]=i}b=b.sort(randomizeOrder);$.each(b,function(j,k){var $child=$children.eq(k);var $clone=$child.clone(true);$clone.show().appendTo($this);if(c!==undefined){c($child,$clone)}$child.remove()})}}))}})(jQuery);

/* ============================================================
 * Lazy Load - jQuery plugin for lazy loading images
 * Copyright (c) 2007-2009 Mika Tuupola
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 * Project home:
 *   http://www.appelsiini.net/projects/lazyload
 * Version:  1.5.0
 ============================================================ */
(function($){$.fn.lazyload=function(options){var settings={threshold:0,failurelimit:0,event:"scroll",effect:"show",container:window};if(options){$.extend(settings,options);}
var elements=this;if("scroll"==settings.event){$(settings.container).bind("scroll",function(event){var counter=0;elements.each(function(){if($.abovethetop(this,settings)||$.leftofbegin(this,settings)){}else if(!$.belowthefold(this,settings)&&!$.rightoffold(this,settings)){$(this).trigger("appear");}else{if(counter++>settings.failurelimit){return false;}}});var temp=$.grep(elements,function(element){return!element.loaded;});elements=$(temp);});}
this.each(function(){var self=this;if(undefined==$(self).attr("original")){$(self).attr("original",$(self).attr("src"));}
if("scroll"!=settings.event||undefined==$(self).attr("src")||settings.placeholder==$(self).attr("src")||($.abovethetop(self,settings)||$.leftofbegin(self,settings)||$.belowthefold(self,settings)||$.rightoffold(self,settings))){if(settings.placeholder){$(self).attr("src",settings.placeholder);}else{$(self).removeAttr("src");}
self.loaded=false;}else{self.loaded=true;}
$(self).one("appear",function(){if(!this.loaded){$("<img />").bind("load",function(){$(self).hide().attr("src",$(self).attr("original"))
[settings.effect](settings.effectspeed);self.loaded=true;}).attr("src",$(self).attr("original"));};});if("scroll"!=settings.event){$(self).bind(settings.event,function(event){if(!self.loaded){$(self).trigger("appear");}});}});$(settings.container).trigger(settings.event);return this;};$.belowthefold=function(element,settings){if(settings.container===undefined||settings.container===window){var fold=$(window).height()+$(window).scrollTop();}else{var fold=$(settings.container).offset().top+$(settings.container).height();}
return fold<=$(element).offset().top-settings.threshold;};$.rightoffold=function(element,settings){if(settings.container===undefined||settings.container===window){var fold=$(window).width()+$(window).scrollLeft();}else{var fold=$(settings.container).offset().left+$(settings.container).width();}
return fold<=$(element).offset().left-settings.threshold;};$.abovethetop=function(element,settings){if(settings.container===undefined||settings.container===window){var fold=$(window).scrollTop();}else{var fold=$(settings.container).offset().top;}
return fold>=$(element).offset().top+settings.threshold+$(element).height();};$.leftofbegin=function(element,settings){if(settings.container===undefined||settings.container===window){var fold=$(window).scrollLeft();}else{var fold=$(settings.container).offset().left;}
return fold>=$(element).offset().left+settings.threshold+$(element).width();};$.extend($.expr[':'],{"below-the-fold":"$.belowthefold(a, {threshold : 0, container: window})","above-the-fold":"!$.belowthefold(a, {threshold : 0, container: window})","right-of-fold":"$.rightoffold(a, {threshold : 0, container: window})","left-of-fold":"!$.rightoffold(a, {threshold : 0, container: window})"});})(jQuery);


