var ie=document.all
var dom=document.getElementById
var ns4=document.layers
var calunits=document.layers? "" : "px"

var bouncelimit=32 //(must be divisible by 8)
var direction="up"

jQuery(document).ready(function() {
    window.countt = (window.countt == undefined)? '1' : window.countt;
    jQuery('#toolbarline').mouseover(function() {
        //if(jQuery('#dropin').is(':hidden') == true ){ //Do not show ex if hover already visible
        var dropin = jQuery('#dropin');
        if(dropin.length == 0 || dropin.is(':hidden') == true){
            window.countt == null;
            var cookieName = "submitted";
            window.submitted = getCookie(cookieName);
            if (window.submitted == null){
                if (window.countt <= 2){
                   // showexit('exitpopup.php');
                    initbox('dropin_ex');
                    var ott = {};
                    ott.offset = jQuery("#toolbarline").offset();
                    ott.topPadding = 0;
                    
                    jQuery(window).scroll(function() {
                        if (jQuery(window).scrollTop() > ott.offset.top) {
                            jQuery("#toolbarline").stop().animate({
                            marginTop: jQuery(window).scrollTop() - ott.offset.top + ott.topPadding
                            }, 1);
                        } else {
                            jQuery("#toolbarline").stop().animate({
                                marginTop: 0
                            });
                        };
                    });
                        
                }
                
            }
        }
    });

    jQuery(".phone").bind("mouseenter",function(){
        jQuery('.phone').css('font-size', 24);
        jQuery('.phone').css('color', 'white');
    }).bind("mouseleave",function(){
            jQuery('.phone').css('font-size', 14);
            jQuery('.phone').css('color', '#7EFF82');
        });

});
        
function getCookie(cookieName){
    
    if (document.cookie.length > 0) {
        var begin = document.cookie.indexOf(cookieName + "=");
        if (begin != -1) {
            begin += cookieName.length+1;
            var end = document.cookie.indexOf(";", begin);
            if (end == -1) {
                end = document.cookie.length;
            }
            return unescape(document.cookie.substring(begin, end));
        }
    }
    return null;
}

function setCookie(cookieName, value, expiredays) {
    var expireDate = new Date ();
    expireDate.setTime(expireDate.getTime() + (expiredays * 24 * 3600 * 1000));
    document.cookie = cookieName + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + expireDate.toGMTString());
}

function initbox(idElement){
    if (!dom&&!ie&&!ns4)
    return
    crossobj=(dom)?document.getElementById(idElement).style : ie? document.all.dropin : document.dropin
    scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
    crossobj.top=scroll_top-250+calunits
    crossobj.visibility=(dom||ie)? "visible" : "show"
    crossobj.display = 'block';
    dropstart=setInterval("dropin()",50)
}

function dropin(){
    scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
    if (parseInt(crossobj.top)<100+scroll_top)
    //crossobj.top=parseInt(crossobj.top)+40+calunits
    crossobj.top='65px'
    else{
    clearInterval(dropstart)
    bouncestart=setInterval("bouncein()",50)
}
}

function bouncein(){
    crossobj.top=parseInt(crossobj.top)-bouncelimit+calunits
    if (bouncelimit<0)
    bouncelimit+=8
    bouncelimit=bouncelimit*-1
    if (bouncelimit==0){
    clearInterval(bouncestart)
    }
}

function dismissbox(is_hover){
    window.countt++; //need to avoid users anoying (not show popup more than two times)
    if (window.bouncestart) clearInterval(bouncestart)
    
    //crossobj.visibility="hidden";
    //crossobj.display = 'none';
    
    if (is_hover == 1){
        jQuery('#dropin').hide();
        play();
    }else{
        jQuery('#dropin_ex').hide();
    }
}

function truebody(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

