﻿jQuery.cookie=function(a,f,c){
    if(typeof f!="undefined"){
        c=c||{};
        if(f===null){
            f="";
            c.expires=-1
        }
        
        var d="";
        
        if(c.expires&&(typeof c.expires=="number"||c.expires.toUTCString)){
            if(typeof c.expires=="number"){
                d=new Date;
                d.setTime(d.getTime()+60*60*24*7)
            } else d=c.expires;d="; expires="+d.toUTCString()
        }

        var g=c.path?"; path="+c.path:"",h=c.domain?"; domain="+c.domain:"";
        c=c.secure?"; secure":"";
        document.cookie=[a,"=",encodeURIComponent(f),d,g,h,c].join("")
    } else{
        f=null;
        if(document.cookie&&document.cookie!= ""){
            c=document.cookie.split(";");
            for(d=0;d<c.length;d++){
                g=jQuery.trim(c[d]);
                    if(g.substring(0,a.length+1)==a+"="){
                        f=decodeURIComponent(g.substring(a.length+1));
                        break
                    }
            }
        }
        return f
    }
}; 


(function(a){
    a(document).ready(function(){
        function f(){
            k=0;k=Math.round(k);m=k-l;m*=-1
        }
        function g(){
            switch(window.orientation){
                case 0:l=320;j=50;i=100;break;
                case -90:l=480;j=100;i=200;break;
                case 90:l=480;j=100;i=200;break;
                case 180:l=320;j=50;i=100;break;
            } f();
        }
        
        function h(b){
            if(b.type=="touchstart"){
                n=false;
                b.preventDefault();
                touching=true;
                if(b.touches.length==1){
                    b=b.touches[0];
                    oX=b.pageX;
                }
            } else if (b.type== "touchmove") {
                n=true;
                b.preventDefault();
                if(b.touches.length==1){
                    b=b.touches[0];
                    b=b.pageX;
                    if(oX>b){
                        b=oX-b;
                        if(b>j)
                            if(touching==true){
                                d("next");
                                touching=false
                            }
                    }else{
                        b=b-oX;
                        if(b>j)
                            if(touching==true){
                                d("prev");touching=false
                            }
                    }
                }
            } else if(b.type=="touchend"){
                touching=false;
                if(a(b.target).parent().is("a")&&!n){
                    b=a(b.target).parent("a").attr("href");
                    q(b)
                }
            } else if(b.type=="touchcancel")
                touching=false
        } 
        
        function q(b){
            window.location.assign(b)
        } 
        
        function o(){
            var b=window.innerHeight+window.pageYOffset+"px",r=window.innerHeight+ window.pageYOffset-186+"px";
            a("#promo").css("top",b).show();a("#promo").animate({top:r})
        }
        
        function s(){a("#promo").hide()}

        function p(){
            var b=window.innerHeight+window.pageYOffset+"px";
            a("#promo").animate({top:b});
            setTimeout(function(){
                a("#promo").remove()
            },200)
        }a(window).load(function(){
            window.scrollTo(0,1)
        });
        var k=0,l=320,m=0,j=50,i=100,n=false;g();
        
        a("body").bind("orientationchange",g);

        if(a.cookie("CFClose") != "close" && (navigator.userAgent.toLowerCase().match("iphone")||navigator.userAgent.toLowerCase().match("ipod")||navigator.userAgent.toLowerCase().match("ipad")) && navigator.userAgent.toLowerCase().match("safari"))
		//if(a.cookie("camfrogClose") != "close")
        {
			if (  (navigator.userAgent.toLowerCase().match("iphone") || navigator.userAgent.toLowerCase().match("ipod")) && navigator.userAgent.toLowerCase().match("safari") ) {
				a("body").append('<div id="promo"><a href="http://itunes.apple.com/us/app/camfrog-video-chat/id409856189?mt=8" id="ad"><img src="/images/apple/bottom_pane_iphone.png" /></a><a href="#" id="close"><img src="/images/apple/close.png" /></a></div>');
			} else if ( (navigator.userAgent.toLowerCase().match("ipad")) && navigator.userAgent.toLowerCase().match("safari") ) {
				a("body").append('<div id="promo"><a href="http://itunes.apple.com/us/app/camfrog-video-chat-for-ipad/id409850100?mt=8" id="ad"><img src="/images/apple/bottom_pane_ipad.png" /></a><a href="#" id="close"><img src="/images/apple/close.png" /></a></div>');
			}

            document.body.ontouchmove=function(){
                s();
            };
                
            document.body.ontouchend=function(){
                setTimeout(function(){
                    o();
                },300);
            };
            
            setTimeout(function(){
                o();
            },2E3);
            
            setTimeout(function(){
                p();
            },2E4);
            
            a("a#close").live("click",function(){
                p();
                a.cookie("camfrogClose","close",{expires:7,path:"/",domain:"camfrog.com"});
                return false
            })
        }
    })
})(jQuery);
