﻿$.fn.makeAbsolute = function(rebase) { return this.each(function() { var el = $(this); var pos = el.position(); el.css({ position: "absolute", marginLeft: 0, marginTop: 0, top: pos.top, left: pos.left }); if (rebase) el.remove().appendTo("body"); }); }

var obj = null;

function checkHover() {
	if (obj) { obj.removeClass('open');  }
}

$(document).ready(function() {
    //$("#TabContainer > ul").tabs();
    // Add the page method call as an onclick handler for the div.
    /*
    $(".getinvest").click(function() {
    var el = this;
    var logos = $(el).parent().parent().parent();
    var resultcontainer = $(logos).parent().find('.infocontainer');
    $(resultcontainer).html("<img src=\"/Templates/Public/Images/ajax-loader.gif\" class=\"loadingicon\" alt=\"loading\" />");
    $.ajax({
    type: "POST",
    url: "/Templates/Public/WebServices/AjaxService.asmx/GetInvestment",
    data: "{'pageid':'" + $(this).attr('rel') + "','lang':'" + $('html').attr('lang') + "'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    processData: false,
    cache: false,
    success: function(msg, status) {
    // Replace the div's content with the page method's return.
    $(resultcontainer).html(msg.d);
    var logolinks = $(logos).find('.getinvest');
    jQuery.each(logolinks, function() {
    if (this == el) {
    if (!$(this).hasClass('selected')) {
    $(this).addClass('selected');
    }
    }
    else if ($(this).hasClass('selected')) {
    $(this).removeClass('selected');
    }
    });
    },
    error: function(xhr, msg, e) {
    alert(msg + ', ' + e); //Error Callback
    }
    });
    });
    */
    $("#investment-logos ul li a").mouseenter(function() {
        $("#investment-logos ul li").removeClass("selected");
        $(this).parent().addClass("selected");
        var tooltip = $("#investment-tooltip");
        var index = $("#investment-logos ul li.show ul li").index($(this).parent());
        var top = Math.ceil((index + 1) / 3) * 75;
        tooltip.css("top", top + "px");
        tooltip.attr("class", "tooltip-arrow" + index % 3);
        $.ajax({
            type: "POST",
            url: "/Templates/Public/WebServices/AjaxService.asmx/GetInvestment",
            data: "{'pageid':'" + $(this).attr('rel') + "','lang':'" + $('html').attr('lang') + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            processData: false,
            cache: false,
            success: function(msg, status) {
                // Replace the div's content with the page method's return.
                tooltip.find("#tooltip-content").html(msg.d).end().show();

            },
            error: function(xhr, msg, e) {
                alert(msg + ', ' + e); //Error Callback
            }
        }, function() { });
    }).mouseleave(function() {
        $(this).parent().removeClass("selected");
        $("#investment-tooltip").hide();
    });

    $("#tabbed-nav li a").click(function(e) {
        e.preventDefault();
        $("#investment-tooltip").hide();
        $("#tabbed-nav li a").removeClass('selected');
        $(this).addClass('selected');
        $("#TabContainer h2").text($(this).text());
        $("#investment-logos ul li").removeClass("show");
        $('#' + $(this).attr('rel')).addClass("show"); /*.find("a").first().trigger("mouseenter");*/
        return false;
    });
    $("#investment-logos ul li a").first().trigger("mouseenter");

    $("a.tooltip").ToolTip({ className: 'dictinfo', position: 'bottom', delay: 300,
        onShow: function() { $('#tooltipHelper #tooltipURL').text(''); }
    })
    $("a.pdftooltip, a.audiotooltip").ToolTip({ className: 'pdfinfo', position: 'right',
        onShow: function() { $('#tooltipHelper #tooltipURL').text(''); }
    })

    $('.imageholder a').click(function(e) {
        e.preventDefault();
        $("#ModalContent").modal();
        // load the contact form using ajax
        $.get(this.href + '?ajax=true', function(data) {
            // create a modal dialog with the data
            $("#ModalContent").html(data);
        });
    });

    $('a.trigger').click(function(e) {
        e.cancelBubble = true;
        e.returnValue = false;

        if (e.stopPropagation) {
            e.stopPropagation();
            e.preventDefault();
        }
    });
    $('.dlmulti').hover(function() {
        $(this).addClass('open');
        $(this).find('.dlmenu').makeAbsolute();
        obj = $(this);
    }, function() {
        obj.removeClass('open');

    });

});

