
/// <reference path="jquery-vsdoc.js" />


/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/var offsetfrommouse = [0, 0]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration = 0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 370; // maximum image size.

if (document.getElementById || document.all) {
    document.write('<div id="popup">');
    document.write('</div>');
}

function gettrailobj() {
    if (document.getElementById)
        return document.getElementById("popup").style
    else if (document.all)
        return document.all.popup.style
}

function gettrailobjnostyle() {
    if (document.getElementById)
        return document.getElementById("popup")
    else if (document.all)
        return document.all.popup
}


function truebody() {
    return (!window.opera && document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}


function completeInfosSearchHandler(result, eventArgs) {
    if (result.get_responseAvailable()) {
        //alert(result.get_statusText());
        $('*[id^="popupinfo"]').each(function (intIndex) {
            if (this.innerHTML.indexOf("Searching...") > -1) {
                //alert(result.get_responseData());
                var resource = eval("(" + result.get_responseData() + ")");

                newHTML = '';

                newHTML = newHTML + '<p><b>Title: </b><a href="http://www.scoilnet.ie/redir.aspx?rid=' + resource.Id + '&url=' + resource.Location + '" target="_New">' + resource.Name + '</a></p>';
                if (resource.Abstract != '') { newHTML = newHTML + '<p><b>Description: </b>' + resource.Abstract + '</p>' }
                if (resource.LearningOutcomes != '') { newHTML = newHTML + '<p><b>Learning outcomes: </b>' + resource.LearningOutcomes + '</p>' }
                if (resource.ResourcesRequired != '') { newHTML = newHTML + '<p><b>Resources required: </b>' + resource.ResourcesRequired + '</p>' }
                if (resource.SpecialNeeds != '') { newHTML = newHTML + '<p><b>Special Needs notes: </b>' + resource.SpecialNeeds + '</p>' }
                if (resource.ExtensionActivities != '') { newHTML = newHTML + '<p><b>Extension activities: </b>' + resource.ExtensionActivities + '</p>' }

                this.innerHTML = newHTML;
                $('<a href="#" style="position:absolute; top: 0px;left:550px;font-weight:bold;font-size:1em;">X Close</a>').appendTo($('*[id="' + this.id + '"]')).click(function () { $('*[id^="popupinfo"]').slideUp('slow', '') });

                if (resource.WebsiteUrl != '') {
                    var webpage = '<img src="GetWebSiteThumbnail.aspx?melt=1&id=' + resource.WebsiteUrl + '" /><br />';
                    $('<div id="websitepreview">').appendTo($('*[id="' + this.id + '"]'))
                    .html('<div id="preview_loading" style="font-style:italic"><img  src="images/loading.gif" /> Loading Preview...</div>').show('slow', '')
                    .append($(webpage)).slideDown('fast', '');
                    $('*[id^="preview_loading"]').hide('fast', '');
                }
            }
            else {
                var $target = $(this);
                this.style.display = "none";
            }
        })

    }
}
function ClosePW() {
    $('*[id^="stooltip"]').hide('slow');

}

function showtrail(linkinfo,resid) {
     $('*[id^="popupinfo"]').remove();
     $('<div id="popupinfo">').appendTo($('*[id$="ResultsResFinder"]')).html('<div style="font-style:italic"><img src="images/ajax-loaderb.gif" /> Searching...</div>').show('slow', '');
     var webRequest = new Sys.Net.WebRequest();
     webRequest.set_url("ResourcesFinder.aspx?pid=" + resid + "&dummy=" + new Date().getTime());
     webRequest.add_completed(completeInfosSearchHandler);
     webRequest.invoke();
}



function completePreview(result, eventArgs) {
    if (result.get_responseAvailable()) {
        gettrailobjnostyle().innerHTML = '<div  id="popup_content" ><img src="GetWebSiteThumbnail.aspx?rid=' + result.get_responseData() + '" /></div>';
        //gettrailobjnostyle().innerHTML = result.get_responseData();
        //alert(result.get_responseData());
    }
}

function hidetrail() {
    gettrailobj().visibility = "hidden"
    document.onmousemove = ""
    gettrailobj().left = "-500px"

}

function followmouse(e) {

    var xcoord = offsetfrommouse[0]
    var ycoord = offsetfrommouse[1]

    var docwidth = document.all ? truebody().scrollLeft + truebody().clientWidth : pageXOffset + window.innerWidth - 15
    var docheight = document.all ? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

    if (typeof e != "undefined") {
        if (docwidth - e.pageX < 380) {
            xcoord = e.pageX - xcoord - 400; // Move to the left side of the cursor
        } else {
            xcoord += e.pageX;
        }
        if (docheight - e.pageY < (currentimageheight + 110)) {
            ycoord += e.pageY - Math.max(0, (110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
        } else {
            ycoord += e.pageY;
        }

    } else if (typeof window.event != "undefined") {
        if (docwidth - event.clientX < 380) {
            xcoord = event.clientX + truebody().scrollLeft - xcoord - 400; // Move to the left side of the cursor
        } else {
            xcoord += truebody().scrollLeft + event.clientX
        }
        if (docheight - event.clientY < (currentimageheight + 110)) {
            ycoord += event.clientY + truebody().scrollTop - Math.max(0, (110 + currentimageheight + event.clientY - docheight));
        } else {
            ycoord += truebody().scrollTop + event.clientY;
        }
    }

    var docwidth = document.all ? truebody().scrollLeft + truebody().clientWidth : pageXOffset + window.innerWidth - 15
    var docheight = document.all ? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
    if (ycoord < 0) { ycoord = ycoord * -1; }
    if (ycoord < 150) { ycoord = ycoord + 50; }
    
    gettrailobj().left = xcoord + "px"
    gettrailobj().top = ycoord + "px"

}


