
function initProfileTooltip() {
	$('a.tips').cluetip(
	{
		cluetipClass: 'jtip', 
		arrows: true,
		positionBy: 'mouse',
		width: '375px', 
		height: 'auto',
		ajaxCache: true,
		hoverIntent: {
              sensitivity:  3,
              interval:     100,
              timeout:      000
		},
		sticky: true,
		closePosition: "title",
		waitImage: true,
		mouseOutClose: true,
		fx: {
			open: 'fadeIn',
			openSpeed: '200',
			closeFXSpeed: '200'
		},
		activation: 'hover',
		clickThrough : true,
		waitImage: true
	});
	/*
	 * QTIP code
	 
	if( $.browser.msie ) {
		var wdth = { min: 360 };
	} else {
		var wdth = "auto";
	}
	var wndw = $(window).width() / 2;
	$(".tips").each( function() {
		var cornertarget = "";
		var cornertooltip = "";
		var adjustx;
		if( $(this).position().left > wndw ) {
			cornertarget = "bottomLeft";
			cornertooltip = "topRight";
			adjustx = 8;
		} else {
			cornertarget = "bottomRightt";
			cornertooltip = "topLeft";
			adjustx = -8;
		}
		$(this).qtip({
			content: {
				url: $(this).attr("rel"),
				title: {
					text: $(this).attr("title"),
					button: "Close"
				}
			},
			style: {
				name: 'light',
				border: {
					width: 1,
					radius: 5
				},
				width: wdth,
				tip: cornertooltip
			},
			show: {
				delay: 100,
				when: {
					event: "mouseover"
				}
			},
			hide: {
				fixed: true,
				when: {
					event: 'unfocus'
				}
			},
			position: {
				corner: {
					target: cornertarget,
					tooltip: cornertooltip
				},
				adjust: {
					x: adjustx,
					y: -10
				}
			}
		});
	});*/
}

$(document).ready(function() {
	$(".addtonetwork").live("click" , function() {
		var authid = $(this).attr("class").split(" ").slice(1,2);
		$.ajax(
		{
			type: "POST",
			url: localhost + "/Contact/AddUserToContactList",
			data: { id: authid },
			dataType: "json",
			async: false,
			time: 10,
			success: function( msg )
			{
				if(msg.success) {
					alert(msg.successmsg);
					initContactList();
				} else {
					if( msg.redirect ) {
						window.location = msg.url;
					} else {
						alert(msg.errormsg);
					}
				}
			}
		});
	});
	
	$(".contactuser").live("click", function() {
			var auth_id=$(this).attr("class").split(" ").slice(1,2);
			var getUse=this;
			$.post(localhost+"/Collaboration/checkContact",{
				contactid: auth_id
				},
				function(data){
					if(data.success){
						$(".token-input-token").remove();
						var name=$(getUse).attr("class").split(" ").slice(2,3);
						var html="<li class=\"token-input-token\"><p>"+name+"</p><span class=\"token-input-delete-token\">x</span></li>";
						$(".token-input-list").children().before(html);
						openLightbox("composeMailForm");
						$("#receiver").val(auth_id+",");
						$("#composeMailForm").css("z-index", "2000000000");
					}else{
						if( data.redirect ) {
							window.location = data.url;
						} else {
							alert(data.errormsg);
						}
					}
				},"json");
	});
	
	$("#Mail-Submit").live("click",function(){
		var title=escape($("#title").val());
		var receiver=$("#receiver").val();
		var content=escape($("#composeMailContent").val());
		var imgbox=".composeMailSuccessBox";
		var image="mailsentsuccessful.png";
		
		$(this).hide();
		$("#ajax_loader_Mail").show();
		if(title==""||receiver==""||content==""){
			alert("Please complete the form");
			$("#Mail-Submit").show();
			$("#ajax_loader_Mail").hide();
		}else{
			$.post(localhost+"/Inbox/sendMails",{
				title: title, 
				receiver: receiver,
				content:content
				},
				function(data){
					if(data.success){
						$("#Mail-Submit").show();
						$("#ajax_loader_Mail").hide();
						var htm = "<img src=\"" + localhost + "/Assets/images/" + image + "\" />";
						$(".token-input-token").remove();
						$("#title").val("");
						$("#receiver").val("");
						$("#composeMailContent").val("");
						$(imgbox).html(htm);
						$(imgbox).show();
						$(".contentComposeMailBox").hide();
						closecheck=false;
						closeTimeout();
						UpdateCount();
					}else{
						alert("Error ocurred, please try again later");
						$("#Mail-Submit").show();
						$("#ajax_loader_Mail").hide();
					}
			}, "json");
			return false;
		}
		return false;
	});
});

function closeTimeout() {
	var id = "";
	window.setTimeout(function() {
		$(".lightbox").each( function() {
			if( !$(this).is(":hidden") ) {
				id = $(this).attr("id");
			}
		});
		if( id != "" ) {
			closeLightbox( id );
		} else {
			return false;
		}
	}, 2000);
}
