﻿/*
* Image preview script 
* powered by jQuery (http://www.jquery.com)
* 
* written by Alen Grakalic (http://cssglobe.com)
* 
* for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
*
*/

this.imagePreview = function () {
    /* CONFIG */

    var xOffset = 50;
    var yOffset = 100;
    var ua = navigator.userAgent;

    // these 2 variable determine popup's distance from the cursor
    // you might want to adjust to get the right result

    /* END CONFIG */
    $("a.articlePreview").hover(function (e) {

        var windowSize = getPageDimensions();
        var windowWidth = windowSize[0];
        var windowHeight = windowSize[1];
        
        if (ua.indexOf("MSIE") >= 0) {
            var top = yOffset + document.documentElement.scrollTop;
            var left = window.event.clientX + xOffset;
        }
        else {
            var top = yOffset + window.pageYOffset;
            var left = e.pageX + xOffset;
        }


        this.t = this.title;
        this.title = "";
        var c = (this.t != "") ? "<br/>" + this.t : "";
        var imgSrc = "";

        if (this.rel == null || this.rel == "") {
            imgSrc = "http://live.invest.ch/Portals/_default/Skins/invest.ch/images/sampleArticle.jpg";
        }
        else {
            imgSrc = this.rel;
        }

        $("body").append("<p id='preview'><img src='" + imgSrc + "' alt='Image preview' />" + c + "</p>");
        $("#preview")
            .css("top", top + "px")
            .css("left", left + "px")
            .css("position", "absolute")
            .css("max-height", "700px")
            .css("overflow", "hidden")
            .fadeIn("fast");
    },
    function () {
        this.title = this.t;
        $("#preview").remove();
    });

};


// starting the script on page load
$(document).ready(function () {
    imagePreview();
});
