/*
 * Marquee jQuery Plug-in
 *
 * Copyright 2009 Giva, Inc. (http://www.givainc.com/labs/) 
 * 
 * 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.
 *
 * Date: 2009-05-20
 * Rev:  1.0.01
 */
(function(a){a.marquee={version:"1.0.01"};a.fn.marquee=function(d){var e=typeof arguments[0]=="string"&&arguments[0];var f=e&&Array.prototype.slice.call(arguments,1)||arguments;var b=(this.length==0)?null:a.data(this[0],"marquee");if(b&&e&&this.length){if(e.toLowerCase()=="object"){return b}else{if(b[e]){var c;this.each(function(g){var h=a.data(this,"marquee")[e].apply(b,f);if(g==0&&h){if(!!h.jquery){c=a([]).add(h)}else{c=h;return false}}else{if(!!h&&!!h.jquery){c=c.add(h)}}});return c||this}else{return this}}}else{return this.each(function(){new a.Marquee(this,d)})}};a.Marquee=function(i,k){k=a.extend({},a.Marquee.defaults,k);var n=this,l=a(i),q=l.find("> li"),e=-1,p=false,b=false,m=0;a.data(l[0],"marquee",n);this.pause=function(){p=true;c()};this.resume=function(){p=false;f()};this.update=function(){var r=q.length;q=l.find("> li");if(r<=1){f()}};function j(r){if(q.filter("."+k.cssShowing).length>0){return false}var t=q.eq(r);if(a.isFunction(k.beforeshow)){k.beforeshow.apply(n,[l,t])}var s={top:(k.yScroll=="top"?"-":"+")+t.outerHeight()+"px",left:0};l.data("marquee.showing",true);t.addClass(k.cssShowing);t.css(s).animate({top:"0px"},k.showSpeed,k.fxEasingShow,function(){if(a.isFunction(k.show)){k.show.apply(n,[l,t])}l.data("marquee.showing",false);d(t)})}function d(s,r){if(b==true){return false}r=r||k.pauseSpeed;if(h(s)){setTimeout(function(){if(b==true){return false}var v=s.outerWidth(),t=v*-1,u=parseInt(s.css("left"),10);s.animate({left:t+"px"},((v+u)*k.scrollSpeed),k.fxEasingScroll,function(){o(s)})},r)}else{if(q.length>1){setTimeout(function(){if(b==true){return false}s.animate({top:(k.yScroll=="top"?"+":"-")+l.innerHeight()+"px"},k.showSpeed,k.fxEasingScroll);o(s)},r)}}}function o(r){if(a.isFunction(k.aftershow)){k.aftershow.apply(n,[l,r])}r.removeClass(k.cssShowing);g()}function c(){b=true;if(l.data("marquee.showing")!=true){q.filter("."+k.cssShowing).dequeue().stop()}}function f(){b=false;if(l.data("marquee.showing")!=true){d(q.filter("."+k.cssShowing),1)}}if(k.pauseOnHover){l.hover(function(){if(p){return false}c()},function(){if(p){return false}f()})}function h(r){return(r.outerWidth()>l.innerWidth())}function g(){e++;if(e>=q.length){if(!isNaN(k.loop)&&k.loop>0&&(++m>=k.loop)){return false}e=0}j(e)}if(a.isFunction(k.init)){k.init.apply(n,[l,k])}g()};a.Marquee.defaults={yScroll:"top",showSpeed:850,scrollSpeed:12,pauseSpeed:10000,pauseOnHover:false,loop:-1,fxEasingShow:"swing",fxEasingScroll:"linear",cssShowing:"marquee-showing",init:null,beforeshow:null,show:null,aftershow:null}})(jQuery);