﻿$.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
			}
		});
	});

	$("a.tooltip").ToolTip({ className: 'dictinfo', position: 'bottom', delay: 300,
		onShow: function() { $('#tooltipHelper #tooltipURL').text(''); }
	})
	$("a.pdftooltip").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');
		
	});

});
