if (typeof jQuery != "undefined" && typeof $j == "undefined") {
    $j = jQuery.noConflict();
}

FuzzFind.Label.TITLE = "";
FuzzFind.Label.LOADING = "";
FuzzFind.Config.debug = false;
FuzzFind.Config.baseUrl = "";
FuzzFind.Config.cssPrefix = "ff-";
FuzzFind.Config.instantEnabled = false;
FuzzFind.Config.autoSuggest = false;
FuzzFind.Config.searchPrefix = "" //"+site:fuzzfind.com ";
FuzzFind.Config.showHighlight = true;
FuzzFind.Config.showEffects = false;
FuzzFind.Config.showControls = false;
FuzzFind.Config.showTitle = false;
FuzzFind.Config.refreshOnSubmit = false;
FuzzFind.Config.target = false; // "_blank";
FuzzFind.Config.ad2Url = "ads3.html";
FuzzFind.Config.showAds = true;
FuzzFind.Config.selectedSearchEngines = ["Google"]; //["Google", "Bing", "Yahoo"];
FuzzFind.Config.selectedSupplementaryEngines = ["GoogleImages"]; //["GoogleImages", "GoogleNews"]
//FuzzFind.Config.selectedSocialEngines = ["Delicious"];
FuzzFind.Config.selectedSuggestionEngines = ["YahooSuggest"];

FuzzFind.UI = {

    searchBoxId: "#ff-site-search-box",
    overlayTop: "0px",
    overlayLeft: "center",
    overlayWidth: "700px",
    overlayHeight: "400px",
    welcomeMessage: "",
    embedded: false,

    initialize: function(input, overlay) {
        if (!FuzzFind.UI.embedded) {
            FuzzFind.UI.embed(input, overlay);
            FuzzFind.UI.embedded = true;
        }
        FuzzFind.UI.overlaySetup();
        FuzzFind.Searcher.initialize();
        //FuzzFind.Searcher.showSearchBox();
    },

    overlaySetup: function() {

        // create custom animation algorithm for jQuery called "drop"
        $j.easing.drop = function (x, t, b, c, d) {
            return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
        };


        // loading animation
        $j.tools.overlay.addEffect("drop", function(css, done) {

            // use Overlay API to gain access to crucial elements
            var conf = this.getConf(),
            overlay = this.getOverlay();

            // determine initial position for the overlay
            if (conf.fixed)  {
                css.position = 'fixed';
            } else {
                css.top += $j(window).scrollTop();
                css.left += $j(window).scrollLeft();
                css.position = 'absolute';
            }

            // position the overlay and show it
            overlay.css(css).show();

            // begin animating with our custom easing
            overlay.animate({
                top: '+=55',
                opacity: 1,
                width: '+=20'
            }, 400, 'drop', done);

        /* closing animation */
        }, function(done) {
            this.getOverlay().animate({
                top:'-=55',
                opacity:0,
                width:'-=20'
            }, 300, 'drop', function() {
                $j(this).hide();
                done.call();
            });
        }
        );

        if (FuzzFind.UI.overlayWidth) {
            $j("#ff-ui").css("width", FuzzFind.UI.overlayWidth);
            $j(".ff-overlay").css("width", FuzzFind.UI.overlayWidth);
        }
        var trigger = $j(FuzzFind.UI.searchBoxId).overlay({
            // custom top position
            top: FuzzFind.UI.overlayTop,
            left: FuzzFind.UI.overlayLeft,

            target: "#ff-ui",

            // some mask tweaks suitable for modal dialogs
            mask: {
                color: '#ebecff',
                loadSpeed: 200,
                opacity: 0.9
            },

            // disable this for modal dialog-type of overlays
            closeOnClick: false,

            closeOnEsc: true,

            effect: (document.all) ? "default" : "drop"

        // load it immediately after the construction
        //load: true
        });

        $j(FuzzFind.UI.searchBoxId).keyup(function(e) {
            $j(FuzzFind.UI.searchBoxId).click();
            e.preventDefault();
        });
        $j(FuzzFind.UI.searchBoxId).click(function(e) {
            if (FuzzFind.UI.overlayHeight) {
                $j("#ff-body").css("min-height", FuzzFind.UI.overlayHeight);
                $j("#ff-body").css("max-height", FuzzFind.UI.overlayHeight);
                $j("#ff-body").css("height", FuzzFind.UI.overlayHeight);
            }
            $j("#ff-searchQuery").value = $j(FuzzFind.UI.searchBoxId).value;
            $j("#ff-searchQuery").focus();
        });
    // select the overlay element - and "make it an overlay"
    },

    embed: function(input, overlay) {
        // embed input
        if (typeof input == "string" && input.length > 0) {
            FuzzFind.UI.searchBoxId = input;
        }
        else {
            document.write(FuzzFind.UI.inputHtml);
        }

        // embed overlay
        if (overlay && $j(overlay)) {
            $j(overlay).append(FuzzFind.UI.overlayHtml);
        }
        else {
            document.write(FuzzFind.UI.overlayHtml);
        }

        // set welcome message
        $j("#ff-welcome").html(FuzzFind.UI.welcomeMessage);
    },

    inputHtml:
        '<form>\
            <input type="text" id="ff-site-search-box" value="Search" />\
        </form>',

    overlayHtml:
        '<div id="ff-ui" class="ff-overlay">\
            <div id="ff-sideLabel"><a href="http://www.fuzzfind.com" target="_blank"></a></div>\
            <div id="ff-body">\
                <div id="ff-searchControls">\
                    <form id="ff-searchBoxForm" method="GET" action="" onsubmit="FuzzFind.Searcher.submitSearchBox();">\
                        <div id="ff-searchBox">\
                            <div id="ff-searchTextFields">\
                                <div id="ff-searchMessage">Powered by <a href="http://www.fuzzfind.com" target="_blank">FuzzFind Web Search</a></div>\
                                <input type="text" id="ff-searchQuery" name="q" class="searchField" autocomplete="off" />\
                                <input type="text" id="ff-suggestedQuery" class="searchField" autocomplete="off" />\
                            </div>\
                            <div id="ff-hiddenQuery" class="searchField"></div>\
                            <div id="ff-resultsStatus" style="display:none"></div>\
                            <div id="ff-debug"></div>\
                            <div id="ff-searchBoxOptions">\
                                <div class="clear"></div>\
                                <label for="searchEngines">&nbsp;</label>\
                                <div id="ff-searchEnginesBox">\
                                    <input type="checkbox" id="ff-searchEngines" name="searchEngines" value="Google" disabled="disabled" xchecked="checked" /> Google\
                                    <input type="checkbox" id="ff-searchEngines" name="searchEngines" value="Bing" disabled="disabled" xchecked="checked" /> Bing\
                                    <input type="checkbox" id="ff-searchEngines" name="searchEngines" value="Yahoo" disabled="disabled" xchecked="checked" /> Yahoo\
                                    <input type="checkbox" id="ff-supplementaryEngines" name="supplementaryEngines" value="GoogleImages" disabled="disabled" xchecked="checked" /> Google Images\
                                    <input type="checkbox" id="ff-supplementaryEngines" name="supplementaryEngines" value="GoogleNews" disabled="disabled" xchecked="checked" /> Google News\
                                </div>\
                                <div class="clear"></div>\
                                <label for="socialEngines">&nbsp;</label>\
                                <div id="ff-socialEnginesBox">\
                                    <input type="checkbox" id="ff-socialEngines" name="socialEngines" value="Delicious" disabled="disabled" xchecked="checked" /> Del.icio.us\
                                </div>\
                                <div class="clear"></div>\
                                <label for="suggestionEngines">&nbsp;</label>\
                                <div id="ff-suggestionEnginesBox">\
                                    <input type="checkbox" id="ff-suggestionEngines" name="suggestionEngines" value="YahooSuggest" disabled="disabled" xchecked="checked" /> Yahoo Suggestions\
                                </div>\
                            </div>\
                        </div>\
                    </form>\
                </div>\
                <div id="ff-body-div">\
                    <div id="ff-body-content-div">\
                        <div id="ff-welcome"></div>\
                        <div id="ff-resultsPanel">\
                            <div id="ff-resultsBox"></div>\
                            <div id="ff-resultsFooter">\
                                <div id="ff-searchFeedbackBox"></div>\
                                <div id="ff-searchMoreBox">\
                                    Search for more results on\
                                    <ul id="ff-searchMoreList">\
                                        <li><a href="http://www.fuzzfind.com" onclick="FuzzFind.Searcher.openExternalSearch(\'searcher.html?q=\');return false" title="Go to FuzzFind"><img id="ff-iconFuzzFind" border="0" width="16" height="16" /> FuzzFind</a></li>\
                                        <li><a href="http://www.google.com" onclick="FuzzFind.Searcher.openExternalSearch(\'http://www.google.com/search?q=\');return false" title="Go to Google"><img id="ff-iconGoogle" border="0" width="16" height="16" /> Google</a></li>\
                                        <li><a href="http://www.bing.com" onclick="FuzzFind.Searcher.openExternalSearch(\'http://www.bing.com/results.aspx?q=\');return false" title="Go to Bing"><img id="ff-iconBing" border="0" width="16" height="16" /> Bing</a></li>\
                                        <li><a href="http://search.yahoo.com" onclick="FuzzFind.Searcher.openExternalSearch(\'http://search.yahoo.com/search?p=\');return false" title="Go to Yahoo"><img id="ff-iconYahoo" border="0" width="16" height="16" /> Yahoo</a></li>\
                                        <li><a href="http://del.icio.us" onclick="FuzzFind.Searcher.openExternalSearch(\'http://del.icio.us/search/?fr=del_icio_us&p=\');return false" title="Go to del.icio.us"><img id="ff-iconDelicious" border="0" width="16" height="16" /> del.icio.us</a></li>\
                                    </ul>\
                                </div>\
                            </div>\
                        </div>\
                        <div id="ff-sidebarPanel">\
                            <div id="ff-imagesPanel" style="display:none">\
                                <fieldset>\
                                    <legend>Related Images</legend>\
                                    <div id="ff-imagesBox">\
                                    </div>\
                                </fieldset>\
                            </div>\
                            <div id="ff-newsPanel" style="display:none">\
                                <fieldset>\
                                    <legend>Related News</legend>\
                                    <div id="ff-newsBox">\
                                    </div>\
                                </fieldset>\
                            </div>\
                            <div id="ff-suggestionsPanel" style="display:none">\
                                <fieldset>\
                                    <legend>Related Searches</legend>\
                                    <div id="ff-suggestionsBox">\
                                    </div>\
                                </fieldset>\
                            </div>\
                            <div id="ff-adsPanel">\
                                <fieldset>\
                                    <legend>Ads</legend>\
                                    <div id="ff-adsBox">\
                                    </div>\
                                </fieldset>\
                            </div>\
                        </div>\
                    </div>\
                </div>\
            </div>\
        </div>'

}

