/**---------------------------------
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
 * common.js
 * 
 * ...
 * author	: takaaki koyama
 *
 * @use jQuery later
 ---------------------------------*/
/*! Copyright (c) 2011 Brandon Aaron (http://brandonaaron.net)
 * Licensed under the MIT License (LICENSE.txt).
 *
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 * Thanks to: Seamus Leahy for adding deltaX and deltaY
 *
 * Version: 3.0.6
 * 
 * Requires: 1.2.2+
 */
(function(a){function d(b){var c=b||window.event,d=[].slice.call(arguments,1),e=0,f=true,g=0,h=0;b=a.event.fix(c);b.type="mousewheel";if(c.wheelDelta){e=c.wheelDelta/120}if(c.detail){e=-c.detail/3}h=e;if(c.axis!==undefined&&c.axis===c.HORIZONTAL_AXIS){h=0;g=-1*e}if(c.wheelDeltaY!==undefined){h=c.wheelDeltaY/120}if(c.wheelDeltaX!==undefined){g=-1*c.wheelDeltaX/120}d.unshift(b,e,g,h);return(a.event.dispatch||a.event.handle).apply(this,d)}var b=["DOMMouseScroll","mousewheel"];if(a.event.fixHooks){for(var c=b.length;c;){a.event.fixHooks[b[--c]]=a.event.mouseHooks}}a.event.special.mousewheel={setup:function(){if(this.addEventListener){for(var a=b.length;a;){this.addEventListener(b[--a],d,false)}}else{this.onmousewheel=d}},teardown:function(){if(this.removeEventListener){for(var a=b.length;a;){this.removeEventListener(b[--a],d,false)}}else{this.onmousewheel=null}}};a.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery);

/*
 * jQuery hashchange event - v1.3 - 7/21/2010
 * http://benalman.com/projects/jquery-hashchange-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);

/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/
jQuery.easing.jswing=jQuery.easing.swing;jQuery.extend(jQuery.easing,{def:"easeOutQuad",swing:function(e,f,a,h,g){return jQuery.easing[jQuery.easing.def](e,f,a,h,g)},easeInQuad:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutQuad:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutQuad:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a},easeInCubic:function(e,f,a,h,g){return h*(f/=g)*f*f+a},easeOutCubic:function(e,f,a,h,g){return h*((f=f/g-1)*f*f+1)+a},easeInOutCubic:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f+a}return h/2*((f-=2)*f*f+2)+a},easeInQuart:function(e,f,a,h,g){return h*(f/=g)*f*f*f+a},easeOutQuart:function(e,f,a,h,g){return -h*((f=f/g-1)*f*f*f-1)+a},easeInOutQuart:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f+a}return -h/2*((f-=2)*f*f*f-2)+a},easeInQuint:function(e,f,a,h,g){return h*(f/=g)*f*f*f*f+a},easeOutQuint:function(e,f,a,h,g){return h*((f=f/g-1)*f*f*f*f+1)+a},easeInOutQuint:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f*f+a}return h/2*((f-=2)*f*f*f*f+2)+a},easeInSine:function(e,f,a,h,g){return -h*Math.cos(f/g*(Math.PI/2))+h+a},easeOutSine:function(e,f,a,h,g){return h*Math.sin(f/g*(Math.PI/2))+a},easeInOutSine:function(e,f,a,h,g){return -h/2*(Math.cos(Math.PI*f/g)-1)+a},easeInExpo:function(e,f,a,h,g){return(f==0)?a:h*Math.pow(2,10*(f/g-1))+a},easeOutExpo:function(e,f,a,h,g){return(f==g)?a+h:h*(-Math.pow(2,-10*f/g)+1)+a},easeInOutExpo:function(e,f,a,h,g){if(f==0){return a}if(f==g){return a+h}if((f/=g/2)<1){return h/2*Math.pow(2,10*(f-1))+a}return h/2*(-Math.pow(2,-10*--f)+2)+a},easeInCirc:function(e,f,a,h,g){return -h*(Math.sqrt(1-(f/=g)*f)-1)+a},easeOutCirc:function(e,f,a,h,g){return h*Math.sqrt(1-(f=f/g-1)*f)+a},easeInOutCirc:function(e,f,a,h,g){if((f/=g/2)<1){return -h/2*(Math.sqrt(1-f*f)-1)+a}return h/2*(Math.sqrt(1-(f-=2)*f)+1)+a},easeInElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k)==1){return e+l}if(!j){j=k*0.3}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}return -(g*Math.pow(2,10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j))+e},easeOutElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k)==1){return e+l}if(!j){j=k*0.3}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}return g*Math.pow(2,-10*h)*Math.sin((h*k-i)*(2*Math.PI)/j)+l+e},easeInOutElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k/2)==2){return e+l}if(!j){j=k*(0.3*1.5)}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}if(h<1){return -0.5*(g*Math.pow(2,10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j))+e}return g*Math.pow(2,-10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j)*0.5+l+e},easeInBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}return i*(f/=h)*f*((g+1)*f-g)+a},easeOutBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}return i*((f=f/h-1)*f*((g+1)*f+g)+1)+a},easeInOutBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}if((f/=h/2)<1){return i/2*(f*f*(((g*=(1.525))+1)*f-g))+a}return i/2*((f-=2)*f*(((g*=(1.525))+1)*f+g)+2)+a},easeInBounce:function(e,f,a,h,g){return h-jQuery.easing.easeOutBounce(e,g-f,0,h,g)+a},easeOutBounce:function(e,f,a,h,g){if((f/=g)<(1/2.75)){return h*(7.5625*f*f)+a}else{if(f<(2/2.75)){return h*(7.5625*(f-=(1.5/2.75))*f+0.75)+a}else{if(f<(2.5/2.75)){return h*(7.5625*(f-=(2.25/2.75))*f+0.9375)+a}else{return h*(7.5625*(f-=(2.625/2.75))*f+0.984375)+a}}}},easeInOutBounce:function(e,f,a,h,g){if(f<g/2){return jQuery.easing.easeInBounce(e,f*2,0,h,g)*0.5+a}return jQuery.easing.easeOutBounce(e,f*2-g,0,h,g)*0.5+h*0.5+a}});

;(function($,undefined){
	
	
	$.extend({
		//preloadImage
		preloadImage : function(arr){
			if(typeof(arr) == 'string'){
				var img = new Image();
				img.src = arr;
			}else
			if(typeof(arr) == 'object' && arr.length > 0){
				arr = $.unique(arr);
				var len = arr.length;
				for(var i = 0; i < len; i++){
					$.preloadImage(arr[i]);
				}
			}
		},	 
		
		uif : {
			setup : (function(){
				
				var setup = function(range){
					setup.rollover(range);
					setup.externalLink(range);
					setup.popup(range);
					setup.smoothScroll();
					setup.fixHeight();
					//setup.css3Utils();
					setup.formUtils();
				}
				
				//rollover	
				// switching image xxx_off.xxx -> xxx_on.xxx
				// if image name is bnr_xxxx or btn_xxx which don't has neme _off , _on
				// fade effect on mouse over.
				setup.rollover = function(range, option){
					if(range == undefined){
						option = range;
						range = 'body';
					}
					range = $(range);
					var config = {
						off : '_off.',
						on : '_on.',
						currentClass : 'current'
					}
					$.extend(config,option);
					
					var offRegExp = new RegExp(config.off);
					var onRegExp = new RegExp(config.on);
					
					var rollOverHandler_old = setup.rollover.rollOverHandler;
					var rollOutHandler_old = setup.rollover.rollOutHandler;
					setup.rollover.rollOverHandler = function(){
						var $t = $(this);
						if($t.hasClass(config.currentClass)) return;
						if ($t.attr("src").match(offRegExp)) $t.attr("src",$t.attr("src").replace(config.off, config.on));
					};
				
					setup.rollover.rollOutHandler = function(){
						var $t = $(this);
						if($t.hasClass(config.currentClass)) return;
						if ($t.attr("src").match(onRegExp)) $t.attr("src",$t.attr("src").replace(config.on, config.off));
					}
					
					
					$("a img[src*='_on']",range)
						.addClass(config.currentClass);
						
					$("a img,:image",range)
						.unbind("mouseover",rollOverHandler_old)
						.bind("mouseover",setup.rollover.rollOverHandler);
						
					$("a img,:image",range)
						.unbind("mouseout",rollOutHandler_old)
						.bind("mouseout",setup.rollover.rollOutHandler);
					
					
					//preload images
					var images = [];
					var img;
					$("a img,:image",range).each(function(index){
						if($(this).attr("src").match(offRegExp)){
							images[images.length] = $(this).attr("src").replace(config.off, config.on);
						}
					});
					
					$.preloadImage(images);
				}
				
				//externalLink
				//if has class .extenal -> open _blank window
				setup.externalLink = function(range, option){
					if(range==undefined){
						option = range;
						range = 'body';
					}
					range = $(range);
					var config = {
						className : 'external',
						ignoreURLs : []
					}
					$.extend(config,option);
					
					// target _blank auto add
					var domains = [document.domain];
					if(config.ignoreURLs.length){
						domains = domains.concat(config.ignoreURLs);
					}
					var selector = ""
					var ls= ":not([href^='http://";
					var lss= ":not([href^='https://";
					var rs = "'])";
					selector  = ls + domains.join(rs + ls) + rs;
					selector += lss + domains.join(rs + lss) +rs;
					$("a[href^='http']:not([class^='popup'])" + selector).addClass(config.className);
					$("area[href^='http']:not([class^='popup'])" + selector).addClass(config.className);
					
					
					$("a."+config.className, range)
						.unbind("click",setup.externalLink.windowOpen)
						.bind("click",setup.externalLink.windowOpen);
					$("area."+config.className, range)
						.unbind("click",setup.externalLink.windowOpen)
						.bind("click",setup.externalLink.windowOpen);
					
				}
				setup.externalLink.windowOpen = function(){
					window.open(this.href,"_blank");
					return false;
				}
				
				//popup
				// class="popup400x600" 
				//  -> window.open(this.href,"popup","width=400,height=600,...)
				//
				// open in popup parent window.
				// add class="openParentWin" on a-tag in a popup window.
				setup.popup = function(range){
					if(range==undefined){
						range = 'body';
					}
					range = $(range);
					$("a[class^='popup']", range)
						.unbind('click', setup.popup.popupOpen)
						.bind('click', setup.popup.popupOpen);
					
					$("a.openParentWin", range)
						.unbind('click', setup.popup.openParentWindow)
						.bind('click', setup.popup.openParentWindow);
				}
				
				setup.popup.popupOpen = function(){
					if($.browser.safari){
						window.open(this.href,"_blank");
						return false;
					}
					var className = $(this).attr("class").match(/popup([0-9]{1,})x([0-9]{1,})/) ;	
					var width = RegExp.$1;
					var height = RegExp.$2;
					var state = [];
					var notHasSize = "yes"
					if(width != null && height != null){
						state = [
							"width=" + width,
							"height=" + height
						];
						notHasSize = "no";
					}
					state = state.concat([
						"location=" + notHasSize,
						"toolbar=" + notHasSize,
						"directories=" + notHasSize,
						"status=yes",
						"menubar=no",
						"scrollbars=yes",
						"resizable=yes",
						"alwaysRaised=yes"
					]);
					
					window.name = document.domain + "_root";
					window.open(this.href,"popup"+(new Date()).getTime().toString(),state.join(','));
					
					return false;
				}
				setup.popup.openParentWindow = function(){
					window.open(this.href,document.domain + "_root");
					return false;
				}
				
				//smoothScroll
				setup.smoothScroll = function(){
					$(document)
						.off("click",'a[href^="#"]:not(.non_scroll)',setup.smoothScroll.clickHandler)
						.on("click",'a[href^="#"]:not(.non_scroll)',setup.smoothScroll.clickHandler);
				};
				setup.smoothScroll.clickHandler = function() { 
					if(window.marna.scroller == undefined || !window.marna.scroller.isSetuped){
						var target = $(this.hash); 
						if(target.size()) { 
							var top = target.offset().top;
							if($('body').hasClass('popup')){
								console.log(top)
								$("html, body")
									.animate({scrollTop:top}, setup.smoothScroll.speed);
							}else{
								$('#content')
									.animate({scrollTop:top}, setup.smoothScroll.speed);
							}
						} 
					}else{
						marna.scroller.anchor($(this).attr('href'));
					}
					return false; 
				}
				setup.smoothScroll.speed = 1000;
				
				
				setup.fixHeight = function(){
					$('.fix_height').each(function(){
						var mh = 0;
						$(this).children().each(function(){
							if(mh < $(this).height()){
								mh = $(this).height();
							}
						}).height(mh);
					});
				}
				
				setup.css3Utils = (function(){
					
					var css3Utils = function(){
						css3Utils.firstChild();
						css3Utils.lastChild();
						css3Utils.evan();
						css3Utils.odd();
					}
					
					css3Utils.firstChild = function(){
						
						css3Utils._set(":first-child","first-chlid");
					}
					
					css3Utils.lastChild = function(){
						css3Utils._set(":last-child","last-chlid");
					}
					
					css3Utils.nthChild = function(nth,className){
						css3Utils._set(":nth-chlid(" + nth + ")", className);
					}
					
					css3Utils.evan = function(){
						css3Utils._set(":even","even");
					}
					
					css3Utils.odd = function(){
						css3Utils._set(":odd","odd");
					}
					
					css3Utils._set = function(selecter,className){
						css3Utils._clear(className);
						
						$("ul > li" + selecter).addClass(className);
						$("ol > li" + selecter).addClass(className);
						$("dl > dt" + selecter).addClass(className);
						$("dl > dd" + selecter).addClass(className);
						$("tr > th" + selecter).addClass(className);
						$("tr > td" + selecter).addClass(className);
						$("table > tr" + selecter).addClass(className);
						$("thead > tr" + selecter).addClass(className);
						$("tbody > tr" + selecter).addClass(className);
						$("tfoot > tr" + selecter).addClass(className);
					},
					
					css3Utils._clear = function(className){
						$("."+className).removeClass(className);
					}
					
					return css3Utils;
				})()
				
				setup.formUtils = function(){
					$(document)
						.off({
								'focus' : setup.formUtils.focusHandler,
								'blur' : setup.formUtils.blurHandler,
								'mouseover' : setup.formUtils.mouseOverHandler,
								'mouseout' : setup.formUtils.mouseOutHandler
							}, "input,textarea,select")
						.on({
								'focus' : setup.formUtils.focusHandler,
								'blur' : setup.formUtils.blurHandler,
								'mouseover' : setup.formUtils.mouseOverHandler,
								'mouseout' : setup.formUtils.mouseOutHandler
							}, "input,textarea,select")
						
				}
				setup.formUtils.focusHandler = function(){$(this).addClass("focus")}
				setup.formUtils.blurHandler = function(){$(this).removeClass("focus")}
				setup.formUtils.mouseOverHandler = function(){$(this).addClass("hover")}
				setup.formUtils.mouseOutHandler = function(){$(this).removeClass("hover")}
				
				return setup;
			})()
		}
	})
	
	
	$.extend($.uif, {
		resize : {
			_isStarted : false,
			_callbacks : $.Callbacks('unique'),
			_timerID : 0,
			_bindFunc : null,
			_apply : function(){
				clearTimeout(this._timerID);
				this._timerID = setTimeout(this._callbacks.fire, 20);
			},
			
			add : function(callback){
				this._callbacks.add(callback);
				return this;
			},
			remove : function(callback){
				this._callbacks.remove(callback);
				return this;
			},
			
			start : function(){
				if(!this._isStarted){
					var scope = this;
					this._bindFunc = function(){scope._apply.call(scope);}
					$(window).bind('resize', this._bindFunc ).trigger('resize');
					this._isStarted = true;
				}
				return this;
			},
			
			stop : function(){
				if(!this._isStarted){
					$(window).unbind('resize', this._bindFunc);
					this._bindFunc = null;
					this._isStarted = false;
				}
				return this;
			}
		}
	})
	
	
})(jQuery);
		
		

