﻿// NOTE TO GP ADMINS: Do not link directly to this Javascript file.  The file name 
// is occasionally changed when the contents need to be updated in a user's cache.
var interferingScripts = false; 

var getPageHasGallery = function() {
    if ($.find("#grpSlides").length > 0) {
        return true;
    }
    else {
        return false;
    }
}

var wireGallery = function() {
    if (getPageHasGallery()) {
        if (jQuery('#grpSlides') != null) {
            jQuery('#grpSlides').cycle(
            {
                fx: 'fade',
                speed: 2500,
                timeout: 6000,
                delay: -5000,
                next: '#grpSlides',
                pause: 1,
                random: 1
            }
        );
        }
    }
}

var pageLoad = function() {
}


jQuery(document).ready(function() {
    wireUi();
    reWireGrids();
    tooltip();
    applyFaceBox();
});

// DDrive Transition Empty Functions.
function hideddrivetip() {} 
function ddrivetip(s, o, p) {} 

function writeFlashElement(iWidth, iHeight, sSrc, sNavTo)
{
    var gpDoc = document; 
    
    gpDoc.write('<span onmousedown="window.location.href=&#39;' + sNavTo + '&#39;">');
    gpDoc.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + iWidth.toString() + '" height="' + iHeight.toString() + '">');
    gpDoc.write('<param name="movie" value="' + sSrc + '">');
    gpDoc.write('<param name="quality" value="high">');
    gpDoc.write('<param name="wmode" value="transparent">');
    gpDoc.write('<embed src="' + sSrc + '" WMODE="transparent" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + iWidth.toString() + '" height="' + iHeight.toString() + '"></embed></object>');
    gpDoc.write('</span>');        
}

function openFloater(gId, sUrl, iHeight) {
    jQuery("#IAdmin").hide();
    jQuery("#IAdmin").attr("src", sUrl + "&GuildPortalGuild=" + gId);
    jQuery("#IAdmin").css("height", iHeight);
    jQuery("#IAdmin").show();
    jQuery("#IAdmin").slideDown("fast");
}

function openCWin(gId, pOpt) {
    window.open('/CExplorer/cexpFrame.aspx?Group=' + gId + '&PageOption=' + pOpt, 'EditCWin_' + pOpt, 'width=900,height=675,scrollbars=yes=resizable=yes,status=yes,toolbars=yes,location=no,menubar=no');
}

var openPoppyWin = function(sUrl, sWinId, iWidth, iHeight) {
    window.open(sUrl, sWinId, 'width=' + iWidth + ',height=' + iHeight + ',scrollbars=yes=resizable=yes,status=yes,toolbars=yes'); return false;
}

function prepAdminTools() {

    jQuery(".adminMenuItem").each(function(e) {
        if (jQuery(this).attr("rel") != null && jQuery(this).attr("rel").length > 0) {
            jQuery(this).attr("href", "javascript:openCWin(" + getGroupId() + ", '" + jQuery(this).attr("rel") + "');");
        };
    }); 
}

function navTo(sUrl) {
    window.location.href = sUrl; 
}

function reWireGrids() {
    try 
    {
        if (jQuery(".UnSelectedTab") != null) {
            jQuery(".UnSelectedTab").hover(function() {
                jQuery(this).removeClass("UnSelectedTab").addClass("UnSelectedTabMo");
            },
            function() {
                jQuery(this).removeClass("UnSelectedTabMo").addClass("UnSelectedTab");
            });
        }
        
        if (jQuery(".AltGridRow") != null) {
            jQuery(".AltGridRow,div.AltGridRow").mouseover(function() {
                jQuery(this).removeClass("AltGridRow").addClass("MoGridRow");
            }).mouseout(function() {
                jQuery(this).removeClass("MoGridRow").addClass("AltGridRow");
            });
        }

        if (jQuery(".NormGridRow") != null) {
            jQuery(".NormGridRow,div.NormGridRow").mouseover(function() {
                jQuery(this).removeClass("NormGridRow").addClass("MoGridRow");
            }).mouseout(function() {
                jQuery(this).removeClass("MoGridRow").addClass("NormGridRow");
            });
        }

        if (jQuery(".ActiveDiv") != null) {
            jQuery(".ActiveDiv,div.ActiveDiv").mouseover(function() {
                jQuery(this).removeClass("ActiveDiv").addClass("MoGridRow");
            }).mouseout(function() {
                jQuery(this).removeClass("MoGridRow").addClass("ActiveDiv");
            });

            jQuery("div.ActiveDiv").css("padding", "3px");
        }

        if (jQuery(".straightBarWrapper") != null && jQuery(".straightBarActiveTab") != null && jQuery(".straightBarNormalTab") != null) {
            if (jQuery(".straightBarWrapper").height() != null) {
                jQuery(".straightBarActiveTab").mouseover(function() {
                    jQuery(this).removeClass("straightBarActiveTab").addClass("straightBarMouseOverTab");
                }).mouseout(function() {
                    jQuery(this).removeClass("straightBarMouseOverTab").addClass("straightBarActiveTab");
                });

                jQuery(".straightBarNormalTab").mouseover(function() {
                    jQuery(this).removeClass("straightBarNormalTab").addClass("straightBarMouseOverTab");
                }).mouseout(function() {
                    jQuery(this).removeClass("straightBarMouseOverTab").addClass("straightBarNormalTab");
                });
            }
        }  
    }
    catch (err) {
        interferingScripts = true; 
    } 
}

var applyFaceBox = function() {
    jQuery('img[rel*=facebox],a[rel*=facebox],[rel*=facebox]').facebox();
}

function wireUi() {

    
    // for each TD of class blkbgl or blkbgr, if it has a background-image, set the background-color to transparent.
    jQuery('.blkbgl, .blkbgr').each(function() {
        if (jQuery(this).css("background-image") != null && jQuery(this).css("background-image").length > 0) {
            jQuery(this).css("background-color", "transparent");
        }
    });

    try {
        jQuery('span[rel*=instSpanner]').mouseover(function() {
            $id = jQuery(this).attr('id');
            if (jQuery('#instTools' + $id.toString()) != null) {
                jQuery('#instTools' + $id.toString()).fadeIn();
            }
        }).mouseout(function() {
            $id = jQuery(this).attr('id');
            if (jQuery('#instTools' + $id.toString()) != null) {
                jQuery('#instTools' + $id.toString()).fadeIn();
            }
        });
    

        reWireGrids();

        prepAdminTools(); 
          
        jQuery('.ToolLinkButton').hover(function() { jQuery(this).addClass("ui-state-hover"); }, function() { jQuery(this).removeClass("ui-state-hover"); }); 
        
        jQuery.growl.settings.displayTimeout = 15000; 
        jQuery.growl.settings.noticeElement(jQuery('.notice'));

    } catch (err) {
        interferingScripts = true; 
    }

}

function growl(sTitle, sMsg) {
    try {
        jQuery.growl(sTitle, sMsg);
    } catch (growlErr) {
        interferingScripts = true; 
    } 
}

var handleScriptError = function(oExceptionProperties) {
    var sExceptionDescription = oExceptionProperties.description;
    if (document.getElementById) { // DOM3 = IE5, NS6
        var oNotification = document.getElementById('errorNotification');
        if (oNotification != null) {
            oNotification.style.display = 'block';
            oNotification.innerHTML = '<b>Error on Page</b>: There is an error with javascript on the page (possibly admin-created custom javascript), that is interfering ' +
                    'with the normal functionality of the site.  Until the problem is located and resolved (or custom javascript removed), certain functionality may not behave as ' +
                    'expected.  Note to guild site admins: the description of the error is: ' + sExceptionDescription;
        }
    }

}



var ddrivetip = function(sNull) {
    // This was put in to override the re-placement of the direct drive script, which 
    // causes problems with the .Net framework and jQuery.
}
        

/*
* Tooltip 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.tooltip = function() {
    /* CONFIG */
    xOffset = 10;
    yOffset = 20;
    // these 2 variable determine popup's distance from the cursor
    // you might want to adjust to get the right result		
    /* END CONFIG */
    $("a.tooltip,div.tooltip,input[type=button].tooltip,button.tooltip,input.tooltip,img.tooltip,li.tooltip").hover(function(e) {
        this.t = this.title;
        this.title = "";
        $("body").append("<p id='tooltip'>" + this.t + "</p>");
        $("#tooltip")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function() {
	    this.title = this.t;
	    $("#tooltip").remove();
	});
    $("a.tooltip,div.tooltip,input[type=button].tooltip,input.tooltip,button.tooltip,img.tooltip,li.tooltip").mousemove(function(e) {
        $("#tooltip")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px");
    });
};
