﻿// Variables
var timeoutID;

function ShowRSSDIV(divID) {
    document.getElementById(divID).style.visibility = "visible";
}

function HideRSSDIV(divID) {
    document.getElementById(divID).style.visibility = "hidden";
}

function HideRSSDIV_Delayed(divID) {
    timeoutID = setTimeout("HideRSSDIV('" + divID + "')", 1000);
}
function HideRSSDIV_Delayed(divID,delay) {
    timeoutID = setTimeout("HideRSSDIV('" + divID + "')", delay);
}
function switchTheImage(sender, eventArgs) {
    if (sender.src.indexOf("_off.gif") > -1)
        sender.src = sender.src.replace("_off.gif", "_on.gif");
    else
        sender.src = sender.src.replace("_on.gif", "_off.gif");
}

//http://www.walterzorn.com/tooltip/tooltip_e.htm

// the following little extension (handling OnMoveAfter event) is an addition to preserve the 
// mouse click position until data comes back from the server
// as well as working-around the fact that the tooltip appears
// where the mouse is at (if you move the mouse right after invoking the action that pops the tooltip)
// even if we reset the mouse position right after the call to Tip()

var ajaxFixExtension = new tt_Extension();
ajaxFixExtension.OnMoveBefore = function() {
    if(this.coordinates) {
        tt_SetTipPos(this.coordinates[0], this.coordinates[1]);
        
    }
}

var RSS = function() {
    return {       
        GrabSnippet : function(postID, ev) {
            // we have to save the coordinates where the mouse clicked
            // so that we can show the tooltip at the correct place in the
            // ajax callback
            xpos = tt_GetEvtX(ev);
            ypos = tt_GetEvtY(ev);
            successArgs = xpos.toString() + ";" + ypos.toString();
            DailySlice.Modules.RSS_m.RSSWebService.GetPostSnippet(postID,
                        RSS.SucceededCallback, RSS.FailedCallback, successArgs);
        },
        
        GetPostsInCategory : function(categoryName, websiteID, ev) {
            // we have to save the coordinates where the mouse clicked
            // so that we can show the tooltip at the correct place in the
            // ajax callback
            xpos = tt_GetEvtX(ev);
            ypos = tt_GetEvtY(ev);
            successArgs = xpos.toString() + ";" + ypos.toString();
            DailySlice.Modules.RSS_m.RSSWebService.GetPostsInCategory(categoryName,
                websiteID, RSS.SucceededCallback, RSS.FailedCallback, successArgs);
        },
        
        SucceededCallback : function(result, args) {
            coordinates = args.split(';', 2);
            Tip(result,
            STICKY, true,
            CLICKCLOSE, true,
            BGCOLOR, '#FFF',
            BORDERCOLOR, '#0C1967',
            SHADOW, true,
            PADDING, 9,
            FADEOUT, 200,
            FADEIN, 200,
            WIDTH, -340);
            //debugger;
            ajaxFixExtension.coordinates = coordinates;
        },
        
        FailedCallback : function(result) {
            alert("Oops! we're sorry, we are having some technical difficulties.");
        },
        
        ShowToolTip : function (text, sticky) {
            Tip(text,
            STICKY, sticky,
            CLICKCLOSE, sticky,
            BGCOLOR, '#c6c9dc',
            BORDERCOLOR, '#0C1967',
            SHADOW, true,
            PADDING, 9,
            FADEOUT, 200,
            FADEIN, 200,
            WIDTH, -340);
        },
        
        ShowToolTip2 : function (text, sticky, clickclose) {
            TagToTip(text,
            CLOSEBTN, true,
            STICKY, sticky,
            CLICKCLOSE, clickclose,
            BGCOLOR, '#c6c9dc',
            BORDERCOLOR, '#0C1967',
            SHADOW, true,
            PADDING, 9,
            FADEOUT, 200,
            FADEIN, 200,
            WIDTH, -340);
        }
    };
}();

function TipMorePosts(divID) {
    var div = document.getElementById(divID);
    //alert(div.offsetWidth);
    //alert(div.offsetHeight);
    //alert(div.offsetLeft);
    //alert(div.offsetTop);
    //alert(div.top);
    //alert(tt_GetScrollX());
    //alert(tt_GetScrollY());
    //alert(tt_GetClientW());
    //alert(tt_GetClientH());
    
    // Reset position.
    div.style.left = "";
    div.style.top = "";
    
    // Check if showing the div will cause it to go outside the screen.
    
    if (div.offsetLeft + div.offsetWidth > tt_GetScrollX() + tt_GetClientW()) {
        var diff = (div.offsetLeft + div.offsetWidth) - (tt_GetScrollX() + tt_GetClientW()) + 30;
        div.style.left = (div.offsetLeft - diff) + "px";
    }

    if (div.offsetTop + div.offsetHeight > tt_GetScrollY() + tt_GetClientH()) {

        div.style.top = ((div.offsetTop - div.offsetHeight - 20) > 0) ? (div.offsetTop - div.offsetHeight - 20) + "px" :
        "0px";
    }
	//var maxPosX = tt_GetClientW() + tt_scrlX - div.style.width - 1;
	//var maxPosY = tt_GetClientH() + tt_scrlY - div.style.height - 1;
    
    
    ShowRSSDIV(divID);
    
    //alert(div.offsetTop);

    
    //RSS.ShowToolTip(div.innerHTML, true);
}

function UnTip_Delayed() {
    timeoutID = setTimeout("UnTip()", 1000);
}
