﻿this.tipper = function (page) {
    section = page;

    console.log(section);

    sectionColour = "#333333";

    xOffset = 20;
    yOffset = 20;
    tipWidth = 250;

    switch (section) {
        case "s-home":
            sectionColour = "#da9a23";
            break;
        case "s-portfolio":
            sectionColour = "#78b8bd";
            break;
        case "s-experiments":
            sectionColour = "#96c33d";
            break;
        case "s-chronicles":
            sectionColour = "#969fb2";
            break;
        case "s-interaction":
            sectionColour = "#a276a5";
            break;
    }

    $('.tipped').hover(
			function (e) {
			    //  x = (x + tipw > $(document).scrollLeft() + $(window).width()) ? x - tipw - (stickytooltip.tooltipoffsets[0] * 2) : x
			    x = e.pageX + xOffset;
			    y = e.pageY + yOffset;
			    x = (x + tipWidth > $(document).scrollLeft() + $(window).width()) ? x - tipWidth - (xOffset * 2) : x;
			    y = (y + $('#toolTipWrapper').outerHeight() > $(document).scrollTop() + $(window).height()) ? $(document).scrollTop() + $(window).height() - $('#toolTipWrapper').outerHeight() - 10 : y

			    this.tip = this.title;
			    this.title = "";
			    $("body").append(unescape('%3Cdiv id="toolTipWrapper"%3E' + this.tip + '%3C/div%3E'));
			    $('#toolTipWrapper')
					.css({
					    'background-color': sectionColour,
					    'top': y + "px",
					    'left': x + "px",
					    'position': 'absolute',
					    'width': tipWidth,
					    'padding': '5px 10px',
					    'color': '#fff',
					    'border': '1px solid #fff',
					    '-moz-border-radius': '0 10px',
					    '-webkit-border-radius': '0 10px',
					    'border-radius': '0 10px',
					    'font-size': '1.1em'
					})
					.fadeIn("fast");
			},
			function () {
			    this.title = this.tip;
			    $('#toolTipWrapper').fadeOut(100);
			    $('#toolTipWrapper').remove();
			}
		).click(function () {
		    this.css({'cursor' : 'pointer'});
		});

    $(".tipped").mousemove(function (e) {
        x = e.pageX + xOffset;
        y = e.pageY + yOffset;
        x = (x + tipWidth > $(document).scrollLeft() + $(window).width()) ? x - tipWidth - (xOffset * 2) : x;
        y = (y + $('#toolTipWrapper').outerHeight() > $(document).scrollTop() + $(window).height()) ? $(document).scrollTop() + $(window).height() - $('#toolTipWrapper').outerHeight() - 10 : y
        $("#toolTipWrapper").css({
            "top": y + "px",
            'left': x + "px"
        });
    });
};
