


(function() {

// Localize jQuery variable
var jQuery;

function replace(item, newstr) {
    el = jQuery(item);
    el.attr("origtext", el.text());
    el.text(newstr);
}

function restore(item) {
    el = jQuery(item);
    el.text(el.attr("origtext"));
}

function _load_query() {
    if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.6.4') {
        var script_tag = document.createElement('script');
        script_tag.setAttribute("type","text/javascript");
        script_tag.setAttribute("src",
            "http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js");
        script_tag.onload = _start;
        script_tag.onreadystatechange = function () { // Same thing but for IE
            if (this.readyState == 'complete' || this.readyState == 'loaded') {
                _start();
            }
        };
        // Try to find the head, otherwise default to the documentElement
        (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
    } else {
        // The jQuery version on the window is the one we want to use
        jQuery = window.jQuery;
        _start();
    }
}

function _start() {
    jQuery = window.jQuery.noConflict(true);
    
    custard_start();
    
}

function unload() {
    jQuery.ajax("http://www.getcustard.com/wl", {async: true});
}



function restore_all() {
    restore("span#-custard-header-text");
    restore("a#-custard-call");
    restore("div#-cust-phone-number");
}

function widget_show() {
    jQuery('div#-cust-extended').slideDown('fast');
    jQuery('div#-cust-header').addClass('open');
    jQuery(this).blur();
}

function widget_hide() {
    jQuery('div#-cust-extended').slideUp('fast');
    jQuery('div#-cust-header').removeClass('open');
    jQuery(this).blur();
    restore_all();
}

function custard_start() { 
    var d = new Date();

    jQuery(document).ready(function($) { 
        jQuery(window).unload(unload);
        var css_link = jQuery("<link>", { 
            rel: "stylesheet", 
            type: "text/css", 
            href: "http://www.getcustard.com/static/css/widget.css?d=" + d.getTime()
        });
        css_link.appendTo('head'); 

        jQuery("body").append('<style>div#-cust-container{background-color:#4815d4}</style><div id="-cust-container" class="bottom-right -custard-pie"><div id="-cust-header"><a href=""><span id="-custard-phone-icon">&nbsp;</span><span id="-custard-header-text">Get Live Help</span></a></div><div id="-cust-extended"><a href="#" class="-custard-button -custard-pie" id="-custard-call">Click to Call</a><div id="-cust-phone-number">+1 (508) 333-8162</div><div id="-cust-footer"><a href="http://www.getcustard.com"><span>powered by</span><span id="-custard-logo"></span></a></div></div></div>');

        

        jQuery('div#-cust-header a').click(function() {
            jQuery('div#-cust-extended').slideToggle('fast');
            jQuery('div#-cust-header').toggleClass('open');
            jQuery(this).blur();
            return false;
        });

	jQuery("a#-custard-call").click(function() {
            
            window.open("http://www.getcustard.com/widget_call", '_blank', 'toolbar=0,location=0,menubar=0,status=0,width=276,height=400,resizable=0'); 
            jQuery(this).blur();
            widget_hide();
            return false;
            });

        
    });
}

_load_query();
})(); // We call our anonymous function immediately
