function init_one_page_application(){window.ParseURL=Backbone.Router.extend({routes:{"*actions":"parseURL"},grab_view:function(){first_view=false;view_el.html("<img src='_public/img/loader.gif'/>Loading...");munstro.import_view({view:current_controller+"/"+current_view,callback:function(view,has_js){if(view){view_el.unbind();view_el.html(view);view_el.slideDown("slow",function(){if(has_js){eval("window._"+current_controller+"_"+current_view+" = new window."+current_controller+"_"+current_view)}})}else{self.location="#"}}})},parseURL:function(actions){var _this=this;var params=actions.split("/");current_controller=params[0]?params[0]:"index";current_view=params[1]?params[1]:"index";if(!first_view){view_el.slideUp("slow",function(){_this.grab_view()})}else{if(!(current_controller=="index"&&current_view=="index")){_this.grab_view()}else{first_view=false;munstro.import_view({view:"index",callback:function(view,has_js){if(has_js){eval("window._"+current_controller+"_"+current_view+" = new window."+current_controller+"_"+current_view)}}})}}}});window.ParseURL=new window.ParseURL;Backbone.history.start()}var view_el=$(".view");var current_controller="index";var current_view="index";var first_view=true;window.munsieMVC=Backbone.Model.extend({defaults:{base_url:$("base").attr("href")},flash_message:function(a,b){if($("#flash").attr("id")){$("#flash").html(a)}else{$("body").append('<div id="flash">'+a+"</div>")}$("#flash").delay(1e3).slideDown("fast").delay(5e3).slideUp("fast")},import_scripts:function(a,b){var c=this;if(a==null){return false}for(x in a){if(a[x].toString().indexOf("http://")<0){a[x]=this.defaults.base_url+a[x]}if(this.check_script_loaded(a[x])){a.splice(x,1)}}a=a.reverse();require(a,function(){b.apply(this)})},init_view:function(controller,view){eval("window._"+controller+"_"+view+" = new window."+controller+"_"+view)},init_current_view:function(){eval("window._"+current_controller+"_"+current_view+" = new window."+current_controller+"_"+current_view)},remove_script_loaded:function(a){$("script").each(function(){if($(this).attr("src")!=null){if($(this).attr("src").search(a)>-1){$(this).remove();return false}}})},check_script_loaded:function(a){var b=false;$("script").each(function(){if($(this).attr("src")!=null){if($(this).attr("src").toString().indexOf(a)>-1){b=true;return false}}});return b},check_css_loaded:function(a){var b=false;$("link[rel='stylesheet']").each(function(){if($(this).attr("href")!=null){if($(this).attr("href").toString().indexOf(a)>-1){b=true;return false}}});return b},load_css:function(a,b){var c=this;var d;if(a.length>0){$.each(a,function(a,e){if(!c.check_css_loaded(e)){d=document.createElement("link");d.setAttribute("rel","stylesheet");d.setAttribute("type","text/css");d.setAttribute("href",e);if(b){d.setAttribute("data-for",b)}document.getElementsByTagName("head")[0].appendChild(d)}})}},import_view:function(a){var b=this;var c=new Array;var d=new Array;var e=new Array;var f=new Array;var g="";var h=false;if(!a["data"]){a["data"]=false}if(!a["method"]){a["method"]="GET"}if(!a["callback"]){a["callback"]=false}if(!a["js"]){a["js"]=false}if(a["models"]){d=$.merge(d,a["models"])}if(a["templates"]){e=$.merge(e,a["templates"])}if(a["vendors"]){f=$.merge(f,a["vendors"])}__load_view=function(){if(a["view"]){$.ajax({type:a["method"],url:a["view"],data:a["data"],success:function(a){if(a["view"]==false){}g=a["view"];if(a["models"]){d=$.merge(d,a["models"])}if(a["templates"]){e=$.merge(e,a["templates"])}if(a["vendors"]){f=$.merge(f,a["vendors"])}if(a["js"]){c.push(a["js"])}__load_vendors()}})}else{__load_vendors()}};__load_vendors=function(){if(f.length>0){b.load_vendors(f,function(){__load_templates()})}else{__load_templates()}};__load_templates=function(){if(e.length>0){b.load_templates(e,function(){__loadmodels()})}else{__loadmodels()}};__loadmodels=function(){if(d.length>0){for(x in d){d[x]="_public/js/models/"+d[x]+".js"}}require(d,function(){__loadjs()})};__loadjs=function(){if(c.length>0){require(c,function(){__callback()})}else{__callback()}};__callback=function(){if(a["callback"]){if(c.length>0){h=true}else{h=false}a["callback"].call(this,g,h)}};__load_view()},check_template_loaded:function(a){var b=false;$("script[type='text/x-jquery-tmpl']").each(function(){if($(this).attr("data")!=null){if($(this).attr("data").toString().indexOf(a)>-1){b=true;return false}}});return b},load_templates:function(a,b){var c=this;$.ajax({url:"index?munsieMVC_jqtemplate="+a[0],success:function(d){if(d["view"]){if(!c.check_template_loaded(a[0])){$("head").append('<script type="text/x-jquery-tmpl" data="'+a[0]+'">'+d["view"]+"</script>")}}else{console.error("Template: "+a[0]+" does not exist")}a=a.slice(1);if(a.length==0){if(b){b.apply(this)}}else{c.load_templates(a,b)}}})},apply_template:function(a,b){var c;if(!a["data"]){a["data"]=false}if(!this.check_template_loaded(a["template"])){this.load_templates([a["template"]],function(){c=$.tmpl($("script[data='"+a["template"]+"']").html(),a["data"]);a["el"].html(c);if(b){b.apply(this)}})}else{c=$.tmpl($("script[data='"+a["template"]+"']").html(),a["data"]);a["el"].html(c);if(b){b.apply(this)}}},load_vendors:function(a,b){var c=this;var d;if(a.length==0){b.apply(this)}else{d=a[0];switch(d){case"waypoints":this.import_scripts["vendors/js/waypoints/waypoints.min.js"],function(){a.splice(0,1);c.load_vendors(a,b)};break;case"nivoslider":this.load_css(["vendors/js/nivoslider/style.css"]);this.import_scripts(["vendors/js/nivoslider/jquery.nivo.slider.js"],function(){a.splice(0,1);c.load_vendors(a,b)});break;case"fancybox":this.load_css(["vendors/js/fancybox/jquery.fancybox-1.3.4.css"]);this.import_scripts(["vendors/js/fancybox/jquery.fancybox-1.3.4.pack.js"],function(){a.splice(0,1);c.load_vendors(a,b)});break;case"jqueryui":this.import_scripts(["vendors/js/jquery_ui/jquery-ui-1.8.14.custom.min.js"],function(){a.splice(0,1);c.load_vendors(a,b)});break;case"formvalidation":this.import_scripts(["vendors/js/form-validation/jquery.js"],function(){a.splice(0,1);c.load_vendors(a,b)});break;case"placeholder":this.import_scripts(["vendors/js/placeholder/placeholder.js"],function(){a.splice(0,1);c.load_vendors(a,b)});break;case"supersized":this.import_scripts(["vendors/js/supersized/js/supersized.3.2.4.min.js"],function(){a.splice(0,1);c.load_vendors(a,b)});break;case"jqcycle":this.import_scripts(["vendors/js/jqcycle/jquery.cycle.all.min.js"],function(){a.splice(0,1);c.load_vendors(a,b)});break;case"paginate":this.load_css(["vendors/js/paginate/css/style.css"]);this.import_scripts(["vendors/js/paginate/jquery.paginate.js"],function(){a.splice(0,1);c.load_vendors(a,b)});break;case"spritely":this.import_scripts(["vendors/js/spritely/spritely.js"],function(){a.splice(0,1);c.load_vendors(a,b)});break;case"twitterfeed":this.import_scripts(["vendors/js/twitterfeed/twitterfeed.js"],function(){a.splice(0,1);c.load_vendors(a,b)});break;case"rollbox":this.import_scripts(["vendors/js/rollbox/rollbox.js"],function(){a.splice(0,1);c.load_vendors(a,b)});break;case"easing":this.import_scripts(["vendors/js/easing.js"],function(){a.splice(0,1);c.load_vendors(a,b)});break;case"rotate":this.import_scripts(["vendors/js/rotate.js"],function(){a.splice(0,1);c.load_vendors(a,b)});break;case"backgroundposition":this.import_scripts(["vendors/js/backgroundposition.js"],function(){a.splice(0,1);c.load_vendors(a,b)});break;case"scrollbar":this.import_scripts(["vendors/js/scrollbar.js"],function(){a.splice(0,1);c.load_vendors(a,b)});break}}},request_url_var:function(a){var b=[],c;var d=window.location.href.slice(window.location.href.indexOf("?")+1).split("&");for(var e=0;e<d.length;e++){c=d[e].split("=");b.push(c[0]);b[c[0]]=c[1]}return b[a]}});var munstro=new window.munsieMVC;$("#flash").delay(1e3).slideDown("fast").delay(5e3).slideUp("fast")
