﻿$(document).ready(function() {
    var webRequest = new Sys.Net.WebRequest();
    webRequest.set_url("Default.aspx?gi=1&dummy=" + new Date().getTime());
    webRequest.add_completed(createTerms);
    webRequest.invoke();
//    $('*[id$="teacherlink"]').click(function () {
//        window.location = "http://www.scoilnet.ie/teachers/services.aspx";
//    });
});
function createTerms(result, eventArgs) {
    if (result.get_responseAvailable()) {

        if (result.get_responseData() == "") { createTermsNotForSchool() }
        else { createTermsForSchool() }

    }

}
function createTermsNotForSchool() {
    var terms = '<div id="wbgeneral" class="wbgeneral"><p>Sorry, this service is only available through computers on the Schools Broadband Network. </p></div>';

    $('*[id$="britannica"]').mouseover(function() {

        if (!($('*[id$="wbgeneral"]')[0])) {
            $(terms).appendTo($('*[id$="bannerad"]')).hide("slow").slideToggle("2000");
        }
        else {
            $('*[id$="wbgeneral"]').slideToggle("20000");
        }
    });
    $('*[id$="britannicalink"]').mouseover(function() {

        if (!($('*[id$="wbgeneral"]')[0])) {
            $(terms).appendTo($('*[id$="bannerad"]')).hide("slow").slideToggle("2000");
        }
        else {
            $('*[id$="wbgeneral"]').slideToggle("20000");
        }
    });
   
    $('*[id$="britannica"]').mouseout(function() {
        $('*[id$="wbgeneral"]').hide("fast");
    });
   

}
function createTermsForSchool() {

    $('*[id$="britannica"]').click(function() {
        bt();
    });

}
function britannicaclose() {
    $('*[id$="wbtermsbritannica"]').hide("fast");
}
function wbstudentsclose() {
    $('*[id$="wbtermsstudents"]').hide("fast");
}
function bt() {
        var webRequest = new Sys.Net.WebRequest();
        webRequest.set_url("Default.aspx?wb=britannica&dummy=" + new Date().getTime());
        webRequest.add_completed(openBritannica);
        webRequest.invoke();
}
function wbstudents() {
//    if ($('input[id=webtermscheck]').is(':checked')) {
//        $('input[id=webtermscheck]').attr('checked', false);
//        
        var webRequest = new Sys.Net.WebRequest();
        webRequest.set_url("Default.aspx?wb=worldbook&dummy=" + new Date().getTime());
        webRequest.add_completed(openWorldbookStudents);
        webRequest.invoke();
    //}
}
function openBritannica(result, eventArgs) {
    if (result.get_responseAvailable()) {
        $('*[id$="wbtermsbritannica"]').hide("fast");
        window.location = "http://www.school.eb.co.uk";
    }
}
var wbtip = {
    fadeeffect: [false, 2000], //enable Fade? [true/false, duration_milliseconds]
    useroffset: [10, 10], //additional x and y offset of tooltip from mouse cursor, respectively
    loadingHTML: '<div style="font-style:italic"><img src="images/loading.gif" /> Searching...</div>',

    positiontip: function($tooltip, e) {
        var docwidth = (window.innerWidth) ? window.innerWidth - 15 : ajaxtooltip.iebody.clientWidth - 15
        var docheight = (window.innerHeight) ? window.innerHeight - 18 : ajaxtooltip.iebody.clientHeight - 15
        var twidth = $tooltip.get(0).offsetWidth
        var theight = $tooltip.get(0).offsetHeight
        var tipx = e.pageX + this.useroffset[0]
        var tipy = e.pageY + this.useroffset[1]
        tipx = (e.clientX + twidth > docwidth) ? tipx - twidth - (2 * this.useroffset[0]) : tipx //account for right edge
        tipy = (e.clientY + theight > docheight) ? tipy - theight - (2 * this.useroffset[0]) : tipy //account for bottom edge
        if (tipy < 0) { tipy = 150 }
        $tooltip.css({ left: tipx, top: tipy })
    },

    showtip: function($tooltip, e) {
        if (this.fadeeffect[0])
            $tooltip.hide().fadeIn(this.fadeeffect[1])
        else
            $tooltip.show()
    },

    hidetip: function($tooltip, e) {
        if (this.fadeeffect[0])
            $tooltip.fadeOut(this.fadeeffect[1])
        else
            $tooltip.hide()

    }

}



