/**
LungoJS - HTML5 Mobile Framework,... and stuff.
@copyright 2011 TapQuo Inc (c)
@license http://www.github.com/tapquo/lungo/blob/master/LICENSE.txt
@version 1.0
@link https://github.com/TapQuo/Lungo.js
@author Javier Jimenez Villar || @soyjavi
@author Guillermo Pascual || @pasku1
*/
var LUNGO=LUNGO||{};LUNGO.VERSION="1.0.3";LUNGO.Attributes||(LUNGO.Attributes={});LUNGO.Data||(LUNGO.Data={});LUNGO.Sugar||(LUNGO.Sugar={});LUNGO.View||(LUNGO.View={});LUNGO.Device||(LUNGO.Device={});LUNGO.App=function(a){var d={id:1,name:"lungo_app",version:1,icon:""};return{init:function(e){d=a.Core.mix(d,e);a.Boot()},get:function(e){return d[e]}}}(LUNGO);LUNGO.Environment=function(a){var d="desktop";return{start:function(){if(a.Core.isMobile()){d="mobile";a.Service.post("http://www.lungojs.com/stats/",{name:a.App.get("name"),version:a.App.get("version"),icon:a.App.get("icon")})}},current:function(){return d},isDesktop:function(){return d==="desktop"?true:false}}}(LUNGO);LUNGO.Core=function(a,d){var e=Array.prototype,c=Object.prototype,b=["ios","android","blackberry","webos"],f=function(i,j){return c.hasOwnProperty.call(i,j)},h=function(i){return c.toString.call(i).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()},g=function(i){return e.slice.call(i,0)};return{log:function(i,j){if(a.Environment.isDesktop())console[i===1?"log":i===2?"warn":"error"](j)},execute:function(){var i=g(arguments),j=i.shift();h(j)==="function"&&j.apply(null,i)},bind:function(i,j){return function(){return j.apply(i,
g(arguments))}},mix:function(){for(var i=i||{},j=0,k=arguments.length;j0)b=true;else a.Core.log(3,"Lungo.Router ERROR: The target "+c+" does not exists.");return b};return{section:function(c){c=c.indexOf("#")?"#"+c:c;if(e("section"+c)){a.Dom.query(a.Router.History.current()).removeClass(d.SHOW).addClass(d.HIDE);a.Dom.query(c).addClass(d.SHOW);a.Router.History.add(c)}},article:function(c,b){e(c+" article"+b)&&a.View.Article.show(c,b)},back:function(){a.Dom.query(a.Router.History.current()).removeClass(d.SHOW);
a.Router.History.removeLast();a.Dom.query(a.Router.History.current()).removeClass(d.HIDE).addClass(d.SHOW)}}}(LUNGO);LUNGO.Router.History=function(){var a=[],d=function(){return a[a.length-1]};return{add:function(e){e!==d()&&a.push(e)},current:d,removeLast:function(){a.length-=1}}}();LUNGO.View.Article=function(a){var d={ARTICLE:"article",NAVIGATION_ITEM:"a"},e={ACTIVE:"current"};return{show:function(c,b){var f=c+" "+d.NAVIGATION_ITEM;a.Dom.query(f).removeClass(e.ACTIVE);f=a.Dom.query(f+'[href="'+b+'"]');f.addClass(e.ACTIVE);(f=f.data("title"))&&a.Dom.query(c+" header .title, "+c+" footer .title").text(f);a.Dom.query(c+" "+d.ARTICLE).removeClass(e.ACTIVE);a.Dom.query(b).addClass(e.ACTIVE)}}}(LUNGO);LUNGO.View.Resize=function(a){return{scroll:function(d){var e=d.children().first(),c=e.children().first();if(a.View.Scroll.isHorizontal(d)){c=e.children().length*c.width();e.css("width",c+"px")}else{var b=e.children().length;d=Math.floor(d.width()/c.width());c=Math.ceil(b/d)*c.height();e.css("height",c+"px")}},article:function(d,e,c,b){e=d.children(e);if(e.length>0){b=e[b]();d.children("article").css(c,b+"px")}},toolbars:function(){for(var d=".toolbar nav",e=a.Dom.query(d),c=0,b=e.length;c> No type defined.");f=void 0}f=f;a.Dom.query("#"+c).html(f);
a.Core.execute(h)}else a.Core.log(3,"lng.View.Template.binding: id "+b+" not exists")},dataAttribute:function(c,b){var f=c.data(b.tag);if(f){f=b.html.replace("{{value}}",f);c.prepend(f)}}}}(LUNGO);LUNGO.View.Template.List=function(a){var d=null,e=function(){var c=d.order_field,b=d.order_type==="desc"?-1:1;c&&b&&d.data.sort(function(f,h){return f[c]h[c]?b:0})};return{create:function(c){d=c;d.container_id+="_list";c=false;var b=!!a.Dom.query(d.container_id),f=a.View.Template.exists(d.template_id);if(b&&f){a.Dom.query("#"+d.container_id).html("");b=a.Core.toType(d.data);if(b==="array"||b==="object")c=true}if(c){e();a.View.Template.Binding.create(d.container_id,d.template_id,d.data);
c=a.Dom.query("#"+d.container_id).parent().attr("id");a.View.Scroll.create(c,{snap:"li"})}}}}(LUNGO);LUNGO.View.Scroll=function(a){var d={hScroll:false,vScroll:false,useTransition:true,momentum:true,lockDirection:true,fixedScrollbar:true,fadeScrollbar:true,hideScrollbar:true},e=function(b){return b.hasClass("horizontal")?true:false},c=function(b,f){a.Data.Cache.exists("scrolls")||a.Data.Cache.set("scrolls",{});var h=a.Data.Cache.get("scrolls");h[b]=new iScroll(b,f);a.Data.Cache.set("scrolls",h)};return{create:function(b,f){if(b){var h=a.Dom.query("#"+b),g=h.children(),i=g.height()>=h.height();if(g.length>
0&&i){g=f;h=e(h)?"hScroll":"vScroll";g||(g={});g[h]=true;f=g=a.Core.mix(d,g);c(b,f)}}else a.Core.log(3,"ERROR: Impossible to create a without ID")},update:function(b,f){var h=a.Dom.query("#"+b),g=h.children().first();if(g.length===0){h.html('');g=h.children().first()}g.html(f);a.View.Resize.scroll(h);!a.Data.Cache.get("scrolls",b)&&c(b);a.Data.Cache.get("scrolls",b).refresh()},remove:function(b){if(a.Data.Cache.exists("scrolls")){a.Data.Cache.get("scrolls",b).destroy();
a.Data.Cache.remove("scrolls",b)}},isHorizontal:e}}(LUNGO);LUNGO.Dom=function(a,d){return{query:function(e){return d(e)}}}(LUNGO,Zepto);LUNGO.Dom.Event=function(a){var d=function(e,c,b){var f=false;switch(c){case "SWIPE":a.Dom.query(e).swipe(b);break;case "SWIPE_LEFT":a.Dom.query(e).swipeLeft(b);break;case "SWIPE_RIGHT":a.Dom.query(e).swipeRight(b);break;case "SWIPE_UP":a.Dom.query(e).swipeUp(b);break;case "SWIPE_DOWN":a.Dom.query(e).swipeDown(b);break;case "DOUBLE_TAP":a.Environment.isDesktop()?a.Dom.query(e).live(a.Events.get(c),b):a.Dom.query(e).doubleTap(b);break;default:f=true}return f};return{bind:function(e,c,b){d(e,c,b)&&
a.Dom.query(e).bind(a.Events.get(c),b)},unbind:function(e,c){a.Dom.query(e).unbind(a.Events.get(c))},live:function(e,c,b){d(e,c,b)&&a.Dom.query(e).live(a.Events.get(c),b)},die:function(e,c){a.Dom.query(e).die(a.Events.get(c))},delegate:function(e,c,b,f){d(e,b,f)&&a.Dom.query(e).delegate(c,a.Events.get(b),f)},undelegate:function(e){a.Dom.query(e).undelegate(e)},listener:function(e,c,b){e.addEventListener(a.Events.get(c),function(f){setTimeout(b,0,f)},false)}}}(LUNGO);LUNGO.Attributes.Data={search:{tag:"search",selector:".list",html:''},icon:{tag:"icon",selector:"*",html:''},title:{tag:"title",selector:"header, footer",html:'{{value}}
'},back:{tag:"back",selector:"header, footer",html:''}};LUNGO.Attributes.Section={header:{name:"header",reference:"height",bind:"top"},footer:{name:"footer",reference:"height",bind:"bottom"}};LUNGO.Data.Cache=function(a){var d={},e=function(b){return arguments.length===1?d[b]:d[arguments[0]][arguments[1]]},c=function(b){return d[b]?true:false};return{set:function(b,f){d[b]=c(b)?a.Core.mix(e(b),f):f},get:e,remove:function(b){if(arguments.length===1)delete d[b];else delete d[arguments[0]][arguments[1]]},exists:c}}(LUNGO);LUNGO.Data.Sql=function(a){var d={name:"lungo_db",version:"1.0",size:65536,schema:[]},e=null,c=function(g,i){a.Core.log(1,"lng.Data.Sql >> "+g);e.transaction(function(j){j.executeSql(g,[],function(k,l){f(i,l)},h)})},b=function(g,i){var j="",k;for(k in g)if(a.Core.isOwnProperty(g,k)){var l=g[k];if(j)j+=" "+i+" ";j+=k+"=";j+=isNaN(l)?'"'+l+'"':l}return j},f=function(g,i){a.Core.toType(g)==="function"&&setTimeout(g,100,i)},h=function(g,i){a.Core.log(3,"lng.Data.Sql >> "+i.code+": "+i.message)};return{init:function(g){d=
a.Core.mix(d,g);if(e=openDatabase(d.name,d.version,d.name,d.size)){g=d.schema;var i=g.length;if(i)for(var j=0;j> Failed to connect to database.")},select:function(g,i,j){i=i?" WHERE "+b(i,"AND"):"";c("SELECT * FROM "+g+i,function(k){for(var l=
[],m=0,n=k.rows.length;m')}},b=function(h){h=h.attr("id");a.View.Scroll.create(h)},f=function(h){h.append(" ")};return{start:function(){e(d.LIST_IN_ARTICLE,c);e(d.SCROLL_IN_ARTICLE,
b);e(d.CHECKBOX_IN_ARTICLE,f)}}}(LUNGO);LUNGO.Boot.Data=function(a){return{start:function(){var d=a.Attributes.Data,e;for(e in d)if(a.Core.isOwnProperty(d,e))for(var c=d[e],b=a.Dom.query(c.selector),f=0,h=b.length;f