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