/*!
 * jQuery Smart Banner
 * Copyright (c) 2012 Arnold Daniels <arnold@jasny.net>
 * Based on 'jQuery Smart Web App Banner' by Kurt Zenisek @ kzeni.com
 */
!function(n){var t=function(t){var u,i,r;(this.origHtmlMargin=parseFloat(n("html").css("margin-top")),this.options=n.extend({},n.smartbanner.defaults,t),u=navigator.standalone,i=navigator.userAgent,this.options.force?this.type=this.options.force:i.match(/iPad|iPhone|iPod/i)!=null?i.match(/Safari/i)!=null&&(i.match(/CriOS/i)!=null||window.Number(navigator.userAgent.substr(navigator.userAgent.indexOf("OS ")+3,3).replace("_","."))<6)&&(this.type="ios"):this.type=i.match(/Android/i)!=null?"android":i.match(/Windows NT 6.2/i)!=null&&i.match(/Touch/i)!==null?"windows":Math.floor(Math.random()*100+1)%2==0?"android":"ios",!this.type||u||this.getCookie("sb-closed")||this.getCookie("sb-installed"))||(this.scale=this.options.scale=="auto"?n(window).width()/window.screen.width:this.options.scale,this.scale<1&&(this.scale=1),r=n(this.type=="android"?'meta[name="google-play-app"]':this.type=="ios"?'meta[name="apple-itunes-app"]':'meta[name="msApplication-ID"]'),r.length!=0)&&(this.type=="windows"?(this.pfn=n('meta[name="msApplication-PackageFamilyName"]').attr("content"),this.appId=r.attr("content")[1]):this.appId=/app-id=([^\s,]+)/.exec(r.attr("content"))[1],this.title=this.options.title?this.options.title:n("title").text().replace(/\s*[|\-·].*$/,""),this.author=this.options.author?this.options.author:n('meta[name="author"]').length?n('meta[name="author"]').attr("content"):window.location.hostname,this.create(),this.show(),this.listen())};t.prototype={constructor:t,create:function(){var t,r=this.options.url?this.options.url:(this.type=="windows"?"ms-windows-store:PDP?PFN="+this.pfn:this.type=="android"?"market://details?id=":"https://itunes.apple.com/"+this.options.appStoreLanguage+"/app/id")+this.appId,u=this.options.price?this.options.price+" - "+(this.type=="android"?this.options.inGooglePlay:this.type=="ios"?this.options.inAppStore:this.options.inWindowsStore):"",i=this.options.iconGloss===null?this.type=="ios":this.options.iconGloss;n("body").append('<div id="smartbanner" class="'+this.type+'"><div class="sb-container"><a href="#" class="sb-close">&times;<\/a><span class="sb-icon"><\/span><div class="sb-info"><strong>'+this.title+"<\/strong><span>"+this.author+"<\/span><span>"+u+'<\/span><\/div><a href="'+r+'" class="sb-button"><span>'+this.options.button+"<\/span><\/a><\/div><\/div>"),this.options.icon?t=this.options.icon:n('link[rel="apple-touch-icon-precomposed"]').length>0?(t=n('link[rel="apple-touch-icon-precomposed"]').attr("href"),this.options.iconGloss===null&&(i=!1)):n('link[rel="apple-touch-icon"]').length>0?t=n('link[rel="apple-touch-icon"]').attr("href"):n('meta[name="msApplication-TileImage"]').length>0?t=n('meta[name="msApplication-TileImage"]').attr("content"):n('meta[name="msapplication-TileImage"]').length>0&&(t=n('meta[name="msapplication-TileImage"]').attr("content")),t?(n("#smartbanner .sb-icon").css("background-image","url("+t+")"),i&&n("#smartbanner .sb-icon").addClass("gloss")):n("#smartbanner").addClass("no-icon"),this.bannerHeight=n("#smartbanner").outerHeight()+2,this.scale>1&&(n("#smartbanner").css("top",parseFloat(n("#smartbanner").css("top"))*this.scale).css("height",parseFloat(n("#smartbanner").css("height"))*this.scale),n("#smartbanner .sb-container").css("-webkit-transform","scale("+this.scale+")").css("-msie-transform","scale("+this.scale+")").css("-moz-transform","scale("+this.scale+")").css("width",n(window).width()/this.scale))},listen:function(){n("#smartbanner .sb-close").on("click",n.proxy(this.close,this));n("#smartbanner .sb-button").on("click",n.proxy(this.install,this))},show:function(t){n("#smartbanner").stop().animate({top:0},this.options.speedIn).addClass("shown"),n("html").animate({marginTop:this.origHtmlMargin+this.bannerHeight*this.scale},this.options.speedIn,"swing",t)},hide:function(t){n("#smartbanner").stop().animate({top:-1*this.bannerHeight*this.scale},this.options.speedOut).removeClass("shown"),n("html").animate({marginTop:this.origHtmlMargin},this.options.speedOut,"swing",t)},close:function(n){n.preventDefault(),this.hide(),this.setCookie("sb-closed","true",this.options.daysHidden)},install:function(){this.hide(),this.setCookie("sb-installed","true",this.options.daysReminder)},setCookie:function(n,t,i){var r=new Date;r.setDate(r.getDate()+i),t=escape(t)+(i==null?"":"; expires="+r.toUTCString()),document.cookie=n+"="+t+"; path=/;"},getCookie:function(n){for(var r,u,i=document.cookie.split(";"),t=0;t<i.length;t++)if(r=i[t].substr(0,i[t].indexOf("=")),u=i[t].substr(i[t].indexOf("=")+1),r=r.replace(/^\s+|\s+$/g,""),r==n)return unescape(u);return null},switchType:function(){var t=this;this.hide(function(){t.type=t.type=="android"?"ios":"android";var i=n(t.type=="android"?'meta[name="google-play-app"]':'meta[name="apple-itunes-app"]').attr("content");t.appId=/app-id=([^\s,]+)/.exec(i)[1],n("#smartbanner").detach(),t.create(),t.show()})}},n.smartbanner=function(i){var u=n(window),r=u.data("typeahead"),f=typeof i=="object"&&i;r||u.data("typeahead",r=new t(f)),typeof i=="string"&&r[i]()},n.smartbanner.defaults={title:null,author:null,price:"FREE",appStoreLanguage:"us",inAppStore:"On the App Store",inGooglePlay:"In Google Play",inWindowsStore:"In the Windows Store",icon:null,iconGloss:null,button:"VIEW",url:null,scale:"auto",speedIn:300,speedOut:400,daysHidden:15,daysReminder:90,force:null},n.smartbanner.Constructor=t}(window.jQuery)