function O2O( obj1, obj2 ){
  if( typeof( obj1 ) == 'undefined' ) return false;
  if( typeof( obj2 ) == 'undefined' ) return false;       
  for( var key in obj2 ){                                                  
		if( typeof obj2[ key ] == 'undefined' ){
			D.console.error( obj2, key );
		}
    if( obj2[ key ].constructor == Object ){
      if( ! obj1[ key ] ) obj1[ key ] = {};                                    
      O2O( obj1[ key ], obj2[ key ] );
    } else {
			obj1[ key ] = obj2[ key ];      
    }
  }
  return true;  
};
if( typeof D == 'undefined' ){
	var D = {};
}
var DBase = {
	mouseX:0,
	mouseY:0,
	initMouse:function(){
		if( D.initMouse.ok ){
			return;
		}
		if( document.body ){
			$( document.body ).mousemove( function( e ){
				D.mouseX = e.clientX;
				D.mouseY = e.clientY;
			} );
			D.initMouse.ok = true;
		}
		setTimeout( D.initMouse, 100 );
	},
	
	console:{
		info:function(){
			if( typeof console == 'object' && typeof console.info == 'function' ){
				console.info.apply( console, arguments );
			}
		},
		error:function(){
			if( typeof console == 'object' && typeof console.error == 'function' ){
				console.error.apply( console, arguments );
			}
		},
		warn:function(){
			if( typeof console == 'object' && typeof console.warn == 'function' ){
				console.warn.apply( console, arguments );
			}
		},
		debug:function(){
			if( typeof console == 'object' && typeof console.debug == 'function' ){
				console.debug.apply( console, arguments );
			}
		},
		log:function(){
			if( typeof console == 'object' && typeof console.log == 'function' ){
				console.log.apply( console, arguments );
			}
		}
	},
	
	ajaxPostData:function( el ){
		var data = {};
		$( 'input, textarea, select', el ).each( function(){
			if( this.type == 'checkbox' || this.type == 'radio'){
				if( this.checked ){
					data[ this.getAttribute( 'name' ) ] = this.value;
				}
			} else {
				data[ this.getAttribute( 'name' ) ] = this.value;
			}
		} );
		return data;
	},
	
	ajaxPost:function( el, url, id, par ){
		if( ! par ){
			par = {};
		}
		var data = this.ajaxPostData( el );
		if( typeof id == 'object' ){
			var node = id;
		} else {
			var node = document.getElementById( id );
		}
		if( par.overlay ){
			var position = getStyle( node, 'position' );
			if( position == 'static' ){
				node.style.position = 'relative';
			}
			var overlay = mkE( {
				tag:'div',
				className:'rqOverlay',
				style:{
					height:node.offsetHeight + 'px',
					width:node.offsetWidth + 'px'
				}
			} ).append( node );
			if( ! $.browser.msie ){ 
				$( overlay ).animate( { opacity:0.9 }, 6000 );
			}
		} else {
			node.innerHTML = '<img src="' + ( typeof pimg != 'undefined' ? pimg : 'http://ifrype.com' ) + '/img/load.gif" />';
		}
		$.post( url, data, function( html ){
			node.innerHTML = html;
			evalScriptHTML( html );
			if( par.callback ){
				par.callback( { form:el, node:node}, par );
			}
		} );
		D.console.info( data );
		return false;
	},
	
	getChildByTagName:function( node, tagName ){
		var re = [];
		for( var k in node.childNodes ){
			if( node.childNodes[ k ].tagName && node.childNodes[ k ].tagName.toLowerCase() == tagName.toLowerCase() ){
				re.push( node.childNodes[ k ] );
			}
		}
		return re;
	},
	
	sendMail:function(fid){
		InfoBox.iframe('/messages/ibox.php?p=write&fid=' + fid, { width:700 });//, height:300
		return false;
	},
	
	confirmDelete:function(){
		return confirm( xGlobal[ 'confirm delete' ] || 'Are you sure?' );
	},
	
	idPath:function( id ){
		id = String( id );
		if( id.length < 6 ){
			for( var i = 6 - id.length; i > 0; i -- ){
				id = '0' + id;
			}
		}
		return id.substr( id.length - 6, 3 ) + '/' + id.substr( id.length - 3, 3 ) + '/';
	},
	
	imgUrl:function( $type, $id, $v, $size ){
		var $folder;
		switch( $type ){
			default:
				$folder = $type;
			case 'tmp':	
				return D.idPicDomain( $id ) + 'tmp/' + String( $id ).substr(0,2) + '/' + D.getImgPrefix( $size ) + $id + '.jpg'
		}
		var $re = D.idPicDomain( $id ) + $folder;
		$re += '/' + D.idPath( $id ) + ( $v ? 'v' + $v + '/' : '' ) + D.getImgPrefix( $size ) + $id + '.jpg';	
		return $re;
	},
	
	getImgPrefix:function( $size ){
		var $prefix = $size;
		switch( $size ){
			case 'icon':
				$prefix = 'i_';
				break;
			case 'small':
				$prefix = 'sm_';
				break;
			case 'middle':
				$prefix = 'm_';
				break;
			case 'large':
				$prefix = 'l_';
				break;
		}
		return $prefix;
	},
	
	idPicDomain:function( $id ){
		var s = new String( $id );
		return 'http://i' + s.substr( s.length - 1, 1 ) + '.ifrype.com/';
	},
	
	reload:function(){
		document.location.href=document.location.href.split('#')[0];
	},
	
	newWindow:function( urlOrLink, name, par ){
		if( ! par ){
			par = {};
		}
		if( typeof par.directories == 'undefined' ){
			par.directories = 1;
		}
		if( typeof par.location == 'undefined' ){
			par.location = 1;
		}
		if( typeof par.resizable == 'undefined' ){
			par.resizable = 1;
		}
		if( typeof par.toolbar == 'undefined' ){
			par.toolbar = 1;
		}
		if( typeof par.scrollbars == 'undefined' ){
			par.scrollbars = 1;
		}
		if( typeof par.status == 'undefined' ){
			par.status = 1;
		}
		var url = urlOrLink;
		if( typeof urlOrLink == 'object' && urlOrLink.href ){
			url = urlOrLink.href;
			name = urlOrLink.target;
		}
		var windowOpenPar = [];
		for( var k in par ){
			windowOpenPar.push( k + '=' + par[ k ] );
		}
		return window.open( url, name, windowOpenPar.join( ',' ) );
	},
	
	changeProfilePic:function( get, reload ){
		return InfoBox.open( '/account/pic.php?' + ( get ? get : '' ), { width:500, onClose:( reload ? D.reload : function(){} ) } );
	},
	
	stopPropagation:function( e ){
		if( ! e ){
			e = window.event;
		}
		if( e.stopPropagation ){
			e.stopPropagation();
		}
		e.cancelBubble = true;
		return e;
	},
	
	position:function( el, parent ){
		var re = {
			left:findPosX( el, parent ),
			top:findPosY( el, parent )
		};
		re.x = re.left + document.body.scrollLeft + document.getElementById( 'outermost' ).scrollLeft;
		re.y = re.top + document.body.scrollTop + document.getElementById( 'outermost' ).scrollTop;
		return re;
	},
	
	checkCtrlEnter:function( e ){
		return ( e.keyCode == 13 || e.keyCode == 10 ) && ( e.ctrlKey || e.metaKey );
	},
	
	addPicsGallery:function( par ){
		if( empty( par.urls ) ){
			return false;
		}
		if( ! par.urls.length ){
			par.urls = [ par.urls ];
		}
		var href = '/gallery/ext/add.php?albumTitle=' + encodeURIComponent( par.title || '' );
		for( var k in par.urls ){
			href += '&u[]=' + encodeURIComponent( par.urls[ k ] );
		}
		InfoBox.iframe( href, { width:640, height:400 } );
		return false;
	},
	
	loadingOverlay:function( node ){
		if( typeof node == 'string' ){
			node = document.getElementById( node );
		}
		if( ! node ){
			D.console.error( 'D.loadOverlay( node ) - not element' );
			return false;
		}
		if( node._drOverlay ){
			node._drOverlay.remove();
		}
		position = getStyle( node, 'position' );
		if( position == 'static' ){
			node.style.position = 'relative';
		}		
		var overlay = node._drOverlay = mkE( {
			tag:'div',
			className:'rqOverlay',
			style:{
				height:node.offsetHeight + 'px',
				width:node.offsetWidth + 'px'
			}
		} ).append( node );
		if( ! $.browser.msie ){ 
			$( overlay ).animate( { opacity:0.9 }, 6000 );
		}
		return overlay;
	},
	
	removeLoadingOverlay:function( node ){
		if( typeof node == 'string' ){
			node = document.getElementById( node );
		}
		if( ! node ){
			D.console.error( 'D.removeLoadOverlay( node ) - not element' );
			return false;
		}
		if( node._drOverlay ){
			node._drOverlay.remove();
			return true;
		}
		return false;
	},
	
	reloadCSS:function(){
		var links = document.getElementsByTagName( 'link' );
		var t = ( new Date() ).getTime();
		for( var i = 0; i < links.length; i ++ ){
			if( links.item( i ).type == 'text/css' ){
				links.item( i ).href = links.item( i ).href.split( '?' )[ 0 ] + '?' + t;
			}
		}
	}
};
O2O( D, DBase );
D.initMouse();

function rq( url,element_id, par ){
	if( typeof par != 'object' ){
		par = {};
	}
	if( typeof element_id == 'object' ){
		var node = element_id; 
	} else {
		var node = document.getElementById( element_id );
	}
	var position, overlay;
	if( node ){
		if( par.overlay ){
			overlay = D.loadingOverlay( node );
		} else {
			if( ! par.withoutLoading ){
				node.innerHTML = '<img class="rqLoading" src="' + ( typeof pimg != 'undefined' ? pimg : 'http://ifrype.com' ) + '/img/load.gif" />';
			}
		}
		if( par.scrollIntoView ){
			$( '#outermost' ).animate( {
				scrollTop:node.offsetTop - 40
			} );
		}
	}
	$.get( url, function( html, status ){
		if( ! node ){
			D.console.error( 'rq - no element' );
			return false;
		}
		switch( status ){
			case 'timeout':
			case 'error':
				if( overlay ){
					overlay.remove();
				}
				alert( status );
				break;
		}
		if( position ){
			node.style.position = position;
		}		
		if( par.replace ){
			if( ! node.parentNode ){
				return;
			}
			var newNode = mkE( {
				tag:node.parentNode.tagName,
				prop:{
					innerHTML:html
				}
			} );
			var nodeChilds = newNode.childNodes;
			var nodeChildsArr = [];
			for( var i = 0; i < nodeChilds.length; i ++ ){
				nodeChildsArr.push( nodeChilds[ i ] );				
			}
			for( var k in nodeChildsArr ){
				D.insertBefore( nodeChildsArr[ k ], node );
			}
			removeNode( node );
		} else {
			node.innerHTML = html;
		}
		evalScriptHTML( html );
		if( par.onload ){
			par.onload();
		}
		Draugiem.Emo.load( element_id );
		if( Draugiem.Inspekt ){
			Draugiem.Inspekt.init();
		}
		if($.browser.msie && $.browser.version<7){
			//$('#'+element_id).pngFix();
		}
	} );
	return false;
} // rq

var Draugiem={
	version:'0.1'
};
D.blink = Draugiem.blink = function( par ){  
  if( par.node.fx_blink ) return;
  if( ! par.color1 ) par.color1 = '';
  if( ! par.color2 ) par.color2 = '#F00';
  if( ! par.sk ) par.sk = 2;
  var sk = 0;
  par.node.style.background = par.color1;
  par.node.fx_blink = true;
  function blink_(){  
    setTimeout( function(){      
      if( ! par.type || par.type == 'background' ) par.node.style.background = par.color2;
      if( par.type == 'border' ) par.node.style.borderColor = par.color2;
			if( par.type == 'className' ) addClassName( par.node, par.className || 'blink' );
      setTimeout( function(){
        sk ++;      
        if( ! par.type || par.type == 'background' ) par.node.style.background = par.color1;
        if( par.type == 'border' ) par.node.style.borderColor = par.color1;
				if( par.type == 'className' ) removeClassName( par.node, par.className || 'blink' );
        if( sk < par.sk ) blink_(); else par.node.fx_blink = false;       
      }, 100 );
    }, 80 );
  }
  blink_();
}; // function blink
	
	
Draugiem.Cookie = {
	version: '0.1',
	create: function(name,value,days,path){
		if(  ! path ){
			path = '/';
		}
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=" + path;
	},
	read: function(name){
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;		
	},
	erase: function(name){
		this.create(name,"",-1);
	}
}

Draugiem.Tools = {
	version: '0.1',
	callback:false,
	lastTarget:false,
	inArray: function(arr,value){
		var i;
		for (i=0; i < arr.length; i++) {
			if (arr[i] == value) {
				return true;
			}
		}
		return false;
	},
	LTrim: function(value){
		var re = /\s*((\S+\s*)*)/;
		return value.replace(re, "$1");
	},
	RTrim: function(value){
		var re = /((\s*\S+)*)\s*/;
		return value.replace(re, "$1");		
	},
	trim: function(value){
		return this.LTrim(this.RTrim(value));
	},
	dhtmlLoadScript: function(url){
		var e = document.createElement("script");
		e.src = url;
		e.type="text/javascript";
		document.getElementsByTagName("head")[0].appendChild(e);
		//D.console.info('DLScript: '+url);
	},
	dhtmlLoadCSS: function(url){
		var e = document.createElement("link");
		e.rel = "stylesheet";
		e.type = "text/css";
		e.href = url
		document.getElementsByTagName("head")[0].appendChild(e);
		//D.console.info('dlCSS: '+url);
	},
	loadScript: function(url, callback, hide){
		var f = arguments.callee;
		if (!("queue" in f))
			f.queue = {};
		var queue =  f.queue;
		if (url in queue) { 
			if (callback) {
				if (queue[url]) 
					queue[url].push(callback);
				else 
					callback();
			}
			return;
		}
		queue[url] = callback ? [callback] : [];
		var script = document.createElement("script");
		script.type = "text/javascript";
		script.onload = script.onreadystatechange = function(){
			if (script.readyState && script.readyState != "loaded" && script.readyState != "complete")
				return;
			script.onreadystatechange = script.onload = null;
			while (queue[url].length)
				queue[url].shift()();
			queue[url] = null;
		};
		script.src = url;
		document.getElementsByTagName("head")[0].appendChild(script);
		if(typeof(hide)=='undefined'){
			//D.console.info('load '+url);
		}
	},	
	
	rq: rq
}

Draugiem.Forms ={
	version: '0.1',
	defaults: {loading: '...'},
	formOptions: false,
	formCancel:false,
	load: function(target){
		var cnt=0;
		var loadTime=new Date();
		if(typeof($.fn.ajaxSubmit)!='undefined' && $((target?'#'+target+' ':'')+'form[rel=form]').size()){
			if(!$('#formResp')[0]){
				$('#outermost').append('<div id="formResp"></div>');
			}
			Draugiem.Forms.formOptions = { 
				target: '#formResp',
				beforeSubmit: Draugiem.Forms.correctRequest,
				success: Draugiem.Forms.formSuccess
			}; 
			cnt=$((target?'#'+target+' ':'')+'form[rel=form]').ajaxForm(Draugiem.Forms.formOptions).size();			
		}
		var now=new Date();
		//D.console.info(cnt+" forms "+(target?'@'+target+' ':'')+((now-loadTime)/1000).toFixed(2)+"sec");		
	},
	correctRequest: function(formData,jqForm,options){
		if(Draugiem.Forms.formCancel){
			formData.push({ name: 'cancel', value: 'yes'});
			Draugiem.Forms.formCancel=false;
		}
		Draugiem.Forms.info();
		formData.push({ name: 'ajax', value: 'yes'});
		window.setTimeout(function(){InfoLite.close();},1000);
	},
	formSuccess: function(formData,jqForm,options){
		InfoLite.close();
	},	
	info: function(){
		InfoLite.open({text:'<div style="border:1px solid #ccc; margin:5px; background-color:white;padding:7px;font-weight:bold">'+Draugiem.Forms.defaults.loading+'</div>'});
	}	
}

Draugiem.sayExtPost = function( title, url, titlePrefix, text , closeFunction){
 var href = '/say/ext/add.php?title=' + encodeURIComponent( title ) +
  '&link=' + encodeURIComponent( url ) +
  ( titlePrefix ? '&titlePrefix=' + encodeURIComponent( titlePrefix ) : '' ) +
	( text ? '&text=' + encodeURIComponent( text ) : '' );
 InfoBox.iframe( href, { width:400, height:400, onClose: closeFunction?closeFunction:''} );
 return false;
};

function getStyle(el, prop){
  if( document.defaultView && document.defaultView.getComputedStyle ){
    return document.defaultView.getComputedStyle( el, null )[ prop ];
  } else if ( el.currentStyle ){
    return el.currentStyle[ prop] ;
  } else {
    return el.style[ prop ];
  }
}

function evalScripts( par ){
	var bSaf = (navigator.userAgent.indexOf('Safari') != -1);
	var bOpera = (navigator.userAgent.indexOf('Opera') != -1);
	var bMoz = (navigator.appName == 'Netscape');
	var node = par.node;
	/* IE wants it uppercase */
	var st = node.getElementsByTagName('SCRIPT');
	var strExec;
	for( var i = 0; i < st.length; i++ ){
		if ( bSaf ){
			strExec = st[ i ].innerHTML;
			st[ i ].innerHTML = "";
		} else if( bOpera ){
			strExec = st[i].text;
			st[ i ].text = "";
		} else if( bMoz ){
			strExec = st[ i ].textContent;
			st[ i ].textContent = "";
		} else {
			strExec = st[ i ].text;
			st[ i ].text = "";
		}
		try {
			var x = document.createElement( "script" );
			x.type = "text/javascript";
			/* In IE we must use .text! */
			if ( bSaf || bOpera || bMoz )
				x.innerHTML = strExec;
			else x.text = strExec;
			document.getElementsByTagName( "head" )[0].appendChild(x);
		} catch(e) {
			D.console.error( e );
		}
	}
}

function evalScriptHTML( html ){
	var np, p = 0;	
	while( ( np = html.indexOf( '<script', p ) ) != -1 ){
		p = html.indexOf( '>', np );
		np = html.indexOf( '</script>', p );
		if( np != -1 ){
			try{
				eval.call( window, html.substr( p + 1, np - p -1 ) );
				//D.console.info( html.substr( p + 1, np - p -1 ) );
			} catch( e ){
				D.console.error( e );
			}
		}
	}
}

// +++ DOM +++
function mkE( par ){ 
	if( ! par.tag && ! par.text ) return false;
	if( par.tag ){
		var elm = document.createElement( par.tag );    	
		if( par.attr ) for( key in par.attr ) elm.setAttribute( key, par.attr[ key ] );			
		// append childs
		if( par.els && par.els instanceof Array ) for( ii = 0; ii < par.els.length; ii++ ) if( par.els[ ii ] ){
			if( par.els[ ii ].append ) par.els[ ii ].append( elm ); else elm.appendChild( par.els[ ii ] );
		} 
		if( par.els && ! par.els instanceof Array ) elm.appendChild( par.els );
		// set properties
		if( par.prop ) O2O( elm, par.prop );	
		if( par.id ) elm.id = par.id;
		if( par.className ) elm.className = par.className;	
		if( par.style )	O2O( elm.style, par.style );	
		if( par.text ) elm.appendChild( document.createTextNode( par.text ) );
		elm.append = mkE.append;
		elm.remove = mkE.remove;
		return elm;
	}
	if( par.text ){
		elm = document.createTextNode( par.text );
		elm.append = mkE.append;
		elm.remove = mkE.remove;
		return elm;
	}
}
mkE.append = function( node ){
	if( typeof node == 'string' ){
		node = document.getElementById( node );
	}
	node.appendChild( this );
	return this;
};
mkE.remove = function(){
	removeNode( this );
	return this;
};
mkE.clear = function(){
	clearNode( this );
	return this;
};

function removeNode( node ){
	if( node.parentNode && node.parentNode.tagName ){
		return node.parentNode.removeChild( node ); 
	} else {
		return false;
	}
}

function clearNode( node ){
	var n;
	while( n = node.firstChild ){
		removeNode( n );
	}
	return node;
}

function addClassName( node, className ){
	var cn = node.className.split( ' ' );		
	var is = false;
	for( var i = 0; i < cn.length; i ++ ) if( cn[ i ] == className ) is = true;	
	if( ! is ) cn.push( className );
	node.className = cn.join( ' ' );
	return node;
};
function removeClassName( node, className ){
	var cn = node.className.split( ' ' );
	var cnr = [];	
	for( var i = 0; i < cn.length; i ++ ) if( cn[ i ] !== className ) cnr.push( cn[ i ] );	
	node.className = cnr.join( ' ' );
	return node;
};
function existsClassName( node, className ){
	var cn = node.className.split( ' ' );
	for( var i = 0; i < cn.length; i ++ ) if( cn[ i ] == className ) return true;	
	return false;
};

function findPosX( obj, parent ){
	var curleft = 0;
	if( obj.offsetParent ){
		while ( obj.offsetParent ){
			curleft += obj.offsetLeft
			if( obj.offsetParent === parent ){
				break;
			}
			obj = obj.offsetParent;			
		}
	} else if( obj.x ){
		curleft += obj.x;
	}
	return curleft;
};
 
function findPosY( obj, parent ){
	var curtop = 0;
	if ( obj.offsetParent ) {
		while( obj.offsetParent ){
			curtop += obj.offsetTop
			if( obj.offsetParent === parent ){
				break;
			}
			obj = obj.offsetParent;
		}
	} else if ( obj.y ){
		curtop += obj.y;
	}
	return curtop;
};
// --- DOM ---

// +++ infobox v3 +++
var InfoBox3 = {
	
	defaults:{
		width:600,
		height:300
	}, // defaults
	
	init:function( par ){
		var this_ = this;
		if( ! this._ ){
			this._ = {};
			var td;
			this._.node = mkE( {
				tag:'div',
				prop:{
					id:'infobox3',
					style:{
						zIndex:InfoBox.zIndex ++
					}
				},
				els:[
					this._.overlay = mkE( {
						tag:'div',
						prop:{
							id:'infobox3_overlay'
						}						
					} ),
					mkE( {
						tag:'table',						
						id:'infobox3_content_table',
						els:[
							mkE( {
								tag:'tbody',
								els:[
									mkE( {
										tag:'tr',
										els:[
											td = mkE( {
												tag:'td',
												className:'infobox3Td',
												attr:{
													align:'center',
													valign:'middle'
												}
											} )
										]
									} )
								]
							} )
						]
					} )
				]
			} );
			mkE( {
				tag:'table',
				id:'infobox3_content_table2',
				prop:{
					cellSpacing:'0'
				},
				els:[
					mkE( {
						tag:'tbody',
						els:[
							mkE( {
								tag:'tr',
								els:[
									mkE( {
										tag:'td',
										className:'infobox3Td',
										id:'infobox3_tl'
									} ),
									mkE( {
										tag:'td',
										className:'infobox3Td',
										id:'infobox3_tm'
									} ),
									mkE( {
										tag:'td',
										className:'infobox3Td',
										id:'infobox3_tr',
										els:[
											mkE( {
												tag:'div',
												prop:{
													style:{
														position:'relative',
														fontSize:'1px',
														width:'1px',
														height:'1px'
													}
												},
												els:[
													this._.closeButton = mkE( {
														tag:'div',
														id:'infobox3_closeButton',
														prop:{
															onclick:function(){
																this_.close();
															},
															onmouseover:function(){															
																addClassName( this, 'hover' );
															},
															onmouseout:function(){
																removeClassName( this, 'hover' );
															}
														}
													} ) // div.closeButton
												]
											} ) // div
										]
									} )
								]
							} ), // tr
							mkE( {
								tag:'tr',
								els:[
									mkE( {
										tag:'td',
										className:'infobox3Td',
										id:'infobox3_l'
									} ),
									this._.td = mkE( {
										tag:'td',
										className:'infobox3Td',
										els:[
											this._.box = mkE( {
												tag:'div',												
												id:'infobox3_box',												
												els:[
													this.content = this._.box_content = mkE( {
														tag:'div',
														id:'infobox3_box_content',
														style:{
															position:'relative'
														},
														els:[
															this.contentLite = this._.box_lite = mkE( {
																tag:'div',
																id:'infobox3_box_lite'
															} )
														]
													} )
												]
											} )
										]
									} ),
									mkE( {
										tag:'td',
										className:'infobox3Td',
										id:'infobox3_r'
									} )
								]
							} ), // tr
							mkE( {
								tag:'tr',
								els:[
									mkE( {
										tag:'td',
										className:'infobox3Td',
										id:'infobox3_bl'
									} ),
									mkE( {
										tag:'td',
										className:'infobox3Td',
										id:'infobox3_bm'
									} ),
									mkE( {
										tag:'td',
										className:'infobox3Td',
										id:'infobox3_br'
									} )
								]
							} )
						]
					} ) // tbody
				]
			} ).append( td );
		}
		this.setDefaults();
		this.append();
		this._.closeButton.style.display = ( par.withoutClose ? 'none' : '' );
		if( par.withoutFrames ){
			addClassName( this._.node, 'InfoBox3WithoutFrames' );
		} else {
			removeClassName( this._.node, 'InfoBox3WithoutFrames' );
		}
	}, // init:function
	
	setStyle:function( p ){
		//document.body.style.overflow = p ? 'hidden' : '';		
	},
	
	setDefaults:function(){
		this._.box_content.style.width = '';
		this._.box_content.style.height = '';
		this._.box_lite.style.width = '';
		this._.box_lite.style.height = '';		
	}, // setDefaults:function	
	
	close:function(){
		this.type = 'open';
		this.clearAutoResize();
		this.setStyle( false );
		if( this._ && this._.node.parentNode ){
			this.removeNode( this._.node );
			delete this._;
			if( this.onClose ){
				this.onClose();
			}			
			return true;
		} else {
			if( window.parent && window.parent !== window && window.parent.InfoBox ){
				return window.parent.InfoBox.close();
			}
			return false;
		}		
	}, // close:function
	
	append:function(){		
		document.body.appendChild( this._.node );
	}, // append:function
	
	clearAutoResize:function(){
		if( this.interval ){
			clearInterval( this.interval );
		}
	},
	
	autoResize:function(){
		var this_  = this;
		var height = 0;
		this.clearAutoResize();
		var resize = function(){			
			switch( this_.type ){
				case 'open':
						var el = this_._.box_content;
						if( el.scrollHeight < document.body.offsetHeight - 50 ){
							el.style.height = 'auto';
							break;
						}
						if( height != el.scrollHeight ){
							var dh = 0;
							if( $.browser.opera ){
								dh = 10;
							}
							this_.resizeTo( this_.par.width, 20 );
							this_.resizeTo( this_.par.width, el.scrollHeight + dh );
							height = el.scrollHeight;							
						}
						break;						
				case 'iframe':
					try{						
						var el = this_._.iframe.contentWindow.document.getElementById( 'iframe_content' );
						el.style.overflow = 'hidden';
						if( height != el.scrollHeight ){
							var dh = 0;
							if( $.browser.opera ){
								dh = 10;
							}							
							this_.resizeTo( this_.par.width, el.scrollHeight + dh );
							height = el.scrollHeight;
						}
					} catch( e ){
					}
					break;
				case 'html':
					try{
						var el = this_.content;
						if( height != el.scrollHeight ){
							var dh = 0;
							if( $.browser.opera ){
								dh = 10;
							}
							this_.resizeTo( this_.par.width, 50 );
							this_.resizeTo( this_.par.width, el.scrollHeight + dh );
							height = el.scrollHeight;
						}
					} catch( e ){					
					}
					break;
			}
		};
		resize();
		this.interval = setInterval( resize, 500 );
	},
	
	open:function( href, par ){
		this.type = 'open';
		this.clearAutoResize();
		if( typeof par == 'undefined' ){
			par = {};
		}
		this.par = par;
		this.onClose = ( typeof par == 'object' && par.onClose ? par.onClose : false );
		var this_ = this;		
		this.init( par );
		if( par.width && ! par.height ){
			this.content.style.width = par.width + 'px';
			this.content.style.overflow = 'hidden';
		}
		this._.overlay.onclick = function(){};
		this.setStyle( true );
		this.removeNode( this._.box_lite  );
		this._.td.appendChild( this._.box );		
		this.clearNode( this._.box_content );
		this_._.box_content.className = 'load';
		if( typeof par == 'undefined' ) var par = {};		
		$.get( href, function( html ){			
			if( par.onload_resize !== false ){
				if( par.width && par.height ){
					this_.resizeTo( par.width, par.height ); 
				} else if( par.width && ! par.height ){
					this_.autoResize();
				} else {
					this_.resizeTo( this_.defaults.width, this_.defaults.height );
				}
			}
			this_.content.style.overflow = '';
			this_._.box_content.innerHTML = html;
			this_._.box_content.className = 'with_padding';
			evalScriptHTML( html );
			if( par.onload ){
				try{
					par.onload.apply( this_ )
				} catch(e){
					D.console.error(e);
				}
			}
		} );
	}, // open:function
	
	html:function( html, par ){
		this.type = 'html';
		this.clearAutoResize();
		if( typeof par == 'undefined' ){
			par = {};
		}
		this.par = par;
		this.onClose = ( typeof par == 'object' && par.onClose ? par.onClose : false );
		var this_ = this;		
		this.init( par );
		this._.overlay.onclick = function(){};
		this.setStyle( true );
		this.removeNode( this._.box_lite  );
		this._.td.appendChild( this._.box );		
		this.clearNode( this._.box_content );		
		if( typeof par == 'undefined' ) var par = {};
		if( par.width && par.height ){
			this_.resizeTo( par.width, par.height );
		} else if( par.width && ! par.height ){
			this_.resizeTo( par.width, 100 );
			this_.autoResize();
		} else {
			this_.resizeTo( this_.defaults.width, this_.defaults.height );
		}
		this_._.box_content.innerHTML = html;			
		this_._.box_content.className = 'with_padding';
	},
			
	iframe:function( href, par ){
		this.type = 'iframe';
		this.clearAutoResize();
		if( typeof par == 'undefined' ){
			par = {};
		}
		this.par = par;
		this.onClose = ( typeof par == 'object' && par.onClose ? par.onClose : false );
		var this_ = this;
		this.init( par );
		this._.overlay.onclick = function(){};
		this.setStyle( true );
		this.removeNode( this._.box_lite  );
		this._.td.appendChild( this._.box );
		this.clearNode( this._.box_content );
		this_._.box_content.className = 'load';
		if( typeof par == 'undefined' ) var par = {};
		if( $.browser.msie ){
			var iframe = this._.iframe = document.createElement( '<iframe onload="if( this.onload_ ){ this.onload_(); }">' );
		} else {
			var iframe = this._.iframe = document.createElement( 'iframe' );
		}
		iframe.frameBorder = '0';
		if( par.width && ! par.height ){
			this.content.style.width = par.width + 'px';
			iframe.style.width = par.width + 'px';
		}		
		var needResize = true;
		iframe.onload = iframe.onload_ = function(){
			var height = this.style.height; // IE
			this.style.height = ''; // IE
			this.style.height = height; // IE
			if( ! needResize ){
				return;
			}
			if( par.onload_resize !== false ){
				if( par.width && par.height ){
					this_.resizeTo( par.width, par.height );
				} else if( par.width && ! par.height ){
					this_.resizeTo( par.width, 100 );
					this_.autoResize();
				} else {
					this_.resizeTo( this_.defaults.width, this_.defaults.height );
				}
			}
			iframe.style.visibility = '';
			this_._.box_content.className = '';
			if( par.onload ){
				try{
					par.onload.apply( this_ )
				} catch(e){
					D.console.error(e);
				}
			}
			needResize = false;
		};
		if( par.onload_resize !== false ){
			if( par.width && par.height ){
				this_.resizeTo( par.width, par.height );
			} else if( par.width && ! par.height ){
				this_.autoResize();
			} else {
				this_.resizeTo( this_.defaults.width, this_.defaults.height );
			}
		}
		iframe.src = href;
		this._.box_content.appendChild( iframe );		
	}, // iframe:function
	
	reload:function(){
		if( this.type == 'iframe' ){
			this._.iframe.contentWindow.D.reload();
		}
	},
	
	openLite:function( par ){
		var this_ = this;
		if( typeof par == 'undefined' ){
			par = {};
		}
		this.par = par;
		this.init( par );
		this._.overlay.onclick = function(){
			this_.close();
		};
		this.setStyle( true );
		this.removeNode( this._.box  );
		this._.td.appendChild( this._.box_lite );
		this._.box_lite.innerHTML = par.text || '...'; 
		if( par.width && par.height ) this_.resizeTo( par.width, par.height );
	}, // openLite:function
	
	resizeTo:function( w, h, par ){
		var this_ = this;
		var w = String( w );
		var h = String( h );
		if( ! par ){
			par = {};
		}
		if( String( w ).indexOf( 'px' ) == -1 && String( w ).indexOf( '%' ) == -1 && w != 'auto' ){
			w = String( Number( w ) + 20 <= document.body.offsetWidth ? Number( w ) + 20 : document.body.offsetWidth - 20 ) + 'px';
		}
		if( String( h ).indexOf( 'px' ) == -1 && String( h ).indexOf( '%' ) == -1 && h != 'auto' ){
			var maxH = document.body.offsetHeight;
			h = String( Number( h ) + 20 <= maxH - 70 ? Number( h ) + 20 : maxH - 70 ) + 'px';
		}
		if( w != 'auto' && h != 'auto' && par.animated ){
			$( this._.box_content ).animate( { width:w, height:h }, 'fast' );
			return 
		}
		if( w != 'auto' ){
			this._.box_lite.style.width = w;			
			this._.box_content.style.width = w;
			if( this._.iframe ){
				this._.iframe.style.width = w; 
			}
		}
		if( h != 'auto' ){
			this._.box_lite.style.height = h;
			this._.box_content.style.height = h;
			if( this._.iframe ){
				this._.iframe.style.height = h;
			}
		}
	}, // resizeTo:function
	
	removeNode:function( node ){
		if( node.parentNode ) return node.parentNode.removeChild( node ); else return false;
	}, // clearNode:function
	
	clearNode:function( node ){
		var n;
		while( n = node.firstChild ) this.removeNode( n );
	}, // clearNode:function
	
	toString:function(){
		return 'dr.lv infobox3';
	} // toString:function
};
// --- infobox v3 ---

// Adapter objekts, lai nodroshinaatu savietojamiibu ar veco Infobox versiju.
var InfoBox = {

	zIndex:1000,
	
	// parametri
	defaults: {close:''},
	// inicializaacija
	init:function(){
	},
	// ajax variants
	open:function( href, props ){		
		InfoBox3.open( href, props );
		return false;
	},
	
	html:function( html, props ){		
		InfoBox3.html( html, props );
		return false;
	},
	
	// aizveershana
	close:function(){
		return InfoBox3.close();
	},
	// iframe variants
	iframe:function(href, props){		
		InfoBox3.iframe( href, props );
		return false;
	},
	
	reload:function(){
		InfoBox3.reload();
		return false;
	},
	// resize
	resizeTo:function(name, x,y, par ){		
		InfoBox3.resizeTo( x, y, par );
	}
};

var InfoLite = {
	// loga platums un augstums
	width: 300,
	height: 40,
	defaultWidth: 300,
	defaultHeight: 40,
	wnd: null,
	mode: null,
	text: '...',
	init: function(){
		InfoLite.wnd = $('#infolite');
	},
	open: function(props){
		InfoBox3.openLite( props )
		return false;
	},
	close: function(){
		InfoBox3.close();
	},
	postload: function(){		
	},	
	resizeto: function(w,h){
		InfoBox3.resizeTo( w, h );
	},	
	IEcenter:function(){		
	},
	viewport:function(){
	}  
}

var emotionsIcons = {
	0:'no_emotion',
	1:'abroad',
	2:'angry',
	3:'cry',	
	4:'do_not_disturb',
	5:'hangower',
	6:'happy',
	7:'in_love',
	8:'kiss',
	9:'lets_go_dance',
	10:'meet_someone',
	11:'new_galery',
	12:'sick',
	13:'sos',
	14:'write_me',
	15:'zb',
	16:'revolution',
	17:'batman',
	18:'working',
	19:'cool',
	20:'devil',
	21:'emo',
	22:'sexy',
	23:'skull',
	24:'sleep',
	25:'thumb_up',
	26:'rapper',
	27:'pirate',
	28:'peace',
	29:'basketball',
	31:'lacplesis',
	30:'lucky',
	32:'santa',
	33:'angel',
	34:'tree',
	35:'bored',
	36:'clown',
	37:'MR_T',
	38:'heart',
	39:'LT',
	40:'moto',
	41:'police',
	42:'bmw',
	43:'girl',
	44:'hu',
	45:'rabbit',
	46:'morda',
	47:'party',
	48:'liigo',  
	49:'wizard',  
	50:'witch',  
	51:'zombie',  
	52:'pumpkin',  
	53:'cyclops',  
	54:'alien',  
	55:'army',  
	56:'cards',  
	57:'bomb',  
	58:'briedis',
	59:'kachok',
	60:'hockey',
	61:'snowy',
	62:'rose',
	63:'headphones',
	64:'drink',
	65:'bartender',
	66:'8ball',
	67:'hockeyhu',
	68:'valentine',
	69:'blonde',
	70:'fire',
	71:'bomzis',
	72:'robo',
	73:'flower',
	74:'vampire',
	75:'guitar',
	76:'farm',
    77: 'hot'
};

function emoInfo(){
	//if(D.LANG == 'hu'){
		window.open( "/inc/main/emo_infobox.php", "myWindow", 
"status = 1, height = 600, width = 700, resizable = 0, scrollbars = 1" );
	//}else{
	//	InfoBox.iframe( '/inc/main/emo_infobox.php', { width:700 } ); 
	//}
}

var EMO = 0;
Draugiem.Emo = {
	version: '0.2',
	loaded: false,
	load: function(el_id){
		var loadTime=new Date();  
		var cnt=0;
		
		if($((el_id?"#"+el_id+" ":"")+".etEmoFp").size() && !Draugiem.Emo.loaded){  
			Draugiem.Tools.dhtmlLoadCSS(pimg + '/css/emo.css.'+ cssver); 
			Draugiem.Emo.loaded = true;
		}
		if($((el_id?"#"+el_id+" ":"")+".emoOn").size()){
			if(!Draugiem.Emo.loaded){
				Draugiem.Tools.dhtmlLoadCSS(pimg + '/css/emo.css.'+ cssver);
			}
			Draugiem.Emo.loaded = true; 
			$((el_id?'#'+el_id+' ':'')+".emoOn").live("mouseover",function(){ Draugiem.Emo.showBig(this.id,$('#'+this.id).attr('rel'));});
			cnt+= $((el_id?'#'+el_id+' ':'')+".emoOn").size();
			$((el_id?'#'+el_id+' ':'')+".emoOn").live("mouseout",function(){Draugiem.Emo.showSmall(this.id);});
			
			$((el_id?'#'+el_id+' ':'')+".emoOn").live("click",function(){ emoInfo(); });
		}
		if($((el_id?'#'+el_id+' ':'')+".emo_info").size()){
			if(!Draugiem.Emo.loaded){
				Draugiem.Tools.dhtmlLoadCSS(pimg + '/css/emo.css.'+ cssver);
				Draugiem.Emo.loaded = true;
			}
			$('.emo_info').live("mouseover", function(){
				Draugiem.Emo.showInfo(this.id,$('#'+this.id).attr('rel'));
			});
			$('.emo_info').live('mouseout', function(){$('#BubbleEmoBox').remove()});
			$('.emo_info').live('click', function(){
				param = this.id;
				var rez = param.split("_");
				selectEMO(rez[1]);
			}); 
		}
		var now=new Date();
		return false;
	},
	showSmall: function(param){
		var rez = param.split("_");
		
		$('#emoBubble').fadeOut('fast', function(){
			$("#emoBubble").empty();
		});
		return true;
	},
	showBig: function(param,com){
		offset = $('#'+param).offset();
		var rez = param.split("_");
		var uid = rez[0];
		var emo = rez[1];
		$('.prof_emoProfile').empty();
		$("#emoBubble").fadeOut('fast',function(){
			$("#emoBubble").html('<div id="fstEmo" class="emohov"><div class="emo_b'+emo+'"></div></div><div class="emoComSm"><div class="emoComTop"></div><div class="emoComMiddle"><span class="emoComTxt">'+com+'</span></div><div class="emoComBottom"></div></div>').fadeIn();
			if(typeof(emotionsIcons[emo]) == 'undefined'){
				emotionsIcons[emo] = 'no_emotion';
			}
			
			var so1 = new SWFObject(pimg+ '/img/emotions/smile_'+emotionsIcons[emo]+'.swf','emotion_swf',60,60,6,'#ffffff');
			so1.addParam('wmode','transparent');
			so1.write('fstEmo');
		}).css({'z-Index':'10','position':'fixed', 'top': (parseInt(offset.top) - 130) +'px', 'left': (parseInt(offset.left) - 60)+'px'});
		return true;		
	},
	showInfo: function(param,com){
		var rez = param.split("_");
		if(rez[1] != EMO){
			if(typeof(emotionsIcons[rez[1]]) == 'undefined'){
				emotionsIcons[rez[1]] = 'no_emotion';
			}
			var so1 = new SWFObject(pimg + '/img/emotions/smile_'+emotionsIcons[rez[1]]+'.swf','emotion_swf',59,59,6,'#ffffff');
			so1.addParam('wmode','transparent');
			$('#emo_' + EMO).show();
			$('#emo_' + EMO).html('<div class="emo_b'+EMO+'"></div>');   
			EMO = rez[1]; 		
			so1.write(param);
			$('.emoComSm').remove();
			$('#'+param).append('<div class="emoClick" onclick="selectEmo('+ EMO +')"></div>');
			//alert(D.position(document.getElementById('emo_'+EMO)).left);
			$("body").append('<div id="BubbleEmoBox" style="position:absolute;left:'+ (D.position(document.getElementById(param)).left+40) +'px;top:'+ (D.position(document.getElementById(param)).top-50) +'px;margin:0px;" class="emoComSm bubblepos" ><div class="emoComTop"></div><div class="emoComMiddle"><span class="emoComTxt">'+com+'</span></div><div class="emoComBottom"></div></div><br class="clr" /><div class="ieHackClickableEmo">&nbsp;</div>');  
			//$('#BubbleEmoBox').css({'margin':0,'left': +'px', 'top' : (D.position(this).top-50)+'px'});
			//$("#"+param).show();
			
			
		}
		
		
		return true;	
	}
};

var gifts_css_upd = {
	init:function() {
	},
	load_big: function(gid,image) {
		$('.davana'+gid).css({
			"width":"250px",			
			"height":"250px",			
			"background-repeat": "no-repeat",			
			"background-image":"url('"+image+"')",			
			"position":"absolute",			
			"margin-top":"-70px",			
			"right":"-65px",			
			"display":"block",			
			"z-index": "100"
		});
	},
	load_small: function(gid,version) {
		return true;
	}
}

function navigation( pg, pgs, link, onclick, lang ){
	if( typeof lang == 'undefined' ) lang = {};
	var s = ( pg - 5 > 0 ? pg - 5 : 1 );
	var e = ( pg + 5 <= pgs ? pg + 5 : pgs );
	var re = mkE( {
		tag:'p',
		className:'navigation',
		prop:{
			style:{
				margin:'0',
				textAlign:'center'				
			}
		}
	} );
	if( pg > 1 ){
		mkE( {
			tag:'a',
			className:'da',
			prop:{
				onclick:function(){
					return onclick( 1 );
				},
				href:String( link ).replace( /%s/, '1' )
			},
			els:[
				mkE( {
					tag:'span',
					className:'dbl_arrw',
					text:'« '
				} )
			]
		} ).append( re );
		mkE( {
			tag:'a',
			className:'da',
			text:( lang.prev1 || 'prev1' ) + ' ',
			prop:{
				onclick:function(){
					return onclick( pg -1 );
				},
				href:String( link ).replace( /%s/, String( pg - 1 ) )
			}
		} ).append( re );
	} else {		
		mkE( {
			tag:'span',
			className:'dbl_arrw',
			text:'« '
		} ).append( re );
		mkE( {
			tag:'span',
			text:( lang.prev1 || 'prev1' ) + ' '
		} ).append( re );
	}	
	function oncl(){
		return onclick( this.navigation_pg );
	};
	mkE( {
		tag:'span',
		text:'( ' + ( lang.page || 'page' ) + ' '
	} ).append( re );	
	for( var i = s; i <= e; i ++ ){
		if( i == pg ){
			mkE( {
				tag:'b',
				text:String( i ) + ' '
			} ).append( re );
		} else {
			mkE( {
				tag:'a', 
				text:String( i ),
				prop:{
					navigation_pg:i,
					onclick:oncl,
					href:String( link ).replace( /%s/, String( i ) )
				}
			} ).append( re );
			re.appendChild( document.createTextNode( ' ' ) );			
		}
	}
	mkE( {
		tag:'span',
		text:') '
	} ).append( re );
	if( pgs > pg ){
		mkE( {
			tag:'a',
			className:'da',
			text:( lang.next1 || 'next1' ) + ' ',
			prop:{
				onclick:function(){
					return onclick( pg + 1 );
				},
				href:String( link ).replace( /%s/, String( pg + 1 ) )
			}
		} ).append( re ); 
		mkE( {
			tag:'a',
			className:'da',
			prop:{
				onclick:function(){
					return onclick( pgs );
				},
				href:String( link ).replace( /%s/, String( pgs ) )
			},
			els:[
				mkE( {
					tag:'span',
					className:'dbl_arrw',
					text:' »'
				} )
			]
		} ).append( re );		
	} else {				
		mkE( { 
			tag:'span',
			text:( lang.next1 || 'next1' )
		} ).append( re );
		mkE( {
			tag:'span',
			className:'dbl_arrw',
			text:' »'
		} ).append( re );
	}
	return re;
}; // function navigation

function htmlspecialchars(p_string) {
	p_string = p_string.replace(/&/g, '&amp;');
	p_string = p_string.replace(/</g, '&lt;');
	p_string = p_string.replace(/>/g, '&gt;');
	p_string = p_string.replace(/"/g, '&quot;');
//	p_string = p_string.replace(/'/g, '&#039;');
	return p_string;
};


function htmlspecialchars_decode( string, quote_style ){
	if( typeof string == 'undefined' ) string = '';
	string = string.toString();
	string = string.replace( /&amp;/g, '&' ).replace( /&lt;/g, '<' ).replace( /&gt;/g, '>' );
	if( quote_style == 'ENT_QUOTES' ){
		string = string.replace( /&quot;/g, '"' ).replace( /&#039;/g, '\'' );
	}else if( quote_style != 'ENT_NOQUOTES' ){
		string = string.replace( /&quot;/g, '"' );
	}
	return string;
}

function empty( v ){
	if( v === null ) return true;
	switch( typeof v ){
		case 'object':			
			for( var k in v ) return false;
			break;
		case 'boolean':
			return ! v;			
		case 'number':
			return ( v === 0 );
		case 'string':
			return ( v === '' || v === '0' );
		case  'function':
			return false;
	}
	return true;
}

function count( v ){
	if( typeof v != 'object' ) return 1;
	if( v instanceof Array ) return v.length;
	var l = 0;
	for( var k in v ) l ++;
	return l;
}

function array_search( need, haystack, strict ){
	var i;
	if( haystack instanceof Array && typeof haystack.indexOf == 'function' && ! strict ){
		i = haystack.indexOf( need );
		if( i != -1 ){
			return i;
		}
	} else if( typeof haystack == 'object' || typeof haystack == 'function' ){		
		for( var i in haystack ){
			if( array_search ? haystack[ i ] === need : haystack[ i ] == need ){
				return i;
			}
		}
	}
	return false;
}

function array_keys( array ){
	var re = [];
	for( var k in array ){
		re.push( k );
	}
	return re;
}

// sludinajuma atversana (arpus /zip/ radamajiem sludinajumiem)
function zipOpen(href){
	var w=720;
	var h=620;
	var left = (screen.width) ? (screen.width-w)/2 : 0;
	var top = (screen.height) ? (screen.height-h)/2 : 0;
	var handle;
	if(handle=window.open(href,'ad_view'+(new Date().getTime()) ,'width='+w+', height='+h+', left='+left+', top='+top+', status=no, scrollbars=yes')){
		handle.focus();
		return false;
	} else {
		return true;
	}
}

function profpic(link, id){
	InfoBox.iframe( link, { onload_resize:false } );
	return false
}

Draugiem.moveNode = { 
	X:0,
	Y:0,
	
	mouseMove:function( e ){
		if ( document.all ) { 
      Draugiem.moveNode.X = event.clientX + document.body.scrollLeft;
      Draugiem.moveNode.Y = event.clientY + document.body.scrollTop;
    } else {  
      Draugiem.moveNode.X = e.pageX;
      Draugiem.moveNode.Y = e.pageY;
    }
		if( ! Draugiem.moveNode.dragElement ) return;
		Draugiem.moveNode.dragElementFnMove.apply( Draugiem.moveNode.dragElement, [ Draugiem.moveNode.X - Draugiem.moveNode.dX, Draugiem.moveNode.Y - Draugiem.moveNode.dY ] );
	},
	
	mouseUp:function(){
		var node = Draugiem.moveNode.dragElement;
		try{
			if( node && node.onMoveEnd ) node.onMoveEnd.apply( node, [ Draugiem.moveNode.X - Draugiem.moveNode.dX, Draugiem.moveNode.Y - Draugiem.moveNode.dY ] );
		} catch( e ){
			D.console.error( e );
		}
		Draugiem.moveNode.dragElement = false;
	},
	
	enable:function( el, fnMove ){
		this.dX = this.X - el.offsetLeft;
		this.dY = this.Y - el.offsetTop;
		this.dragElementFnMove = fnMove;
		this.dragElement = el;
		document.body.onmousedown = function(){ return false; };
		document.body.onselectstart = function(){ return false; };
		document.body.style.MozUserSelect = 'none';
	},
	
	nowMoving:function( el ){
		return this.dragElement == el;
	}
};

// +++ RPC +++
function RPC( url ){
	RPC.list = [
		function(){ return new XMLHttpRequest(); },
		function(){ return new ActiveXObject ( 'Microsoft.XMLHTTP' ); },
		function(){ return new ActiveXObject ( 'Msxml2.XMLHTTP' ); },
		function(){ return new ActiveXObject ( 'Msxml2.XMLHTTP.4.0' );}
	];
	if( ! RPC.XHR ){
		for(var i=0; i < RPC.list.length; i ++ ) try{
			RPC.list[i]();
			RPC.XHR = RPC.list[i];
			break;
		}catch(e){}
	}
	this.url = url;
	this.XHR = RPC.XHR;	
}

RPC.prototype.toString = function(){
	return 'RPC "' + this.url + '"';
};
RPC.prototype.send = function( method, data, re_fn, o ){
	if( D.DEV ){
		//D.console.info( JSON.encode( { method:method, data:data } ) );
	}
	$.post( this.url, JSON.encode( { method:method, data:data } ), function( re_text ){
		if( D.DEV ){
			//D.console.info( re_text );
		}
		if( re_fn ){
			var re_data = JSON.decode( re_text );
			try{
				if( typeof re_data == 'object' && typeof re_data.ok != 'undefined' ){				
					re_fn( re_data.ok, o );
					if( ! empty( re_data.ob ) ){
						D.console.warn( re_data.ob );
					}
				} else {
					D.console.error( re_text );
				}
			}
			catch( e ){
				D.console.error( e );
			}
		}
	} );
};
// --- RPC ---

// +++ JSON +++
var JSON = {
	decode:function( s ){
    try{
			return !( /[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test( s.replace(/"(\\.|[^"\\])*"/g, '')) ) && eval( '(' + s + ')' );
    }
    catch( e ){
        return false;
    }
	}, // decode:function
	
	encode:function( v ){		
		return this.s[ typeof v ]( v );
	},	// encode:function
	
	s:{
		'boolean': function (x) { return String(x); },
		'null': function (x) { return "null"; },
		'undefined': function (x) { return "null"; },
		number: function (x) { return isFinite(x) ? String(x) : 'null'; },
		string: function (x) {
				if (/["\\\x00-\x1f]/.test(x)) {
						x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
								var c = JSON.m[b];
								if (c) {
										return c;
								}
								c = b.charCodeAt();
								return '\\u00' +
										Math.floor(c / 16).toString(16) +
										(c % 16).toString(16);
						});
				}
				return '"' + x + '"';
		},
		array: function (x) {
				var a = ['['], b, f, i, l = x.length, v;
				for (i = 0; i < l; i += 1) {
						v = x[i];
						f = JSON.s[typeof v];
						if (f) {
								v = f(v);
								if (typeof v == 'string') {
										if (b) {
												a[a.length] = ',';
										}
										a[a.length] = v;
										b = true;
								}
						}
				}
				a[a.length] = ']';
				return a.join('');
		},
		object: function (x) {
				if (x) {
						if (x instanceof Array) {
								return JSON.s.array(x);
						}
						var a = ['{'], b, f, i, v;
						for (i in x) {
								v = x[i];
								f = JSON.s[typeof v];
								if (f) {
										v = f(v);
										if (typeof v == 'string') {
												if (b) {
														a[a.length] = ',';
												}
												a.push( JSON.s.string(i), ':', v );
												b = true;
										}
								}
						}
						a[ a.length ] = '}';
						return a.join('');
				}
				return 'null';
		}
	}, // s
	
	m:{  // A character conversion map
		'\b': '\\b', '\t': '\\t',  '\n': '\\n', '\f': '\\f',
		'\r': '\\r', '"' : '\\"',  '\\': '\\\\'
	} // m
};
// --- JSON ---

Draugiem.getACFriends = function( v, par ){
	if( ! par ){
		par = {};
	}
	var multiAc = this;
	if( ! Draugiem.getACFriends.rpc ){
		Draugiem.getACFriends.rpc = new RPC( '/rq/app.php' );
	}
	var time = Draugiem.getACFriends.onGetListTime = new Date().getTime();
	Draugiem.getACFriends.rpc.send(
		Draugiem.getACFriends.method,
		{
			v:v,
			groups:par.groups || false,
			gr:par.gr || false,
			sex:par.sex || false,
			data:par.data || false,
			age:par.age || false,
			l:par.l || false,
			extra:par.extra || {}
		},
		function( re ){
			if( Draugiem.getACFriends.onGetListTime > time ){
				return;
			}
			var list = [];
			for( var k in re.gr ){
				list.push( {
					caption:re.gr[ k ].n,
					value:'gr' + re.gr[ k ].i,
					online:true,
					group:true
				} );
			}			
			for( var k in re.fr ){
				list.push( {
					caption:re.fr[ k ].n,
					value:re.fr[ k ].i,
					online:re.fr[ k ].o,
					disabled:re.fr[ k ].d || false,
					icon:re.fr[ k ].icon || false
				} );
			}
			multiAc.setList( list );
		}
	);
};
Draugiem.getACFriends.method = 'searchFriends';

function insertAtCursor (myField, myValue) {

		// IE
		if (document.selection) {
			myField.focus();
			sel = document.selection.createRange();
			sel.text = myValue;
		}

		// Mozilla / Netscape support
		else if (myField.selectionStart || myField.selectionStart == '0')
		{
			var startPos = myField.selectionStart;
			var endPos = myField.selectionEnd;
			myField.value = myField.value.substring(0, startPos)
				+ myValue
				+ myField.value.substring(endPos, myField.value.length);
		}

		else
		{
			myField.value += myValue;
		}

		myField.focus();
}

function popUp(URL,w,h,scrollbars,resize) {
	var day = new Date();
	var id = day.getTime();
	D.newWindow( URL, id, {
		toolbar:0,
		scrollbars:scrollbars ? 1 : 0,
		location:0,
		menubar:0,
		resizable:resize ? 1 : 0,
		width:w,
		height:h,
		left:(screen.width)?(screen.width-w)/2:100,
		top:(screen.height)?(screen.height-h)/2:100
	} );
	return false;
}

function openUserPlayer (id) { 
	popUp ('/music/player/window.php?playlistid='+id,280, 420, false, false);
}

function formMessage (obj, clss, msg) {
	if (!$(obj).length) return;
	$(obj).removeClass().addClass('form-message form-' + clss).html(msg);
}

function defaultUploadCallback (inputid, fn) {
	$('#'+inputid).remove();
	var inp = $(document.createElement ('input'));
	inp.attr({id:inputid,type:'file',name:'Filedata'}).bind('change',function(){ startImageUpload($(this)) });
	$('#'+inputid+'-holder').append(inp);
}

// +++++++++++++++++++++++++++++++++ Draugiem V5 JS +++++++++++++++++++++++++++++++++++
// +++ D.ToolTip +++
D.ToolTip = function(){
	if( D.ToolTip.loaded ){
		return;
	}
	D.ToolTip.loaded = true;
	var this_ = this;
	this.node = mkE( {
		tag:'div',
		className:'ToolTip',
		prop:{
			style:{
				display:'none'
			}
		}
	} ).append( document.body );	
	$( document.body ).mousemove( function( e ){
		this_.onmousemove( e );
	} );
	$( document.body ).mouseout( function( e ){
		this_.onmousemout( e );
	} );
};
	
D.ToolTip.prototype.onmousemove = function( e ){
	var node = e.target;
	if( empty( node.getAttribute( 'title' ) ) && ! node._drTitle ){
		node = node.parentNode;
	}
	if( ! ( empty( node.getAttribute( 'title' ) ) && ! node._drTitle ) ){
		this.node.style.left = D.mouseX + 10 + 'px';
		this.node.style.top = D.mouseY + 5 + 'px';		
	}	
	var title = node.getAttribute( 'title' );
	if( empty( title ) ){
		return;
	}
	this.node.innerHTML = title;
	node._drTitle = title;
	node.title = '';
	this.node.style.display = '';
};
	
D.ToolTip.prototype.onmousemout = function( e ){
	var node = e.target;
	if( ! node._drTitle ){
		node = node.parentNode;
	}
	if( empty( node._drTitle ) ){
		return;
	}
	node.setAttribute( 'title', node._drTitle );
	this.node.style.display = 'none';
};

D.insertBefore = function( el, node ){
	node.parentNode.insertBefore( el, node );
};

D.insertAfter = function( el, node ){
	if( node.nextSibling ){
		D.insertBefore( el, node.nextSibling );
	} else {
		node.parentNode.appendChild( el );
	}	
};
// --- D.ToolTip ---

// +++ D.Drag +++
D.Drag = function( par ){
	var this_ = this;
	D.Drag.init();
	//par = par || {};
	if( ! par.node ){
		D.console.warn	( 'D.Drag empty par.node' );		
	}
	if( getStyle( par.node, 'position' ) == 'static' ){
		par.node.style.position = 'relative';
	}
	this.par = par;
	if( ! par.query ){
		D.console.warn	( 'D.Drag empty par.query' );
	}
	this.jq = $( par.query, par.node );
	this.jq.mousedown( function( e ){
		if( ! this.D ){
			this.D = {};
		}
		D.console.info( this.offsetLeft );
		var pos = D.position( this, par.node );
		D.console.info( pos );
		this_.changed = false;
		this.D.Drag = this_;
		this.D.dx = pos.left - this_.mouseX;
		this.D.dy = pos.top - this_.mouseY;
		this.style.position = 'absolute';
		this.style.left = pos.left + 'px';
		this.style.top = pos.top + 'px';
		addClassName( this, 'active' );
		D.dragElements = [ this ];
		this.D.replNode = mkE( {
			tag:'div',
			className:this.className,
			prop:{
				style:{
					background:'none',
					border:'none',
					width:this.offsetWidth + 'px',
					height:this.offsetHeight + 'px'
				}
			}
		} );
		D.insertBefore( this.D.replNode, this );
	} );
	this.insertBeforeElement = function(){
		var pos = D.position( this, par.node );
		if( D.dragElements ){
			for( var i = 0; i < D.dragElements.length; i ++ ){
				var el = D.dragElements[ i ];
				if( this === el ){
					break;
				}
				var elPos = D.position( el, par.node );
				var elReplPos = D.position( el.D.replNode, par.node );
				var halfWidth = this.offsetWidth / 2;
				var halfHeight = this.offsetHeight / 2;
				if( elPos.left > pos.left - halfWidth && elPos.left < pos.left + halfWidth && elPos.top > pos.top - halfHeight && elPos.top < pos.top + halfHeight ){
					if( elReplPos.left > elPos.left ){
						D.insertBefore( el.D.replNode, this );
					} else {
						D.insertAfter( el.D.replNode, this );
					}
					this_.changed = true;
				}
			}
		}	
	}; // this.insertBeforeElement
	$( par.node ).mousemove( function( e ){
		this_.mouseX = e.clientX;
		this_.mouseY = e.clientY;
		if( empty( D.dragElements ) ){
			par.node.style.cursor = 'default';
		} else {
			par.node.style.cursor = 'move';
			for( var i = 0; i < D.dragElements.length; i ++ ){
				var el = D.dragElements[ i ];
				el.style.left = this_.mouseX + el.D.dx + 'px';
				el.style.top = this_.mouseY + el.D.dy + 'px';
				this_.jq.each( this_.insertBeforeElement );
			}
		}
	} );
};

D.Drag.init = function(){
	if( D.Drag.initOk ){
		return;
	}
	$( document.body ).mouseup( function( e ){
		if( D.dragElements ){
			for( var i = 0; i < D.dragElements.length; i ++ ){
				var el = D.dragElements[ i ];
				el.style.position = '';
				el.style.top = '';
				el.style.left = '';
				D.insertBefore( el, el.D.replNode );
				removeNode( el.D.replNode );
				removeClassName( el, 'active' );
				if( el.D.Drag.par.onDragEnd && el.D.Drag.changed ){
					el.D.Drag.par.onDragEnd( el, array_search( el, el.parentNode.childNodes, true ) );
				}
			}
		}
		D.dragElements = [];
	} );
	D.Drag.initOk = true;
};
// --- D.Drag ---

// +++ multi selector
D.MultiSelector = function( par ){
	var this_ = this;
	if( par.onSelect ){
		this.onSelect = par.onSelect
	}
	this.selected = [];
	if( ! par.node  ){
		D.console.warn( 'D.Drag empty par.node' );		
	}
	this.par = par;
	if( ! par.query ){
		D.console.warn( 'D.Drag empty par.query' );
	}
	this.jq = $( par.query, par.node );
	this.jq.mousedown( function( e ){
		if( e.ctrlKey || e.shiftKey || e.metaKey ){
			var pos = array_search( this, this_.selected, true );
			if( pos !== false ){
				$( this ).removeClass( 'selected' );
				this_.selected.splice( pos, 1 );
				return;
			}
			this_.selected.push( this );
		} else {
			$( this_.selected ).removeClass( 'selected' );
			this_.selected = [ this ];
		}
		addClassName( this, 'selected' );
		if( this_.onSelect ){
			this_.onSelect( this_.selected, this );
		}
	} );
};

// +++ select area +++
/*
	par = {
		node:node,jquery,
		onSelectStart:function(){},
		onSelectEnd:function(){},
		onSelectCancel:function(){},
		onSelect:function(){},
		maxWidth:[int],
		maxheight:[int]
	}
*/
D.SelectArea = function( par ){
	var this_ = this;
	this.x = 0;
	this.y = 0;
	this.w = 0;
	this.h = 0;
	this.par = par;
	this.node = $( par.node )[ 0 ];	
	if( ! this.node ){
		return false;
	}
	this.node.style.cursor = 'crosshair';
	this.onSelectStart = par.onSelectStart || function(){ if( this_.debug ){ D.console.info( 'onSelectStart', arguments ) } };
	this.onSelectEnd = par.onSelectEnd || function(){ if( this_.debug ){ D.console.info( 'onSelectEnd', arguments ) } };
	this.onSelectCancel = par.onSelectCancel || function(){ if( this_.debug ){ D.console.info( '.onSelectCancel', arguments ) } };
	this.onSelect = par.onSelect || function(){ if( this_.debug ){ D.console.info( 'onSelect', arguments ) } };
	this.els = {};
	this.resizeEls = {};
	this.bgMousedown = function( e ){
		e = D.stopPropagation( e );
		this_.clear();
		if( this_.onSelectCancel ){
			this_.onSelectCancel();
		}
	};
	this_.els.t = mkE( {
		tag:'div',
		className:'SelectAreaBg',
		style:{
			top:'0px',
			left:'0px',
			width:'100%'
		}
	} );
	this_.els.b = mkE( {
		tag:'div',
		className:'SelectAreaBg',
		style:{
			left:'0px',
			width:'100%'
		}
	} );
	this_.els.l = mkE( {
		tag:'div',
		className:'SelectAreaBg',
		style:{
			left:'0px'
		}
	} );
	this_.els.r = mkE( {
		tag:'div',
		className:'SelectAreaBg'
	} );
	this_.els.c = mkE( {
		tag:'div',
		className:'SelectArea',
		prop:{
			onmousedown:function( e ){
				e = D.stopPropagation( e );
				this_.oldData();
				this_.move = true;
			}
		},
		els:[
			this_.resizeEls.lt = mkE( {
				tag:'div',
				className:'SelectAreaCor SelectAreaLT',
				prop:{
					onmousedown:function( e ){
						e = D.stopPropagation( e );
						this_.oldData();
						this_.resize = 'lt';
						this_.onSelectStart();
					}
				}
			} ),
			this_.resizeEls.lb = mkE( {
				tag:'div',
				className:'SelectAreaCor SelectAreaLB',
				prop:{
					onmousedown:function( e ){
						e = D.stopPropagation( e );
						this_.oldData();
						this_.resize = 'lb';								
						this_.onSelectStart();
					}
				}
			} ),
			this_.resizeEls.rt = mkE( {
				tag:'div',
				className:'SelectAreaCor SelectAreaRT',
				prop:{
					onmousedown:function( e ){
						e = D.stopPropagation( e );
						this_.oldData();
						this_.resize = 'rt';
						this_.onSelectStart();
					}
				}
			} ),
			this_.resizeEls.rb = mkE( {
				tag:'div',
				className:'SelectAreaCor SelectAreaRB',
				prop:{
					onmousedown:function( e ){
						e = D.stopPropagation( e );
						this_.oldData();
						this_.resize = 'rb';
						this_.onSelectStart();
					}
				}
			} )
		]
	} );
	for( var k in this_.els ){
		this_.els[ k ].style.display = 'none';
		this_.els[ k ].append( this_.node );			
		if( k != 'c' ){
			this_.els[ k ].onmousedown = this_.bgMousedown;
		}
	}
	this.node.onmousedown = function( e ){	
		if( this_.resize ){
			return;
		}
		this_.clear();
		if( ! e ){
			e = event;
		}
		this_.startX = e.layerX || e.offsetX;
		this_.startY = e.layerY || e.offsetY;
		this_.oldData();
		this_.onSelectStart();
		for( var k in this_.resizeEls ){
			this_.resizeEls[ k ].style.display = 'none';
		}
		this_.select = true;
		return false;
	};
	this.node.onmousemove = function(){		
		var x, y, w, h;
		var dx = D.mouseX - this_.mouseX;
		var dy = D.mouseY - this_.mouseY;
		if( this_.select ){
			if( par.whSame ){
				if( Math.abs( dx ) > Math.abs( dy ) ){
					dy = dy > 0 ? Math.abs( dx ) : - Math.abs( dx );
				} else {
					dx = dx > 0 ? Math.abs( dy ) : - Math.abs( dy );
				}
			}
			w = Math.abs( dx );
			if( this_.par.maxWidth && w > this_.par.maxWidth ){
				w = this_.par.maxWidth;
			}
			x = this_.startX;
			if( dx < 0 ){
				x = x + dx;
			}
			h = Math.abs( dy );
			if( this_.par.maxHeight && h > this_.par.maxHeight ){
				h = this_.par.maxHeight;
			}
			y = this_.startY;
			if( dy < 0 ){
				y = y + dy;
			}
			if( x + w < this_.node.offsetWidth && y + h < this_.node.offsetHeight && x > 0 && y > 0 ){
				this_.x = x;
				this_.y = y;
				this_.w = w;
				this_.h = h;
			}
		}
		if( this_.move ){
			x = this_.old.x + dx;
			y = this_.old.y + dy;
			if( x < 0 ){
				x = 0;
			}
			if( x + this_.w > this_.node.offsetWidth ){
				x = this_.node.offsetWidth - this_.w;
			}
			if( y < 0 ){
				y = 0;
			}
			if( y + this_.h > this_.node.offsetHeight ){
				y = this_.node.offsetHeight - this_.h;
			}
			this_.x = x;
			this_.y = y;
		}
		if( this_.resize ){
			if( par.whSame ){
				switch( this_.resize ){
					case 'lt':
					case 'rb':
						if( Math.abs( dx ) > Math.abs( dy ) ){
							dy = dx;
						} else {
							dx = dy;
						}
						break;
					case 'lb':
					case 'rt':
						if( Math.abs( dx ) > Math.abs( dy ) ){
							dy = -dx;
						} else {
							dx = -dy;
						}
						break;
				}
			}
			switch( this_.resize ){
				case 'lt':
					x = this_.old.x + dx;
					y = this_.old.y + dy;
					w = this_.old.w - dx;
					h = this_.old.h - dy;
					if( x + w > this_.node.offsetWidth || y + h > this_.node.offsetHeight ){
						break;
					}
					if( x > 0 && w > 10 ){
						this_.x = x;
						this_.w = w;
					}
					if( y > 0 && h > 10 ){
						this_.y = y;
						this_.h = h;
					}
					break;
				case 'lb':
					x = this_.old.x + dx;
					w = this_.old.w - dx;
					h = this_.old.h + dy;
					if( x + w > this_.node.offsetWidth || this_.old.y + h > this_.node.offsetHeight ){
						break;
					}
					if( x > 0 && w > 10 ){
						this_.x = x;
						this_.w = w;
					}
					if( h > 10 ){					
						this_.h = h;
					}
					break;
				case 'rt':
					y = this_.old.y + dy;
					w = this_.old.w + dx;
					h = this_.old.h - dy;
					if( this_.old.x + w > this_.node.offsetWidth || y + h > this_.node.offsetHeight ){
						break;
					}
					if( w > 10 ){
						this_.w = w;
					}
					if( y > 0 && h > 10 ){
						this_.y = y;
						this_.h = h;
					}
					break;
				case 'rb':
					w = this_.old.w + dx;
					h = this_.old.h + dy;
					if( this_.old.x + w > this_.node.offsetWidth || this_.old.y + h > this_.node.offsetHeight ){
						break;
					}
					if( w > 10 ){
						this_.w = w;
					}
					if( h > 10 ){
						this_.h = h;
					}
					break;
					break;
			}
		}
		if( this_.select || this_.move || this_.resize ){
			this_.redraw();
			if( this_.onSelect ){
				this_.onSelect( this_.x, this_.y, this_.w, this_.h );
			}
		}
	};
	this.mouseup = function(){
		if( ( this_.select || this_.move || this_.resize ) && this_.w && this_.h ){
			for( var k in this_.resizeEls ){
				this_.resizeEls[ k ].style.display = '';
			}
			if( this_.onSelectEnd ){
				this_.onSelectEnd( this_.x,	this_.y, this_.w,	this_.h	);
			}
		}
		this_.select = false;
		this_.move = false;
		this_.resize = false;
	};	
	$( document.body ).mouseup( this.mouseup );
};

D.SelectArea.prototype.oldData = function(){
	this.mouseX = D.mouseX;
	this.mouseY = D.mouseY;
	this.old = {
		x:this.x,
		y:this.y,
		w:this.w,
		h:this.h
	};
};

D.SelectArea.prototype.redraw = function(){
	for( var k in this.els ){
		this.els[ k ].style.display = '';			
	}
	O2O( this.els.c.style, {
		left:this.x + 'px',
		top:this.y + 'px',
		width:this.w + 'px',
		height:this.h + 'px'
	} );
	O2O( this.els.t.style, {
		height:this.y + 'px'
	} );
	O2O( this.els.b.style, {
		top:this.y + this.h + 'px',
		height:this.node.offsetHeight - ( this.y + this.h ) + 'px'
	} );
	O2O( this.els.l.style, {
		top:this.y + 'px',
		height:this.h + 'px',
		width:this.x + 'px'
	} );
	O2O( this.els.r.style, {
		top:this.y + 'px',
		height:this.h + 'px',
		left:this.x + this.w + 'px',
		width:this.node.offsetWidth - ( this.x + this.w ) + 'px'
	} );
};

D.SelectArea.prototype.clear = function(){
	this.x = 0;
	this.y = 0;
	this.w = 0;
	this.h = 0;
	for( var k in this.els ){
		this.els[ k ].style.display = 'none';
	}
};

D.SelectArea.prototype.setSizes = function( x, y, w, h ){
	this.x = x;
	this.y = y;
	this.w = w;
	this.h = h;
	this.redraw();
}

D.SelectArea.prototype.unbind = function(){
	this.node.onmousedown = function(){};
	this.node.onmousemove = function(){};
	this.node.style.cursor = '';
	$( document.body ).unbind( 'mouseup', this.mouseup );
};
// --- D.SelectArea ---

D.smallPopUp = {

	open:function( url, par ) {
		this.close();
		par.title = par.title || '';
		this.offsetX = par.offsetX || 20;
		this.offsetY = ( par.offsetY || -50 ) + document.getElementById( 'outermost' ).scrollTop;
		this.onLoad = par.onLoad || function(){};
		this.onClose = par.onClose || function(){};
		var $this = this;
		this.x = par.x || D.mouseX;
		this.y = par.y || D.mouseY;
		this.node = mkE( {
			tag:'div',
			prop:{
				className:'small-popup',
				style:{
					top:this.y + this.offsetY + 'px',
					width:( par.width ? par.width + 'px' : '' ),
					height:( par.height ? par.height + 'px' : '' ),
					zIndex:InfoBox.zIndex ++
				}
			},
			els:[
				mkE( {
					tag:'div',
					className:'small-popup-title',
					prop:{
						onmousedown:function(){
							var this_ = this;							
							this._drDrag = {
								x:D.mouseX,
								y:D.mouseY,
								sx:$this.node.offsetLeft,
								sy:$this.node.offsetTop,
								onmove:function(){
									$this.node.style.left = D.mouseX - this_._drDrag.x + this_._drDrag.sx  + 'px';
									$this.node.style.top = D.mouseY - this_._drDrag.y + this_._drDrag.sy + 'px';
								}
							};
							$( document.body ).mousemove( this._drDrag.onmove );
							document.body.onmousedown = document.body.onselectstart = function(){ return false; };
						},
						onmouseup:function(){
							$( document.body ).unbind( 'mousemove', this._drDrag.onmove );
							delete this._drDrag;
							document.body.onmousedown = document.body.onselectstart = function(){};
						}
					},
					els:[
						this.titleDiv = mkE( {
							tag:'div',
							text:par.title							
						} ),
						mkE( {
							tag:'a',
							className:'deleteInactiveIcon deleteIconSize',
							prop:{
								href:'',
								onmouseover:function(){
									removeClassName( this, 'deleteInactiveIcon' );
									addClassName( this, 'cancelIcon' );
								},
								onmouseout:function(){
									addClassName( this, 'deleteInactiveIcon' );
									removeClassName( this, 'cancelIcon' );
								},
								onclick:function(){
									$this.close();
									return false;
								}
							}
						} )
					]
				} ),
				this.content = mkE( {
					tag:'div',
					className:'small-popup-content'
				} ),
				this.arrow = mkE( {
					tag:'div',
					className:'small-popup-arrow'
				} )
			]
		} ).append( document.getElementById( 'outermost' ) );
		var node = document.getElementById( 'wrap' ) || document.getElementById( 'outermost' );
		if( this.x + this.offsetX - D.position( node ).left + this.node.offsetWidth > 1100 ){
			this.node.style.left = this.x - this.node.offsetWidth + 'px';
			addClassName( this.node, 'small-popup-right' );
		} else {
			removeClassName( this.node, 'small-popup-right' );
			this.node.style.left = this.x + this.offsetX + 'px'
		}
		this.load( url );
		return false;
	},
	
	load:function( url ){
		var $this = this;
		rq( url, this.content, { overlay:true, onload:function(){ $this.onLoad(); } } );
	},
	
	setTitle:function( title ){
		if( ! this.titleDiv ){
			return;
		}
		clearNode( this.titleDiv );
		mkE( {
			tag:'span',
			text:title
		} ).append( this.titleDiv );
	},
	
	close:function() {
		if( this.node ){
			var $node = this.node;
			$( this.node ).fadeOut( 'fast', function(){
				$node.remove();
			} );
			this.onClose();
		}
	}
};

D.Lang = function( module ){
	this.module = module;
};

D.Lang.prototype.get = function( string ){
	return D.Lang.get( string, this.module );
};

D.Lang.get = function( string, module ){
	return window[ module ] && window[ module ][ string ] ? window[ module ][ string ] : ( D.DEV ? string : '' );
};

D.Lang.prototype.nget = function( n, string ){
	return D.Lang.nget( n, string, this.module );
};

D.numberFormat = function( v, round ){
	if( round ){
		v = Math.round( v * Math.pow( 10, round ) ) / Math.pow( 10, round );			
		var vs = String( v );
		var vsSplited = vs.split( '.' );
		var re = vsSplited[ 0 ] + '.';
		if( ! vsSplited[ 1 ] ){
			vsSplited[ 1 ] = '';
		}
		re += vsSplited[ 1 ].substr( 0, 2 );
		for( var i = vsSplited[ 1 ].substr( 0, 2 ).length; i < round; i ++ ){
			re += '0';
		}
		v = re;
	} else {
		v = Math.round( v );			
	}
	return v;
};
Number.prototype.format = function( round ){
	return D.numberFormat( this, round );
};

D.Lang.nget = function( $n, string, module ){
	switch( D.LANG ){
		case 'lv':
			/*
			 * _1 vienskaitlis
			 * _2 daudzskaitlis
			 * */
			$plural=($n%10==1&&$n%100!=11?'1':'2');
			break;
		case 'ru':
			/*
			 * _1 vienskaitlis
			 * _2 daudzskaitlis
			 * _3 2-4 specgadījums
			 *  */
			$plural=$n%10==1&&$n%100!=11?'1': ($n%10>=2 && $n%10<=4 && ($n%100<10 || $n%100>=20) ? '3' : '2');
			break;
		case 'en':
		case 'de':
			/*
			 * _1 - vienskaitlis
			 * _2 - daudzskaitlis
			 * */
			$plural=(int)($n!=1) + '1';
			break;
		case 'hu':
			/*
			 * _1 - vienskaitlis
			 * */
			$plural = '1';
			break;
		case 'lt':
			$plural=	($n%10==1 && $n%100!=11 ? '1' : ($n%10>=2 && ($n%100<10 || $n%100>=20) ? '2' : '3'));
			break;
		default:
			$plural = '1';
			break;
	}
	var k = string + ( $plural ? '_' + $plural : '' );
	return window[ module ] && window[ module ][ k ] || ( D.DEV ? k : '' );
};

D.Lang.exists = function( string, module ){
	return window[ module ] && window[ module ][ string ] ? true : false;
};

D.Lang.prototype.exists = function( string ){
	return D.Lang.exists( string, this.module );
};

// +++ BrowserDetect +++
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
// --- BrowserDetect ---
// ------------------------------- Draugiem V5 JS ----------------------------------------
$( document ).ready( function(){
	new D.ToolTip();
	Draugiem.Emo.load();
} );
 
var VInfo = {
	open:function(script,id){
			$('body').append('<div id="infobox4"><div id="infobox4_overlay" style="width:100%;height: 100%;background-color:#fff;opacity:0.8;position:absolute;"></div><center style="height:100%;"><table style="position:relative;height:100%"><tr ><td><div id="info_wrap"  class="'+id+'"><div id="info_content" style="padding:20px; padding-top:7px; background:#5A653E;	border:solid 1px #000;border-radius:10px; -o-border-radius:10px;-icab-border-radius:10px;-khtml-border-radius:10px;	-moz-border-radius:10px;-webkit-border-radius:10px;"><div id="source"></div></div><div id="infobox4_closeButtonSR" onclick="VInfo.close();" style="position:absolute;right:-12px;top:6px; z-index: 100 !important; background-image:url(\''+( typeof pimg != 'undefined' ? pimg : 'http://ifrype.com' ) +'/img/easter/infobox.png\'); background-position:left top;background-repeat:no-repeat; cursor:pointer; height:34px; width:34px;"></div></div></td></tr></table></center></div>');
			
			rq(script, 'source');
			return false;
	},
	close:function(){
		
		$('#infobox4').fadeOut('normal', function(){$('#infobox4').remove();})
	}
}	

function lieldienuPopup(link, id) {
		if (!id) id='';
		
	VInfo.open(link, id);
}

function oluKauja(fid) {
	lieldienuPopup('/special/lieldienu/olas/play/?fr='+fid, 'olu-kauja');
}

// +++ Get
var Get = function( url ){
  this.__ = '';      
  this._ = {};
  if( url ){
    var a = url.split( '?' );
    this.__ = a[0];
    if( a[ 1 ] ){
      a = a[ 1 ].split( '&' );
      var b;
      for( var i = 0; i < a.length; i ++ ){
        b = a[ i ].split( '=' );
        this._[ decodeURIComponent( b[0] ).replace( /\+/g, ' ' ) ] = ( b[1] ? decodeURIComponent( b[1] ).replace( /\+/g, ' ' ) : '' );            
      } 
    }
  }
};
Get.prototype.toStr = function(){
  return this.toStrItem( '', '', this._ );
};
Get.prototype.toStrItem = function( prefix, k, v ){
	prefix = ( prefix ? prefix + '[' + encodeURIComponent( k ) + ']' : encodeURIComponent( k ) );
	if( typeof v == 'object' ){ 
		var re = [];
		for( var k2 in v ) re.push( this.toStrItem( prefix, k2, v[ k2 ] ) );
		return re.join( '&' );
	} else {
		return prefix + ( v !== '' ? '=' + encodeURIComponent( v ) : '' );
	}
};
Get.prototype.str = function(){
	return this.toStr();
};
Get.prototype.toString = function(){
	return this.toStr();
};
Get.prototype.toUrl = function( k ){
  return this.__ + '?' + this.toStr();
};
Get.prototype.add = function( k, v ){
  this._[ k ] = ( v ? v : '' );
  return this;
};
Get.prototype.remove = function( k ){
  delete this._[ k ];
  return this;
};
Get.prototype.v = function( k ){
	return ( this._[ k ] ? this._[ k ] : false )
};