/* ========================================================== * mobilyselect * date: 18.1.2010 * author: marcin dziewulski * last update: 25.1.2010 * web: http://www.mobily.pl or http://playground.mobily.pl * email: hello@mobily.pl * free to use under the mit license. * ========================================================== */ (function($){$.fn.mobilyselect=function(options){var defaults={collection:"all",animation:"absolute",duration:500,listclass:"selectercontent",btnsclass:"selecterbtns",btnactiveclass:"active",elements:"li",onchange:function(){},oncomplete:function(){}};var sets=$.extend({},defaults,options);return this.each(function(){var $t=$(this),list=$t.find("."+sets.listclass),btns=$t.find("."+sets.btnsclass),btn=btns.find("a"),li=list.find(sets.elements),w=li.width(),h=li.height(),l=li.length,finishtime;if(sets.animation=="absolute"){li.css({position:"relative"}).children().css({position:"absolute",top:0,left:0})}var select={init:function(){this.start();this.trigger()},start:function(){if(sets.collection!="all"){li.hide().filter("."+sets.collection).show();btn.removeclass(sets.btnactiveclass).filter(function(){return $(this).attr("rel")==sets.collection}).addclass(sets.btnactiveclass)}},trigger:function(){btn.bind("click",function(){var $t=$(this),rel=$t.attr("rel"),selected=li.filter("."+rel),s=li.filter(function(){return $(this).css("display")=="block"});if(rel=="all"){if(l!=s.length){select.animation(li,li)}}else{select.animation(li,selected)}btn.removeclass(sets.btnactiveclass);$t.addclass(sets.btnactiveclass);sets.onchange.call(this);return false})},animation:function(not,selected){switch(sets.animation){case"plain":$(not).hide();$(selected).show();break;case"fade":$(not).fadeout(sets.duration);settimeout(function(){$(selected).fadein(sets.duration)},sets.duration+400);break;case"absolute":settimeout(function(){$(selected).show().children().animate({top:0,left:0},sets.duration)},sets.duration+400);$(not).children().animate({top:-h+"px",left:-w+"px"},sets.duration,function(){$(not).hide()});break}if(sets.animation=="absolute"||sets.animation=="fade"){finishtime=sets.duration*2+400}else{finishtime=100}settimeout(function(){sets.oncomplete.call(this)},finishtime)}};select.init()})}}(jquery));