﻿/* ==================================================

 * jQuery.pursuit.js
 *
 * Copyright (c) Global design,Inc. All rights reserved.
 * http://www.glode.co.jp/ 
 * Version: 1.0.0
 * Last Modified: 2009/4/18
 * Library&Plugin: jQuery 1.3.2, jquery.easing.1.3, jquery.cookie
 
================================================== */

;(function($){var NameSpace='pursuit';$[NameSpace]=function(target,c){$(target).css({position:'relative'});var fixedBoxId=(c.fixedBoxId)?('#'+c.fixedBoxId):$(target).parent();var ani=function(target,iTop){$(target).dequeue();var pageScroll=$(document).scrollTop();var parentTop=$(fixedBoxId).offset().top;var parentHeight=$(fixedBoxId).height();var objTop=$(target).offset().top;var objHeight=target.offsetHeight;var fixedTopValue=Math.min((Math.max((parentTop+iTop),(pageScroll+c.offset))-parentTop),(parentHeight-objHeight));if(!$.cookie(c.cookieName)){$(target).animate({top:fixedTopValue},c.speed,c.easing)}};var top=$(target).css('top');var topParam=(top=='auto')?0:parseInt(top);var switchSouce,changeSouce,topPosition,cookie;var pursuitSwiitch=function(){if($.cookie(c.cookieName)){switchSouce=c.offSouce;changeSouce=c.onSouce;topPosition=0;cookie=null}else{switchSouce=c.onSouce;changeSouce=c.offSouce;topPosition=topParam;cookie=true}};pursuitSwiitch();$(c.offSwitch).each(function(){$(this).html(switchSouce).bind('click',function(){$(this).html(changeSouce);$(target).animate({top:topPosition},c.speed,c.easing);$.cookie(c.cookieName,cookie,{expires:365,path:'/'});pursuitSwiitch()})});$(window).scroll(function(){ani(target,topParam)});$(function(){ani(target,topParam)})};$.fn[NameSpace]=function(options){var config=$.extend({offset:0,speed:500,easing:'easeOutBack',fixedBoxId:this.parent().attr('id'),offSwitch:'#tmp_scroll_switch',onSouce:'ページスクロールをoff',offSouce:'ページスクロールをon',cookieName:NameSpace},options);this.each(function(){new $[NameSpace](this,config)});return this}})(jQuery);
