/**
*
* 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.2
* @link https://github.com/TapQuo/Lungo.js
*
* @author Javier Jimenez Villar || @soyjavi
* @author Guillermo Pascual || @pasku1
*/
var LUNGO=LUNGO||{};LUNGO.VERSION="1.0.1";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(h,j){return c.hasOwnProperty.call(h,j)},i=function(h){return c.toString.call(h).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()},g=function(h){return e.slice.call(h,0)};return{log:function(h,j){if(a.Environment.isDesktop())console[h===1?"log":h===2?"warn":"error"](j)},execute:function(){var h=g(arguments),j=h.shift();i(j)==="function"&&j.apply(null,h)},bind:function(h,j){return function(){return j.apply(h,
g(arguments))}},mix:function(){for(var h=h||{},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:"nav 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){(e=d.children(e))&&d.children("article").css(c,e.height()+"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(i)}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,i){return f[c]i[c]?b:0})};return{create:function(c){d=c;d.container_id+="_list";c=false;if(a.Dom.query(d.container_id)){a.Dom.query("#"+d.container_id).html("");if(a.View.Template.exists(d.template_id)&&d.data.length)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 i=a.Data.Cache.get("scrolls");i[b]=new iScroll(b,f);a.Data.Cache.set("scrolls",i)};return{create:function(b,f){if(b){var i=a.Dom.query("#"+b),g=i.children(),h=g.height()>=i.height();if(g.length>
0&&h){g=f;i=e(i)?"hScroll":"vScroll";g||(g={});g[i]=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 i=a.Dom.query("#"+b),g=i.children().first();if(g.length===0){i.html('');g=i.children().first()}g.html(f);a.View.Resize.scroll(i);!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",bind:"top"},footer:{name:"footer",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,h){a.Core.log(1,"lng.Data.Sql >> "+g);e.transaction(function(j){j.executeSql(g,[],function(k,l){f(h,l)},i)})},b=function(g,h){var j="",k;for(k in g)if(a.Core.isOwnProperty(g,k)){var l=g[k];if(j)j+=" "+h+" ";j+=k+"=";j+=isNaN(l)?'"'+l+'"':l}return j},f=function(g,h){a.Core.toType(g)==="function"&&setTimeout(g,100,h)},i=function(g,h){a.Core.log(3,"lng.Data.Sql >> "+h.code+": "+h.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 h=g.length;if(h)for(var j=0;j> Failed to connect to database.")},select:function(g,h,j){h=h?" WHERE "+b(h,"AND"):"";c("SELECT * FROM "+g+h,function(k){for(var l=
[],m=0,n=k.rows.length;m')}},b=function(i){i=i.attr("id");a.View.Scroll.create(i)},f=function(i){i.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,i=b.length;f