var $jQ = jQuery.noConflict();

$jQ(document).ready(function () {
    $jQ("a.jQueryBookmark").click(function (e) {
        e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
        var bookmarkUrl = this.href;
        var bookmarkTitle = this.title;

        if (window.sidebar) { // For Mozilla Firefox Bookmark
            window.sidebar.addPanel(bookmarkTitle, bookmarkUrl, "");
        } else if (window.external || document.all) { // For IE Favorite
            window.external.AddFavorite(bookmarkUrl, bookmarkTitle);
        } else if (window.opera) { // For Opera Browsers
            $jQ("a.jQueryBookmark").attr("href", bookmarkUrl);
            $jQ("a.jQueryBookmark").attr("title", bookmarkTitle);
            $jQ("a.jQueryBookmark").attr("rel", "sidebar");
        } else { // for other browsers which does not support
            alert('Your browser does not support this bookmark action');
            return false;
        }
    });
});

$jQ(function () {
    $jQ("#query").keyup(function (event) {
        if (event.keyCode != 13) {
            liveSearch($jQ("#query").val());
        }
    });
});

$jQ('.referentItem').each(function (index) {
    if (index > 0) {
        var idReferenceStory = $jQ(this).attr('id');
        var idReferenceStoryButton = $jQ('#' + idReferenceStory).find('.collapseIcon').attr('id');
        $jQ('#' + idReferenceStoryButton).click();
    }
});

/* jQuery liveSearch */
function liveSearch(input) {
    var $results = $jQ("#liveSearchResults");

    if ($results.length === 0) {
        $jQ("#quicksearch").append('<div id="liveSearchResults" style="display:none"></div>');
        $results = $jQ("#liveSearchResults");
    }

    if (input.length > 2) {
        $results.load("/Ajax/LiveSearch/", { "query": input });
        $results.show();
    }
    else {
        $results.hide();
    }
}

function setFlashHeight(height) {
    $("flashContainer").setStyle({ height: height + "px" });
}
