/* needs jQuery */
var UserInfoWnd = function(options){
	var self = this;
	this.options = {};
	jQuery.extend(this.options, UserInfoWnd.defaults, options);
	
	if (!jQuery(this.options.mountpoint).length) return false; 
	
	this.content = this.options.template;
	
	this.content = this.content.replace(/#username#/ig, this.options.username);
	this.content = this.content.replace(/#id#/ig, this.options.userID);
	this.content = this.content.replace(/#company#/ig, this.options.company);
	this.content = this.content.replace(/#position#/ig, this.options.position);
	this.content = this.content.replace(/#telefon#/ig, this.options.telefon);
	this.content = this.content.replace(/#website#/ig, this.options.website);
	this.content = this.content.replace(/#email#/ig, this.options.email);
	this.content = this.content.replace(/#skype#/ig, this.options.skype);
	this.content = this.content.replace(/#fax#/ig, this.options.fax);
	this.content = this.content.replace(/#mobile#/ig, this.options.mobile);
	this.content = this.content.replace(/#languages#/ig, this.options.languages);
	this.content = this.content.replace(/#competencies#/ig, this.options.competencies);
	this.content = this.content.replace(/#ranking#/ig, this.options.ranking);
	this.content = this.content.replace(/#address#/ig, this.options.address);
	jQuery(this.options.mountpoint).append(this.content);
	
	if (jQuery('.usercard-'+this.options.userID,this.options.mountpoint).lenfth)
		jQuery('.usercard-'+this.options.userID,this.options.mountpoint).remove();
	
	this.dom = {};
	this.dom.wnd = jQuery('.usercard-'+this.options.userID)[0];
	
	var w = document.body.clientWidth,
		h = document.body.clientHeight;
	
	if (this.options.closable){
		
		jQuery(this.dom.wnd).append("<img class='close-handle' style='relative: absolute; top: 0; right: 0' src='/images/close.gif'/>");
		jQuery('.close-handle', this.dom.wnd).css({
			position: 'absolute',
			top: 0,
			right: 0,
			border: 'none',
			cursor: 'pointer'
		}).bind('click', function(){
			jQuery(self.dom.wnd).draggable('destroy').remove();
			delete self.options;
			delete self.content;
			delete self.dom;
		});
	}
	
	var scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	  //DOM compliant
		scrOfY = document.body.scrollTop;
	} else if( document.documentElement && document.documentElement.scrollTop ) {
	    scrOfY = document.documentElement.scrollTop;
	}
	
	jQuery(this.dom.wnd,this.options.mountpoint).//data('UserInfoWnd', self).
	css({
		position: 'absolute',
		opacity: 0
	}).show().
	css({
		top: /*scrOfY +*/ h / 2 - this.dom.wnd.clientHeight / 2,
		left: w / 2 - this.dom.wnd.clientWidth / 2
	}).animate({opacity: 1}, 1000).draggable();
	
	return this;
}

jQuery( function(){
	UserInfoWnd.defaults = {
		mountpoint: document.body,
		closable: true,
		userID: 0,
		username: '',
		company: '',
		country: '',
		'function': '',
		fax: '',
		mobile: '',
		languages: '',
		position: '',
		telefon: '',
		website: '',
		skype: '',
		email: '',
		ranking: '',
		competencies: '',
		address: '',
		template: "<div style='z-index: 100; display: none' class='usercard-#id# userCard w1'>" +
				"<div class='inner'>" +
				"<h2><a onclick='make_request_from_this(this); return false;' href='"+location.protocol+'//'+location.host+'/'+"#username#'>#username#</a></h2>" +
				"<a class='userMail' href='mailto: #email#' >#email#</a>"+
				"<div class='userImgWrap'><img border=0 src='/smallphoto.php?pro=#id#'/></div>"+
				"<dl><dt>Company</dt><dd>#company#</dd></dl>"+
				"<dl><dt>Position</dt><dd>#position#</dd></dl>"+
				"<dl><dt>Ranking</dt><dd>#ranking#</dd></dl>"+
				"<dl><dt>Telefon</dt><dd>#telefon#</dd></dl>"+
				"<dl><dt>FAX</dt><dd>#fax#</dd></dl>"+
				"<dl><dt>Mobile</dt><dd>#mobile#</dd></dl>"+
				"<dl><dt>Website</dt><dd><a href='#website#'>#website#</a></dd></dl>"+
				"<dl><dt>Skype</dt><dd class='skype'>#skype#</dd></dl>"+
				"<dl><dt>Address</dt><dd>#address#</dd></dl>"+
				"<dl><dt>Languages</dt><dd>#languages#</dd></dl>"+
				"<dl><dt>Competencies</dt><dd>#competencies#</dd></dl>"+
				"</div>" +
				"</div>"
	}
});