﻿//Code binding for page
jQuery(function () {
    // Accordion
    //    jQuery('#sidebar .accordion').accordion({
    //        header: 'h5',
    //        autoheight: false,
    //        active: 0
    //    });
    //jQuery('.accordion h5').append('<span></span>');

    //Make Homepage   
    jQuery("#makehomepage").click(function (event) {
        if (document.all) {//IE                
            document.body.style.behavior = 'url(#default#homepage)';
            document.body.setHomePage(document.URL);
        }
        else {//FF   
            alert("Make the homepage failed, please manual set!");
        }
        event.preventDefault();
    })

    //Add Favorites
    jQuery("#addfavorites").click(function (event) {
        var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL';
        var url = document.URL;
        var title = document.title;
        if (document.all)
        {
            window.external.addFavorite(url, title);
        }
        else if (window.sidebar) 
        {
            window.sidebar.addPanel(title, url, "");
        }
        else {//Add Favorites  
            alert('Add favorites failed\n You can try use the keyword shortcut' + ctrl + ' + D to add it!');
        }
        event.preventDefault();
    })

    //bind web search
    jQuery("div.websearch").bindSearch()
});

// jQuery UI Accordion 1.6 * Copyright (c) 2007 Jörn Zaefferer * http://docs.jquery.com/UI/Accordion * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * Revision: jQueryId: jquery.accordion.js 4876 2008-03-08 11:49:04Z joern.zaefferer jQuery
(function (e) { e.ui = e.ui || {}; e.fn.extend({ accordion: function (h, i) { var g = Array.prototype.slice.call(arguments, 1); return this.each(function () { if (typeof h == "string") { var j = e.data(this, "ui-accordion"); j[h].apply(j, g); } else { if (!e(this).is(".ui-accordion")) { e.data(this, "ui-accordion", new e.ui.accordion(this, h)); } } }); }, activate: function (g) { return this.accordion("activate", g); } }); e.ui.accordion = function (g, h) { this.options = h = e.extend({}, e.ui.accordion.defaults, h); this.element = g; e(g).addClass("ui-accordion"); if (h.navigation) { var k = e(g).find("a").filter(h.navigationFilter); if (k.length) { if (k.filter(h.header).length) { h.active = k; } else { h.active = k.parent().parent().prev(); k.addClass("current"); } } } h.headers = e(g).find(h.header); h.active = c(h.headers, h.active); if (h.fillSpace) { var j = e(g).parent().height(); h.headers.each(function () { j -= e(this).outerHeight(); }); var i = 0; h.headers.next().each(function () { i = Math.max(i, e(this).innerHeight() - e(this).height()); }).height(j - i); } else { if (h.autoheight) { var j = 0; h.headers.next().each(function () { j = Math.max(j, e(this).outerHeight()); }).height(j); } } h.headers.not(h.active || "").next().hide(); h.active.parent().andSelf().addClass(h.selectedClass); if (h.event) { e(g).bind((h.event) + ".ui-accordion", f); } }; e.ui.accordion.prototype = { activate: function (g) { f.call(this.element, { target: c(this.options.headers, g)[0] }); }, enable: function () { this.options.disabled = false; }, disable: function () { this.options.disabled = true; }, destroy: function () { this.options.headers.next().css("display", ""); if (this.options.fillSpace || this.options.autoheight) { this.options.headers.next().css("height", ""); } e.removeData(this.element, "ui-accordion"); e(this.element).removeClass("ui-accordion").unbind(".ui-accordion"); } }; function b(h, g) { return function () { return h.apply(g, arguments); }; } function d(i) { if (!e.data(this, "ui-accordion")) { return; } var g = e.data(this, "ui-accordion"); var h = g.options; h.running = i ? 0 : --h.running; if (h.running) { return; } if (h.clearStyle) { h.toShow.add(h.toHide).css({ height: "", overflow: "" }); } e(this).triggerHandler("change.ui-accordion", [h.data], h.change); } function a(g, k, l, j, m) { var i = e.data(this, "ui-accordion").options; i.toShow = g; i.toHide = k; i.data = l; var h = b(d, this); i.running = k.size() == 0 ? g.size() : k.size(); if (i.animated) { if (!i.alwaysOpen && j) { e.ui.accordion.animations[i.animated]({ toShow: jQuery([]), toHide: k, complete: h, down: m, autoheight: i.autoheight }); } else { e.ui.accordion.animations[i.animated]({ toShow: g, toHide: k, complete: h, down: m, autoheight: i.autoheight }); } } else { if (!i.alwaysOpen && j) { g.toggle(); } else { k.hide(); g.show(); } h(true); } } function f(l) { var j = e.data(this, "ui-accordion").options; if (j.disabled) { return false; } if (!l.target && !j.alwaysOpen) { j.active.parent().andSelf().toggleClass(j.selectedClass); var i = j.active.next(), m = { instance: this, options: j, newHeader: jQuery([]), oldHeader: j.active, newContent: jQuery([]), oldContent: i }, g = j.active = e([]); a.call(this, g, i, m); return false; } var k = e(l.target); if (k.parents(j.header).length) { while (!k.is(j.header)) { k = k.parent(); } } var h = k[0] == j.active[0]; if (j.running || (j.alwaysOpen && h)) { return false; } if (!k.is(j.header)) { return; } j.active.parent().andSelf().toggleClass(j.selectedClass); if (!h) { k.parent().andSelf().addClass(j.selectedClass); } var g = k.next(), i = j.active.next(), m = { instance: this, options: j, newHeader: k, oldHeader: j.active, newContent: g, oldContent: i }, n = j.headers.index(j.active[0]) > j.headers.index(k[0]); j.active = h ? e([]) : k; a.call(this, g, i, m, h, n); return false; } function c(h, g) { return g != undefined ? typeof g == "number" ? h.filter(":eq(" + g + ")") : h.not(h.not(g)) : g === false ? e([]) : h.filter(":eq(0)"); } e.extend(e.ui.accordion, { defaults: { selectedClass: "selected", alwaysOpen: true, animated: "slide", event: "click", header: "a", autoheight: true, running: 0, navigationFilter: function () { return this.href.toLowerCase() == location.href.toLowerCase(); } }, animations: { slide: function (g, i) { g = e.extend({ easing: "swing", duration: 300 }, g, i); if (!g.toHide.size()) { g.toShow.animate({ height: "show" }, g); return; } var h = g.toHide.height(), j = g.toShow.height(), k = j / h; g.toShow.css({ height: 0, overflow: "hidden" }).show(); g.toHide.filter(":hidden").each(g.complete).end().filter(":visible").animate({ height: "hide" }, { step: function (l) { var m = (h - l) * k; if (e.browser.msie || e.browser.opera) { m = Math.ceil(m); } g.toShow.height(m); }, duration: g.duration, easing: g.easing, complete: function () { if (!g.autoheight) { g.toShow.css("height", "auto"); } g.complete(); } }); }, bounceslide: function (g) { this.slide(g, { easing: g.down ? "bounceout" : "swing", duration: g.down ? 1000 : 200 }); }, easeslide: function (g) { this.slide(g, { easing: "easeinout", duration: 700 }); } } }); })(jQuery);

//jQuery Infinite Carousel  - Copyright 2009 Stéphane Roucheray - Note: This version has been modified by BlueArc.
jQuery.fn.carousel = function (a) { var b = { target: "ul", axis: "y", previous: null, next: null, pause: null, autoscroll: true, hoverpause: true, speed: 750, duration: 5e3, offset: 0 }; if (a) jQuery.extend(b, a); if (jQuery(this).css("position") != "relative") jQuery(this).css("position", "relative"); var c = jQuery(this).children(b.target)[0]; if (jQuery(c).css("position") != "absolute") jQuery(c).css("position", "absolute"); if (c) { var d; if (b.axis == "y") { d = jQuery(c).children().outerWidth("true") + b.offset } else if (b.axis == "x") { d = jQuery(c).children().outerHeight("true") + b.offset } var e = jQuery(c).children(), f = e.length, g = d; var h; if (b.axis == "y") { h = Math.round(jQuery(this).width() / g) } else if (b.axis == "x") { h = Math.round(jQuery(this).height() / g) } var j = 1, k = false, l = false, m; if (f <= h) { jQuery(b.previous).hide(); jQuery(b.next).hide(); if (b.axis == "y") { jQuery(c).css("width", (f + h) * d + d + "px") } else if (b.axis == "x") { jQuery(c).css("height", (f + h) * d + d + "px") } } else { for (i = 0; i < h; i++) { if (b.axis == "y") { jQuery(c).css("width", (f + h) * d + d + "px") } else if (b.axis == "x") { jQuery(c).css("height", (f + h) * d + d + "px") } if (i < f) { jQuery(c).append(jQuery(e[i]).clone()) } } } jQuery(b.previous).click(function (a) { a.preventDefault(); if (!l) { if (j == 1) { if (b.axis == "y") { jQuery(c).css("left", "-" + f * g + "px") } else if (b.axis == "x") { jQuery(c).css("top", "-" + f * g + "px") } j = f } else { j-- } if (b.axis == "y") { jQuery(c).animate({ left: "+=" + d, y: 0, queue: false }, b.speed, "swing", function () { l = false }) } else if (b.axis == "x") { jQuery(c).animate({ top: "+=" + d, x: 0, queue: false }, b.speed, "swing", function () { l = false }) } l = true } }); jQuery(b.next).click(function (a) { a.preventDefault(); if (!l) { if (j > f) { j = 2; if (b.axis == "y") { jQuery(c).css("left", "0px") } else if (b.axis == "x") { jQuery(c).css("top", "0px") } } else { j++ } if (b.axis == "y") { jQuery(c).animate({ left: "-=" + d, y: 0, queue: false }, b.speed, "swing", function () { l = false }) } else if (b.axis == "x") { jQuery(c).animate({ top: "-=" + d, x: 0, queue: false }, b.speed, "swing", function () { l = false }) } l = true } }); jQuery(b.pause).click(function (a) { if (!k) { k = true; jQuery(b.pause).addClass("paused"); if (b.autoscroll) { window.clearInterval(m) } } else { k = false; jQuery(b.pause).removeClass("paused"); if (b.autoscroll && f > h && !b.hoverpause) { m = window.setInterval(function () { jQuery(b.next).click() }, b.duration) } } }); if (b.autoscroll && f > h) { m = window.setInterval(function () { jQuery(b.next).click() }, b.duration) } if (b.hoverpause) { jQuery(this).mouseenter(function () { if (!k && b.autoscroll) { window.clearInterval(m) } }); jQuery(this).mouseleave(function () { if (!k && b.autoscroll) { m = window.setInterval(function () { jQuery(b.next).click() }, b.duration) } }) } } };

(function ($) {
    // the "class" attribute of a selected html element
    var selectedClass = "selected";

    $.fn.bindSearch = function () {
        ///	<summary>
        ///		This is a wrapper function which will setup the "Form" elements in the wrapped set as search forms.
        ///	</summary>
        ///	<returns type="jQuery" />

        //for each form element, make it as a search form and return the collection
        return $(this).each(function () {
            var searchDiv = $(this);
            $("div.scopes a", searchDiv).click(onScopeLinkClick);

            // bind the submit event of the search form to the "onFormSubmit" function
            //searchForm.bind("submit", onFormSubmit);
        });
    };

    // change the scope of searchForm based on a scope link
    function onFormSubmit() {
        // define a variable and refers to the search form
        var searchForm = $(this);
        var scopeUrl = searchForm.attr("action", scopeUrl);
        var queryParams = $.url.getParam(scopeUrl);
        $.queryString.setFormFields(searchForm, queryParams);
    }

    function onScopeLinkClick(event) {
        // prevent the link click event from navigating away from the page
        event.preventDefault();
        // this variable referes to the anchor tag which is the currentTarget of click
        var link = $(this);
        // This variable points to the input element which contains the search term
        var searchTextBox = $("div.search input[type=text]","div.websearch");
        var searchTerm = $.trim(searchTextBox.attr('value'));
        // Set action property of search form to the href of selected scope link.
        //searchForm.attr("action", link.attr('href'));
        var hiddenTextBox = $("div.search input[type=hidden]","div.websearch");
        //remove the "selected" class from the currently selected anchor tag
        $("a." + selectedClass,"div.websearch").removeClass(selectedClass);
        // set the "selected" class on the clicked anchor targ
        link.addClass(selectedClass);
        hiddenTextBox.attr("value",link.text())
        //alert(hiddenTextBox.attr('value'));
        // set focus on the search textbox.
        searchTextBox.trigger("focus");
        // If there is a search term and it is not empty
//        if (searchTerm) {
//            // submit the search form
//            // calling .submit() will not work. jquery bug
//            searchForm.trigger('submit');
//        } 
    }
    
})(jQuery);
