if( typeof D == 'undefined' ){	var D = {};}D.Gallery = {	rpc:new RPC( '/gallery/rq/app.php' ),		savePosition:function( el, pos ){		var overlay = mkE( {			tag:'div',			className:'rqOverlay'					} ).append( el );		D.Gallery.rpc.send(			'changeOrder',			{				pid:el.getAttribute( 'pid' ),				pos:pos			},			function( re ){				removeNode( overlay );			}					);	},		deleteSelected:function( aid ){		if( ! this.ms ){			return false;		}		if( ! confirm( xGlobal[ 'confirm delete' ] ) ){			return false;		}		var pids = []		for( var i = 0; i < this.ms.selected.length; i ++ ){			pids.push( Number( this.ms.selected[ i ].getAttribute( 'pid' ) ) );		}		rq(			'/gallery/rq/album_edit_pics.php?aid=' + aid + '&DS=' + sessid + '&delAlbumItems=' + pids.join( ',' ),			'galleryUploaded',			{				overlay:true			}		);		return false;	},		addPopupWidth:670,	addPopupHeight:500,		addPopup:function( par ){		var url = '/gallery/add.php?aid=' + ( par.aid ? par.aid : '0' );		url += '&tab=' + ( par.tab ? par.tab : '1' );		if( par.fid ){			url += '&fid=' + par.fid;		}		if( par.withTypes ){			url += '&withTypes';		}		if( par.choose ){			url += '&choose';		}		url += '&referer=' + encodeURIComponent( document.location.href.split( '#' )[0] );		if( par.lat && par.lng ){			url += '&lat=' + par.lat + '&lng=' + par.lng;		}		window.open( url, '_blank', 'location=0,status=1,scrollbars=1,width=' + this.addPopupWidth + ',height=' + this.addPopupHeight + ',resizable=0' );		return false;	},		addPopupVirtualItems:function( galApi, aid ){		if( empty( galApi.value() ) ){			window.close();			return;		}		D.Gallery.rpc.send(			'albumAddVirutalItems',			{				aid:aid,				pids:galApi.value()			},			function( re, par ){				$( '#galleryAddFromMy' ).hide();				$( '#galleryAddPermissions' ).show();				if( D.Gallery.activeAlbum.permissions ){					window.opener.location.href = D.Gallery.addPopupReferer + '?aid=' + D.Gallery.activeAlbum.id + '&edit';					window.opener.focus();					window.close();				}			}		);	},		setThumb:function( el, event, aid, pid ){		el.disabled = true;		D.Gallery.rpc.send(			'setThumb',			{				aid:aid,				pid:pid			},			function( re ){				el.disabled = false;			}		);	},		commentReply:function( el, cid, reply, cancel ){		$( '#galleryLargePictureCommentList .galleryCommentReply' ).html( reply );		var galleryLargePictureReply = document.getElementById( 'galleryLargePictureReply' );		if( galleryLargePictureReply.value == cid ){			el.innerHTML = reply;			galleryLargePictureReply.value = 0;			document.getElementById( 'galleryLargePictureCommentList' ).appendChild( document.getElementById( 'galleryLargePictureAddComment' ) );			removeClassName( document.getElementById( 'galleryLargePictureAddComment' ), 'answer' );		} else {			el.innerHTML = cancel;			galleryLargePictureReply.value = cid;			D.insertAfter( document.getElementById( 'galleryLargePictureAddComment' ), document.getElementById( 'galleryLargePictureComment' + cid ) );			addClassName( document.getElementById( 'galleryLargePictureAddComment' ), 'answer' );		}		return false;	}, // commentReply		editSelectedOnSelect:function( els ){		$( '#galleryEditSelectedOk' ).hide();		var galleryEditSelected = document.getElementById( 'galleryEditSelected' );		galleryEditSelected.style.display = ( els.length ? '' : 'none' );		if( els.length == 1 && els[ 0 ].parentNode.childNodes.length > 24 ){			galleryEditSelected.style.marginTop = findPosY( els[ 0 ] ) - findPosY( els[ 0 ].parentNode ) + 'px';		} else {			//galleryEditSelected.style.marginTop = '';		}		if( els.length > 1 ){			$( '#galleryEditSelectedThumb_' ).slideUp();		} else {			$( '#galleryEditSelectedThumb_' ).slideDown();		}		var videoC = 0;		for( var i = 0; i < els.length; i ++ ){			if( els[ i ].getAttribute( 'pictype' ) != 0 ){				videoC ++;			}		}		if( videoC ){			$( '#galleryEditSelectedRotate' ).slideUp();		} else {			$( '#galleryEditSelectedRotate' ).slideDown();		} 		var descr = document.getElementById( 'galleryEditSelectedAbout' );		var tags = document.getElementById( 'galleryEditSelectedKeywords' );		var albumThumb = document.getElementById( 'galleryEditSelectedThumb' );		descr.value = '';		tags.value = '';		albumThumb.checked = false;		if( els.length == 1 ){			D.Gallery.rpc.send(				'getPicInfo',				{					pid:els[ 0 ].getAttribute( 'pid' )				},				function( re ){					if( ! re ){						return false;					}					descr.value = htmlspecialchars_decode( re.descr );					tags.value = htmlspecialchars_decode( re.tags );					albumThumb.checked = re.albumThumb;				}			)		}	}, // editSelectedOnSelect		editSelected:function( aid ){		if( ! this.ms ){			return false;		}		var descr = document.getElementById( 'galleryEditSelectedAbout' );		var tags = document.getElementById( 'galleryEditSelectedKeywords' );		var albumThumb = document.getElementById( 'galleryEditSelectedThumb' );		var newAid = document.getElementById( 'galleryEditSelectedAlbum' ).value;		if( albumThumb.checked && this.ms.selected.length == 1 ){			$( '#galleryUploadedPics .galleryUploadedPic' ).removeClass( 'galleryAlbumThumb' );			addClassName( this.ms.selected[ 0 ], 'galleryAlbumThumb' );		}		var pids = []		for( var i = 0; i < this.ms.selected.length; i ++ ){			pids.push( Number( this.ms.selected[ i ].getAttribute( 'pid' ) ) );		}		$( '#galleryEditSelectedOk' ).show();		D.Gallery.rpc.send(			'editSelected',			{				pids:pids,				descr:descr.value,				tags:tags.value,				albumThumb:albumThumb.checked,				aid:newAid			},			function( re ){				$( '#galleryEditSelectedOk' ).fadeOut();				if( newAid == aid ){					return;				}				rq(					'/gallery/rq/album_edit_pics.php?aid=' + aid,					'galleryUploaded',					{						overlay:true					}				);			}		);	}, // editSelected		rotateSelected:function( angle ){		if( ! this.ms ){			return false;		}		var pids = []		for( var i = 0; i < this.ms.selected.length; i ++ ){			pids.push( Number( this.ms.selected[ i ].getAttribute( 'pid' ) ) );		}		if( pids.length ){			document.location.href = D.Gallery.UPL + 'gallery/rotate.php?angle=' + String( angle ) + '&pids=' + pids.join( ',' );		}		return false;	}, // rotateSelected		createPicUpload:function( par ){		if( typeof par != 'object' ){			par = {};		}		var post_params = {			DS:sessid,			aid:par.aid || 0,			tags:par.tags || ''		};		if( D.Gallery.addLat && D.Gallery.addLng ){			post_params.lat = D.Gallery.addLat;			post_params.lng = D.Gallery.addLng;		}		D.Gallery.upload = new SWFUpload( {			// Backend Settings			upload_url: D.Gallery.UPL + 'gallery/upload.php',			post_params:post_params,						// File Upload Settings			file_size_limit : '10240',				file_types : "*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JEPG;*.GIF;*.PNG",			file_types_description : "Images",			file_upload_limit : par.limit || "10",			file_queue_limit : "0",			// Event Handler Settings (all my handlers are in the Handler.js file)			file_dialog_start_handler : fileDialogStart,			file_queued_handler : fileQueued,			file_queue_error_handler : fileQueueError,			file_dialog_complete_handler : fileDialogComplete,			upload_start_handler : uploadStart,			upload_progress_handler : uploadProgress,			upload_error_handler : uploadError,			upload_success_handler : uploadSuccess,			upload_complete_handler: function( file ){				try {					if (this.getStats().files_queued === 0) {						document.getElementById( this.customSettings.cancelButtonId ).disabled = true;						$( '#galleryAddUploadButtons' ).hide();						$( '#galleryAddPermissions' ).show();						$( '#galleryAddBottom' ).hide();						if( D.Gallery.activeAlbum.permissions ){							window.opener.location.href = D.Gallery.addPopupReferer + '?aid=' + D.Gallery.activeAlbum.id + '&edit';							window.opener.focus();							window.close();						}					} else {						this.startUpload();					}				} catch (ex) {					this.debug(ex);				}			},			// Button Settings			//button_image_url : pimg + '/img/js/XPButtonUploadText_61x22.png',			button_placeholder_id : "spanButtonPlaceholder1",			button_width: 100,			button_height: 22,			button_text:'<span class="uploadButton"><b>' + xGal[ 'Add picture' ] + '</b></span>',			button_text_style:'.uploadButton { color:#777777; font-family: arial,sans-serif; }',			button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,			button_text_left_padding: 3,			button_text_top_padding: 2,						// Flash Settings			flash_url : "/img/js/swfupload2.2.0.1.swf",			custom_settings : {				progressTarget : "fsUploadProgress1",				cancelButtonId : "btnCancel1"			},						// Debug Settings			debug: false		} );	}, // createPicUpload			createVideoUpload:function( par ){		if( typeof par != 'object' ){			par = {};		}		D.Gallery.upload = new SWFUpload( {			// Backend Settings			upload_url: D.Gallery.VIDEO_UPL + 'gallery/video_upload.php',			post_params: {				DS:sessid,				aid:par.aid || 0,				tags:par.tags || ''			},						// File Upload Settings			file_size_limit : D.Gallery.VIDEO_MAX_UPLOAD_SIZE,	// 50MB			file_types : '*.avi;*.mpg;*.mpeg;*.wmv;*.mov;*.divx;*.mp4;*.3gp;*.3g2;*.asf;*.asx;*.flv;*.mkv;*.qt;*.rm;*.swf;*.vob;*.m4v;',			file_types_description : "Images",			file_upload_limit : par.limit || "10",			file_queue_limit : "0",			// Event Handler Settings (all my handlers are in the Handler.js file)			file_dialog_start_handler : fileDialogStart,			file_queued_handler : fileQueued,			file_queue_error_handler : fileQueueError,			file_dialog_complete_handler : fileDialogComplete,			upload_start_handler : uploadStart,			upload_progress_handler : uploadProgress,			upload_error_handler : uploadError,			upload_success_handler : uploadSuccess,			upload_complete_handler : function( file ){				try{					if (this.getStats().files_queued === 0) {						$( '#galleryUpload' ).hide();						$( '#galleryAddBottom' ).hide();						D.Gallery.rpc.send(							'getVideoStackId',							{},							function( re, par ){								if( empty( re.id ) ){									$( '#galleryUploadError' ).show();									if( re.error ){										$( '#galleryUploadErrorText' )[ 0 ].innerHTML = xGal[ 'galleryUploadError' + re.error ] || 'galleryUploadError' + re.error;									}								} else {									$( '#galleryUploadConverting' ).show();									D.Gallery.checkingVideoStatus( re.id );								}							}											);					}				} catch (ex) {					this.debug(ex);				}			},			// Button Settings			//button_image_url : pimg + '/img/js/XPButtonUploadText_61x22.png',			button_placeholder_id : "spanButtonPlaceholder1",			button_width: 100,			button_height: 22,			button_text:'<span class="uploadButton"><b>' + xGal[ 'Add video' ] + '</b></span>',			button_text_style:'.uploadButton { color:#777777; font-family: arial,sans-serif; }',			button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,			button_text_left_padding: 3,			button_text_top_padding: 2,						// Flash Settings			flash_url : "/img/js/swfupload2.2.0.1.swf",			custom_settings : {				progressTarget : "fsUploadProgress1",				cancelButtonId : "btnCancel1"			},						// Debug Settings			debug: false		} );	}, // createVideoUpload		checkingVideoStatus:function( id ){		D.Gallery.rpc.send(			'getVideoStackStatus',			{				id:id			},			function( re ){				if( re.status == 'done' ){					$( '#galleryUploadConverting' ).hide();					$( '#galleryAddPermissions' ).show();					if( D.Gallery.activeAlbum.permissions ){						window.opener.location.href = D.Gallery.addPopupReferer + '?aid=' + D.Gallery.activeAlbum.id + '&edit';						window.opener.focus();						window.close();					}					return;				}				$( '#galleryUploadStackSize' ).html( re.before );				setTimeout( function(){					D.Gallery.checkingVideoStatus( id );				}, 2000 );			}		);	},			deleteFav:function( pid ){		D.Gallery.rpc.send(			'deleteFav',			{				pid:pid			},			function( re, par ){			}		);		$( '#galleryLargePicDelFav' ).hide();		$( '#galleryLargePicAddFav' ).show();		return false;	},		deleteFavList:function( get ){		if( ! D.confirmDelete() ){			return false;		}		return rq( '/gallery/rq/favorites.php?' + get, 'galleryCT', {overlay:true} );	},	addFav:function( el, pid ){				if( this.node ){			this.node.remove();		}		var content = document.getElementById( 'galleryLargePicContent' );		var inp;		var save = function(){			inp.disabled = true;			D.Gallery.rpc.send(				'addFav',				{					pid:pid,					keywords:inp.value				},				function( re, par ){					node.remove();					$( '#galleryLargePicDelFav' ).show();					$( '#galleryLargePicAddFav' ).hide();					var galleryLargePicFavKeywords = document.getElementById( 'galleryLargePicFavKeywords' );											if( empty( inp.value ) ){						galleryLargePicFavKeywords.innerHTML = '';					} else {						galleryLargePicFavKeywords.innerHTML = '(' + htmlspecialchars( inp.value ) + ')';					}				}			);		};		var node = this.node = mkE( {			tag:'div',						prop:{				id:'galleryLargePicAddFavBox',				style:{					left:'20px',					top:document.getElementById( 'galleryLargePictureCenter' ).offsetHeight - 10 + 'px'				}			},			els:[				mkE( {					tag:'h1',					prop:{						innerHTML:xGal[ 'Pievienot izlasei' ] || '...'					}				} ),				mkE( {					tag:'div',					className:'galleryInfoText',					prop:{						innerHTML:xGal[ 'about add to favorites' ] || '...'					}				} ),				inp = mkE( {					tag:'input',					className:'inp',					prop:{						onkeyup:function( e ){							if( ! e ){								e = event;							}							if( e.keyCode == 13 ){								save();							}						}					}				} )			]		} );				var buttons = mkE( {			tag:'div',			className:'inlineNewButtons'		} ).append( node );		T.submitButton( {			size:'small',			caption:xGlobal[ 'Save' ],			onclick:save		} ).append( buttons );		mkE( {			tag:'span',			prop:{				innerHTML:'&nbsp;'			}		} ).append( buttons );		T.submitButton( {			size:'small',			color:'link',			caption:xGlobal[ 'Cancel' ],			onclick:function(){				$( node ).fadeOut();			}		} ).append( buttons );				node.append( content );		inp.focus();		return false;			},		// +++ add pic user +++		hoverPicUser:function( v, uid ){		if( v ){			$( '#galleryLargePicUser' + uid ).addClass( 'hover' );		} else {			$( '#galleryLargePicUser' + uid ).removeClass( 'hover' );		}	}, // hoverPicUser		delPicUser:function( el, pid, fid ){		if( ! confirm( xGlobal[ 'confirm delete' ] ) ){			return false;		}		el.style.display = 'none';		D.Gallery.rpc.send(			'delPicUser',			{				pid:pid,				fid:fid			},			function( re, par ){				$( '#galleryLargePicUser' + fid ).remove();				$( el.parentNode ).fadeOut();				$( '#galleryLargePicUserCount' ).html( re.count );				D.Gallery.activePicture.selectedUsers = re.selectedUsers;			}		);		return false;	},		addPicUser:function( el ){		if( el._drSelect ){			el.innerHTML = xGal[ 'Picture option select user' ];			el._drSelect = false;			$( '#galleryLargePicture' ).removeClass( 'hover' );			D.Gallery.addPicUserOverlay.remove();			D.Gallery.addPicUserSA.unbind();			D.Gallery.addPicUserSelectCancel();		} else {						el.innerHTML = xGal[ 'cancel pic user sel' ];			el._drSelect = true;			$( '#galleryLargePicture' ).addClass( 'hover' );			D.Gallery.addPicUserOverlay = mkE( {				tag:'div',				className:'galleryLargePicOverlay'			} ).append( document.getElementById( 'galleryLargePicture' ) );			D.Gallery.addPicUserSA = new D.SelectArea( {				node:D.Gallery.addPicUserOverlay,				maxWidth:500,				maxHeight:500,				onSelectEnd:D.Gallery.addPicUserSelectEnd,				onSelectCancel:D.Gallery.addPicUserSelectCancel			} );		}	},		addPicUserSelectEnd:function( x, y, w, h ){		D.Gallery.addPicUserShowForm();	},		addPicUserSelectCancel:function(){		if( D.Gallery.addPicUserForm ){			D.Gallery.addPicUserForm.remove();		}	},		addPicUserShowForm:function(){		if( ! D.Gallery.addPicUserForm ){			D.Gallery.addPicUserForm = mkE( {				tag:'div',				className:'galleryLargePicAddUserFrom',				prop:{					onmouseup:function( e ){						if( ! e ){							e = event;						}						if( e.stopPropagation ){							e.stopPropagation();						}						e.cancelBubble = true;					}				},				els:[					mkE( {						tag:'h1',						text:xGal[ 'Picture option select user' ]					} )									]			} );			Draugiem.getACFriends.method = 'searchGalleryTagFriends';			var ac = D.Gallery.addPicUserAC = new MultiAc( {				maxLength:1,				unique_values:true,				onGetList:Draugiem.getACFriends,				onChange:function(){									}			} );			ac.append( D.Gallery.addPicUserForm );			mkE( {				tag:'div',								els:[					mkE( {						tag:'br'					} ),					mkE( {						tag:'a',						text:xGal[ 'pic user I' ],						prop:{							href:'#',							onclick:function(){								D.Gallery.activePictureAddUser( id );								return false;							}															}					} ),					mkE( {						tag:'br'					} ),					mkE( {						tag:'br'					} )				]			} ).append( D.Gallery.addPicUserForm );			var buttons = mkE( {				tag:'div',				className:'inlineNewButtons',				prop:{					style:{						textAlign:'right'					}				}			} ).append( D.Gallery.addPicUserForm );			T.submitButton( {				size:'small',				caption:xGlobal[ 'Save' ],				onclick:function(){					if( empty( ac.value() ) ){						Draugiem.blink( {							node:ac.node						} );						return;					}					D.Gallery.activePictureAddUser( ac.value()[ 0 ] );				}			} ).append( buttons );			mkE( {				tag:'span',				prop:{					innerHTML:'&nbsp;'				}			} ).append( buttons );			T.submitButton( {				size:'small',								color:'link',				caption:xGlobal[ 'Cancel' ],				onclick:function(){					D.Gallery.addPicUserSA.clear();					D.Gallery.addPicUserForm.remove();				}			} ).append( buttons );		}		D.Gallery.addPicUserForm.append( document.getElementById( 'galleryLargePictureCenter' ) );		D.Gallery.addPicUserAC.focus();	},		activePictureAddUser:function( uid ){		if( array_search( uid, D.Gallery.activePicture.selectedUsers ) !== false ){			alert( xGal[ 'user is in photo' ] + '!' );			return;		}				var coords = {			x:D.Gallery.addPicUserSA.x,			y:D.Gallery.addPicUserSA.y,			w:D.Gallery.addPicUserSA.w,			h:D.Gallery.addPicUserSA.h		};		D.Gallery.rpc.send(			'addPicUser',			{				pid:D.Gallery.activePicture.id,				fid:uid,				coords:coords			},			function( re, par ){				var node = document.getElementById( 'galleryLargePicSelectedUsers' );				node.style.display = '';				rq( '/gallery/rq/pic_users.php?pid=' + D.Gallery.activePicture.id + '&openPicUsers', node );				if( re.add ){					mkE( {						tag:'a',						className:'galleryLargePicUser',						prop:{							id:'galleryLargePicUser' + re.uid,							href:'/friend/?' + re.uid,							style:{								left:coords.x + 'px',								top:coords.y + 'px',								width:coords.w + 'px',								height:coords.h + 'px'							}						},						els:[							mkE( {								tag:'div',								className:'bg'							} ),							mkE( {								tag:'div',								className:'galleryLargePicUserName',								text:htmlspecialchars_decode( re.userName )							} )						]					} ).append( document.getElementById( 'galleryLargePicture' ) );				}			}		);		D.Gallery.addPicUserForm.remove();		D.Gallery.addPicUserSA.clear();		D.Gallery.addPicUserAC.clear();	},	// --- add pic user ---		setPicRate:function( pid ){		return function( rate, node ){			D.Gallery.rpc.send(					'setPicRate',				{					pid:pid,					rate:rate				},				function( re ){					if( re.rate ){						$( '#galleryLargeVote' ).html( ( xGal[ 'You vote' ] || 'You rate with' ) + ' ' + rate );						node.style.width = re.rate / 5 * 100 + '%';						console.info( node );					}				}			);		};	}, // setPicRate		picOptionsOpen:function( v ){		if( v ){			Draugiem.Cookie.create( 'galleryPicOptionsOpen', 'Y', 7, '/gallery/' );		} else {			Draugiem.Cookie.create( 'galleryPicOptionsOpen', 'N', 7, '/gallery/' );		}	},		picUsersOpen:function( v ){		if( v ){			Draugiem.Cookie.create( 'galleryPicUsersOpen', '1', 7, '/gallery/' );		} else {			Draugiem.Cookie.create( 'galleryPicUsersOpen', '0', 7, '/gallery/' );		}	},		leftAlbumsOpen:function( v ){		if( v ){			Draugiem.Cookie.create( 'galleryOpenLeftAlbums', '1', 7, '/gallery/' );		} else {			Draugiem.Cookie.create( 'galleryOpenLeftAlbums', '0', 7, '/gallery/' );		}	},		checkAddNewAlbumForm:function(){		var titleNode = document.getElementById( 'galleryNewAlbumTitleInput' );		if( empty( titleNode.value ) ){			Draugiem.blink( {				node:titleNode			} );			return false;		}	},		largeRotate:function( pid, angle, get ){		window.anonymous = window.anonymous + 1 || 1;		var varName = 'anonymous' + window.anonymous;		window[ 'anonymous' + window.anonymous ] = function(){			rq('/gallery/rq/pic_content.php?' + get, 'galleryLargePicContent', { overlay:true } );		};		var file = D.Gallery.UPL + 'gallery/rotate.php';		mkE( {			tag:'script',			prop:{				type:'text/javascript',				src:file + '?pids=' + pid + '&angle=' + angle + '&callback=' + varName + '&DS=' + sessid + '&' + ( new Date() ).getTime()			}		} ).append( document.getElementsByTagName( 'head' )[0] );		return false;	},		albumPicsInfoEdited:function( pid ){		document.getElementById( 'galleryEditAlbumPicsInfoEdited' + pid ).value = '1';	},		setVideoThumb:function( el, pid, nr ){		$( 'div', el.parentNode ).removeClass( 'active' );		$( 'input', el.parentNode )[ 0 ].value = nr;		addClassName( el, 'active' );		D.Gallery.albumPicsInfoEdited( pid );	},		addSimpleUpload:function(){		$( '#fsUploadProgress1' ).hide();		$( '#galleryAddUploadButtons' ).hide();		$( '#galleryAddSimpleUpload' ).show();		return false;	},		albumEditRotate:function( pid, angle ){		window.anonymous = window.anonymous + 1 || 1;		var varName = 'anonymous' + window.anonymous;		window[ varName ] = function( data ){			var el = document.getElementById( 'galleryEditAlbumPid' + pid );			el.style.display = 'none';			el.onload = function(){ this.style.display = ''; };			el.src = data[ pid ].urlGM;		};		var file = D.Gallery.UPL + 'gallery/rotate.php';		mkE( {			tag:'script',			prop:{				type:'text/javascript',				src:file + '?pids=' + pid + '&angle=' + angle + '&callback=' + varName + '&DS=' + sessid + '&' + ( new Date() ).getTime()			}		} ).append( document.getElementsByTagName( 'head' )[0] );		return false;	},		albumEditDeleteItem:function( pid ){		D.Gallery.rpc.send(			'deleteItem',			{				pid:pid			},			function(){			}		);		$( '#galleryAlbumEditRow' + pid ).fadeOut();		$( '#galleryAlbumEditRow_' + pid ).hide();	},		copyAlbum:function( sourceAid ){		InfoBox.iframe( '/gallery/rq/album_copy.php?sourceAid=' + sourceAid, { width:350 } );		return false;	},		doCopyAlbum:function( aid ){		$( '#galleryCopyAlbum' ).hide();		D.Gallery.rpc.send(			'copyAlbum',			{				aid:aid			},			function( re ){				$( '#galleryCopyAlbum2' ).show();				D.Gallery.waitingCopyAlbum( re.id );			}		);	},		waitingCopyAlbum:function( aid ){		D.Gallery.rpc.send(			'copyDone',			{				aid:aid			},			function( re ){				if( re.done ){					document.location.href = '/gallery/?aid=' + aid + '&edit'					return;				}				setTimeout( function(){					D.Gallery.waitingCopyAlbum( aid );				}, 1000 );			}		);			},		setAsProfile:function( el, pid ){		el.style.display = 'none';		D.Gallery.rpc.send(			'setAsProfile',			{				pid:pid			},			function( re ){				if( ! re.ok ){					el.style.display = '';				}			}		);		return false;	},		readMoreMMS:function( el ){		$( el ).hide();		$( '#galleryLeftMMSInfo' ).fadeIn();		return false;	},		statsPayment:function(){		InfoBox.open( '/gallery/rq/visitor_payment.php', {width:250} );		return false;	},		leftPayment:function( fid ){		var el = document.getElementById( 'galleryLeftPayment' );		if( el.style.display == 'none' ){			el.style.display = '';			rq( '/gallery/rq/left_payment.php?fid=' + fid, el );		} else {			el.style.display = 'none';		}		return false;	},		extAdd:function(){		var newName = document.getElementById( 'galleryNewAlbumTitleInput' );		var albumSelect = document.getElementById( 'galleryNewAlbumTitleSelect' );		if( ! this.activeAlbum.id ){						if( newName && empty( newName.value ) ){				D.blink( {					node:newName				} );				return;			}			if( albumSelect && empty( albumSelect.value ) ){				D.blink( {					node:albumSelect				} );				return;			}		}		$( '#galleryAddChoose' ).fadeOut();		if( newName ){			newName.disabled = true;		}		if( albumSelect ){			albumSelect.disabled = true;		}		this.extAddItem( 0, this.activeAlbum.id );		document.getElementById( 'galleryExtAddButton' ).style.display = 'none';	},		extAddItem:function( i, aid ){		if( ! this.extAddUrls[ i ] ){			document.getElementById( 'galleryExtAddDone' ).style.display = '';						return;		}		window.anonymous = window.anonymous + 1 || 1;		var varName = 'anonymous' + window.anonymous;		window[ varName ] = function( re ){			if( re.aid ){				aid = re.aid;			}			document.getElementById( 'galleryExtAddLoad' + i ).style.display = 'none';			document.getElementById( 'galleryExtAddOk' + i ).style.display = '';			D.Gallery.extAddItem( i + 1, aid );					};		var file = D.Gallery.UPL + 'gallery/ext_add.php';		var src = file + '?DS=' + sessid + '&callback=' + varName + '&aid=' + aid + '&url=' + encodeURIComponent( this.extAddUrls[ i ] ) + '&tags=' + encodeURIComponent( D.Gallery.extAddTags || '' );		var newName = document.getElementById( 'galleryNewAlbumTitleInput' );		if( ! this.activeAlbum.id ){			src += '&newAlbumTitle=' + encodeURIComponent( newName.value );		}		mkE( {			tag:'script',			prop:{				type:'text/javascript',				src:src			}		} ).append( document.getElementsByTagName( 'head' )[0] );		document.getElementById( 'galleryExtAddLoad' + i ).style.display = '';	},		extAddOnload:function(){		var node = document.getElementById( 'outermost' ) || document.body;		if( node.scrollHeight > node.offsetHeight ){			window.resizeTo( 640, Math.min( node.scrollHeight + 100, 720 ) );		}	},		addPicMap:function( pid ){		InfoBox.iframe( '/gallery/rq/map/addtomap.php?pid=' + pid, { width:600 } );	},		picSmallMap:function( pid ){		return InfoBox.open( '/gallery//rq/map/pic_small_map.php?pid=' + pid, {width:480,height:480} );	}};// +++ large picture thumb slider +++/*	par = {		count:10,		aid:[albuma id] - ja 0, tad maina index	}*/D.Gallery.largePicThumbs = function( par ){	var $largePicThumbs = this;	this.current = 0;	this.count = par.count;	this.contentWidth = this.count * D.Gallery.largePicThumbs.itemWidth;	this.aid = par.aid || 0;	this.calbums = par.calbums || false;	this.picRq = par.picRq || '/gallery/rq/pic_content.php';	this.node = mkE( {		tag:'div',		className:'largePicThumbs',		prop:{			onmousemove:function(){				var y = findPosY( this );				var x = findPosX( this );				var step = 0;				var regLen = 150;				var regK = 5;				if( /*D.mouseY > y &&  D.mouseY < y + 60 &&*/ D.mouseX < x + regLen ){					step = regLen / regK - Math.max( 5 * regK, D.mouseX - x ) / regK;									}				if( /*D.mouseY > y &&  D.mouseY < y + 60 &&*/ D.mouseX > x + this.offsetWidth - regLen ){					step = regLen / regK - Math.max( 5 * regK, ( x + this.offsetWidth ) - D.mouseX  ) / regK;					step = - step;				}				if( $largePicThumbs.interval ){					clearInterval( $largePicThumbs.interval );				}				step = Math.floor( step );				if( ! step ){					return;				}				$largePicThumbs.interval = setInterval( function(){					if( $largePicThumbs.content.offsetLeft + step > 0 ){						return false;					}					if( $largePicThumbs.content.offsetLeft + step < - ( $largePicThumbs.contentWidth - $largePicThumbs.node.offsetWidth ) ){						return false;					}					$largePicThumbs.content.style.left = $largePicThumbs.content.offsetLeft + step + 'px';				}, 100 );			},						onmouseout:function(){				if( $largePicThumbs.interval ){					clearInterval( $largePicThumbs.interval );				}				$largePicThumbs.interval = false;				$largePicThumbs.loadData();			}		},		els:[			this.content = mkE( {				tag:'div',				className:'largePicThumbsContent'			} )		]	} );	this.node.onmouseover = this.node.onmousemove;	this.els = [];	this.returnFalse = function(){		return false;	};	for( var i = 0; i < par.count; i ++ ){		this.els[ i ] = mkE( {			tag:'a',			className:'galleryLargePicThumb',						prop:{				_drPicIndex:i,				href:'',				style:{					left:( i * D.Gallery.largePicThumbs.itemWidth ) + 'px'				},				onclick:this.returnFalse			},			els:[				mkE( {					tag:'div'				} )			]		} ).append( this.content );	}	var get = new Get( document.location.href );	switch( String( get.v( 'selectedTab' ) ) ){		case '5':		case '6':		case '10':		case '12':		case '17':			for( var k in this.els ){				get.add( 'i', k );				this.els[ k ].href = '/gallery/?' + get.str()				this.els[ k ].onclick = function(){					get.add( 'i', this._drPicIndex );					rq( '/gallery/rq/pic_content.php?' + get.str(), 'galleryLargePicContent', {overlay:true} );					return false;				};			}			break;	}};D.Gallery.largePicThumbs.itemWidth = 55;D.Gallery.largePicThumbs.prototype.append = function( el ){	if( typeof el == 'string' ){		el = document.getElementById( el );	}	this.node.append( el );	this.loadData();};D.Gallery.largePicThumbs.prototype.loadData = function(){	var $largePicThumbs = this;	var count = Math.ceil(  this.node.offsetWidth / D.Gallery.largePicThumbs.itemWidth );	var start = Math.abs( Math.floor( this.content.offsetLeft / D.Gallery.largePicThumbs.itemWidth ) );		var end = Math.min( start + count, this.count );	var from = false;	var to = 0;	var ids = [];		for( var i = start; i < end; i ++ ){		if( ! this.els[ i ]._drItem ){			if( from === false ){				from = i;			}			if( i > to ){				to = i;			}			ids.push( i );		}	}	if( this.loading || empty( ids ) ){		return;	}	this.loading = true;	if( this.aid ){		for( var j = i; j < Math.min( start + count + 10, this.count ); j ++ ){ // 10 vēl papildus ielādē, lai nebūtu pie katra pieprasījums			ids.push( j );		}		var resp = function( re ){						for( var k in re.items ){				$largePicThumbs.els[ k ]._drItem = re.items[ k ];				$largePicThumbs.els[ k ].style.backgroundImage = "url('" + re.items[ k ].urlIcon + "')";				$largePicThumbs.els[ k ].href = '/gallery/?pid=' + re.items[ k ].pid;				$largePicThumbs.els[ k ].onclick = function(){					var get = new Get( document.location.href );					get.add( 'pid', this._drItem.pid );					rq( $largePicThumbs.picRq + '?' + get.str(), 'galleryLargePicContent', {overlay:true} );					return false;				};				if( re.items[ k ].type != 0 ){					addClassName( $largePicThumbs.els[ k ], 'video' );				}			}			$largePicThumbs.loading = false;		};				D.Gallery.rpc.send(			'albumThumbsByIndexs',			{				aid:this.aid,				indexs:ids,				calbums:this.calbums			},			resp		);	} else {		var resp = function( re ){						for( var k in re.items ){				$largePicThumbs.els[ k ]._drItem = re.items[ k ];				$largePicThumbs.els[ k ].style.backgroundImage = "url('" + re.items[ k ].urlIcon + "')";				if( re.items[ k ].type != 0 ){					addClassName( $largePicThumbs.els[ k ], 'video' );				}			}			$largePicThumbs.loading = false;		}		var get = new Get( document.location.href );		switch( get.v( 'selectedTab' ) ){			case '5':				D.Gallery.rpc.send(					'getLastestPicThumbs',					{						uid:D.Gallery.UID,						from:from,						to:to					},					resp				);				break;			case '6':				D.Gallery.rpc.send(					'getLastestVideoThumbs',					{						uid:D.Gallery.UID,						from:from,						to:to					},					resp				);				break;			case '10':				D.Gallery.rpc.send(					'getPicsWhereUser',					{						uid:D.Gallery.UID,						from:from,						to:to					},					resp				);				break;			case '12':				D.Gallery.rpc.send(					'myFavThumbsByIndexs',					{						keyword:get.v( 'keyword' ),						from:from,						to:to					},					resp				);				break;			case '17':				D.Gallery.rpc.send(					'searchThumbs',					{						search:get.v( 'search' ),						type:get.v( 'type' ),						from:from,						to:to					},					resp				);				break;		}	}};D.Gallery.largePicThumbs.prototype.setCurrent = function( v ){	var $largePicThumbs = this;	removeClassName( this.els[ this.current ], 'current' );	if( ! this.els[ v ] ){		return;	}	this.current = v;	addClassName( this.els[ v ], 'current' );	function animateEnd(){				$largePicThumbs.loadData();	};	if( v < 6 ){		$( this.content ).animate( { left:0 }, animateEnd );	} else if( this.contentWidth > this.node.offsetWidth ){		if( v > this.count - 7 ){			$( this.content ).animate( { left:- ( this.contentWidth - this.node.offsetWidth ) }, animateEnd );		} else {			$( this.content ).animate( { left:- ( ( v - 6 ) * D.Gallery.largePicThumbs.itemWidth ) }, animateEnd );		}	}};// --- large picture thumb slider ---// +++ slide show +++D.Gallery.SlideShow = function( aid ){	var $slideShow = this;	this.cached = {};	this.aid = aid;	this.bgColors = [ '000000', '666666', 'FFFFFF'	];	this.bgColorItems = {};	this.index = 0;	this.playing = false;	this.node = mkE( {		tag:'div',		className:'gallerySlideShow gallerySlideShow000000',		els:[			this.bg = mkE( {				tag:'div',				className:'gallerySlideShowBg',				els:[					this.loading = mkE( {						tag:'div',						className:'gallerySlideShowLoading',						prop:{							style:{								display:'none'							}						}					} )				]			} ),			this.content = mkE( {				tag:'div',				className:'gallerySlideShowContent',				els:[					this.current = mkE( {						tag:'div',						className:'gallerySlideShowCurrent'					} ),					/* mkE( {						tag:'a',						className:'gallerySlideShowClose',						text:xGal[ 'slide show close' ] || 'Close',						prop:{							href:'#',							onclick:function(){								$slideShow.close();								return false;							}						}					} ), */					mkE( {						tag:'a',						className:'gallerySlideShowCloseImg',						prop:{							href:'#',							onclick:function(){								$slideShow.close();								return false;							}						}					} ),					this.pic2 = mkE( {						tag:'div',						className:'gallerySlideShowPic'					} ),					this.pic = mkE( {						tag:'div',						className:'gallerySlideShowPic',						els:[							this.playButton2 = mkE( {								tag:'div',								className:'gallerySlideShowPlay',								prop:{									onclick:function(){										$slideShow.playButton.onclick();									},									onmouseover:function(){										$( this ).fadeIn();									},									onmouseout:function(){										$( this ).fadeOut();									}								}							} )						]					} ),										this.bgColorItemsContent = mkE( {						tag:'div',						className:'gallerySlideShowBgColor'					} ),										this.tmpImage = mkE( {						tag:'img',						prop:{							style:{								display:'none'							},							onload:function(){								$slideShow.pic2.style.backgroundImage = $slideShow.pic.style.backgroundImage;																$( $slideShow.pic2 ).show();								$( $slideShow.pic2 ).fadeOut();								$( $slideShow.pic ).hide();								$( $slideShow.pic ).fadeIn();								$slideShow.pic.style.backgroundImage = "url('" + this.src + "')";								$slideShow.cacheNext();								$slideShow.loading.style.display = 'none';							}						}					} ),					this.cacheImage = mkE( {						tag:'img',						prop:{							style:{								display:'none'							}						}					} ),					this.timeoutSelect = mkE( {						tag:'select',						className:'gallerySlideShowTimeout inp',						els:[							mkE( {								tag:'option',								text:'1',								prop:{									value:1								}							} ),							mkE( {								tag:'option',								text:'2',								prop:{									value:2								}							} ),							mkE( {								tag:'option',								text:'3',								prop:{									value:3								}							} ),							mkE( {								tag:'option',								text:'4',								prop:{									value:4								}							} ),							mkE( {								tag:'option',								text:'5',								prop:{									value:5								}							} ),							mkE( {								tag:'option',								text:'10',								prop:{									value:10								}							} )						],						prop:{							onchange:function(){								Draugiem.Cookie.create( 'gallerySlideShowTimeout', this.value, 7, '/gallery/' );							}						}					} ),					mkE( {						tag:'div',						className:'gallerySlideShowNavig',						els:[							this.backButton = mkE( {								tag:'a',																className:'gallerySlideShowNavigBack',								prop:{									href:'#',									onclick:function(){										$slideShow.stop();										$slideShow.back();										return false;									}								}							} ),							this.playButton = mkE( {								tag:'a',								className:'gallerySlideShowNavigPlay',								prop:{									href:'#',									onclick:function(){																				if( $slideShow.playing ){											$slideShow.stop();																					} else {											if( $slideShow.index + 1 == $slideShow.picCount ){												$slideShow.index = -1;											}											$slideShow.play();										}										return false;									}								}							} ),							this.nextButton = mkE( {								tag:'a',								className:'gallerySlideShowNavigNext',								prop:{									href:'#',									onclick:function(){										$slideShow.stop();										$slideShow.next();										return false;									}								}							} )						]					} )				]			} ) // .gallerySlideShowContent		]	} ).append( document.body );	this.playButton2.style.opacity = '0';	this.playButton2.style.filter = 'alpha(opacity=0)';	if( Draugiem.Cookie.read( 'gallerySlideShowTimeout' ) ){		this.timeoutSelect.value = Draugiem.Cookie.read( 'gallerySlideShowTimeout' );	} else {		this.timeoutSelect.value = 5;	}	if( Draugiem.Cookie.read( 'gallerySlideShowColor' ) ){		removeClassName( this.node, 'gallerySlideShow000000' );		addClassName( this.node, 'gallerySlideShow' + Draugiem.Cookie.read( 'gallerySlideShowColor' ) );	}	$( this.bgColorItemsContent ).css( { opacity:0 } );	for( var k in this.bgColors ){				this.bgColorItems[ this.bgColors[ k ] ] = mkE( {			tag:'div',			className:'item',			prop:{				style:{					backgroundColor:'#' + this.bgColors[ k ]				},				_drItem:this.bgColors[ k ],				onclick:function(){					Draugiem.Cookie.create( 'gallerySlideShowColor', this._drItem, 7, '/gallery/' );					$slideShow.node.className = 'gallerySlideShow gallerySlideShow' + this._drItem;					$slideShow.bg.style.backgroundColor = '#' + this._drItem;				},				onmouseover:function(){					this.onclick();				}			}		} ).append( this.bgColorItemsContent );	}	$( this.bg ).css( { opacity:0.05 } );	D.Gallery.rpc.send(		'slideShowGetInfo',		{			aid:aid		},		function( re ){			$( $slideShow.bg ).animate( { opacity:0.92 } );			$( $slideShow.bgColorItemsContent ).animate( { opacity:1 } );						$slideShow.picCount = re.picCount;			$slideShow.index = re.pic.index;			$slideShow.loading.style.display = '';			$slideShow.tmpImage.src = re.pic.urlLarge;			$slideShow.current.innerHTML = re.albumTitle + ' - ' + ( $slideShow.index + 1 ) + '. ' + ( xGal[ 'no' ] || 'from' ) + ' ' + $slideShow.picCount;					}	);};D.Gallery.SlideShow.prototype.close = function(){	var $slideShow = this;	$( this.node ).fadeOut( 'fast', function(){		$slideShow.node.remove();	} );	};D.Gallery.SlideShow.prototype.cacheNext = function(){	var $slideShow = this;	if( this.index + 1 >= this.picCount ){		return false;	}	if( $slideShow.cached[ this.index + 1 ] ){		return false;	}	D.Gallery.rpc.send(		'slideShowGetPic',		{			aid:this.aid,			i:this.index + 1		},		function( re ){						$slideShow.cacheImage.src = re.pic.urlLarge;			$slideShow.cached[ re.pic.index ] = re;		}	);};D.Gallery.SlideShow.prototype.back = function(){	var $slideShow = this;	if( this.index - 1 < 0 ){		return false;	}	$slideShow.loading.style.display = '';	var refn = function( re ){		$slideShow.index = re.pic.index;				$slideShow.tmpImage.src = re.pic.urlLarge;		$slideShow.cached[ re.pic.index ] = re;		$slideShow.backButton.disabled = ( $slideShow.index == 0 );		$slideShow.nextButton.disabled = ( $slideShow.index + 1 == $slideShow.picCount );		$slideShow.current.innerHTML = re.albumTitle + ' - ' + ( $slideShow.index + 1 ) + '. ' + ( xGal[ 'no' ] || 'from' ) + ' ' + $slideShow.picCount;		return true;	}	if( $slideShow.cached[ this.index - 1 ] ){		return refn( $slideShow.cached[ this.index - 1 ] );	}	D.Gallery.rpc.send(		'slideShowGetPic',		{			aid:this.aid,			i:this.index - 1		},		refn	);	return true;};D.Gallery.SlideShow.prototype.next = function(){	var $slideShow = this;	if( this.index + 1 >= this.picCount ){		return false;	}	$slideShow.loading.style.display = '';	var refn = function( re ){		$slideShow.index = re.pic.index;				$slideShow.tmpImage.src = re.pic.urlLarge;		$slideShow.cached[ re.pic.index ] = re;		$slideShow.backButton.disabled = ( $slideShow.index == 0 );		$slideShow.nextButton.disabled = ( $slideShow.index + 1 == $slideShow.picCount );		$slideShow.current.innerHTML = re.albumTitle + ' - ' + ( $slideShow.index + 1 ) + '. ' + ( xGal[ 'no' ] || 'from' ) + ' ' + $slideShow.picCount;		return true;	}	if( $slideShow.cached[ this.index + 1 ] ){		return refn( $slideShow.cached[ this.index + 1 ] );	}	D.Gallery.rpc.send(		'slideShowGetPic',		{			aid:this.aid,			i:this.index + 1		},		refn	);	return true;};D.Gallery.SlideShow.prototype.play = function(){	var $slideShow = this;	this.playing = true;	this.timeout = setTimeout( function(){		if( $slideShow.next() ){			$slideShow.play();					} else {			$slideShow.stop();		}	}, this.timeoutSelect.value * 1000 );	addClassName( this.playButton, 'pause' );};D.Gallery.SlideShow.prototype.stop = function(){	this.playing = false;	clearTimeout( this.timeout );	removeClassName( this.playButton, 'pause' );};// --- slide show ---D.Gallery.calbums = {	add:function( type, id, par ){		var url = '/gallery/c_albums/add.php?type=' + type + '&id=' + id;		if( par.uid ){			url += '&uid=' + par.uid;		}		InfoBox.iframe( url, { width:660, height:480 } );		return false;	},		doAdd:function( type, id ){		D.Gallery.rpc.send(			'joinAlbum',			{				type:type,				id:id,				aids:D.Gallery.calbums.tmpApi.value()			},			function( re ){				window.parent.document.location.href = window.parent.document.location.href.split( '#' )[0];			}		);	}};//D.Gallery.text2HTML = {};D.Gallery.text2HTMLShowImage = function( pic, object ){	InfoBox.html( '', {width:100, height:100} );	var img, prev, next;	var pid = pic.getAttribute( 'pid' );			var pids = array_keys( D.Gallery.text2HTML[ object ] );	var n = Number( array_search( pid, pids ) );	var c = count( D.Gallery.text2HTML[ object ] );	var showArrows = function(){		prev.style.display = ( n > 0 ? '' : 'none' );		next.style.display = ( n < c - 1 ? '' : 'none' );	};			var node = mkE( {		tag:'center',		els:[			mkE( {				tag:'div',				prop:{					id:'galleryLargePicture'				},				els:[					prev = mkE( {						tag:'div',						prop:{							id:'galleryLargePicturePrev',							onclick:function(){								n = n - 1;								img.src = D.Gallery.text2HTML[ object ][ pids[ n ] ].urlLarge;								showArrows();							}						},						els:[							mkE( {								tag:'div'							} )						]					} ),					img = mkE( {						tag:'img',						prop:{							onload:function(){								this.style.display = '';								this.parentNode.style.width = this.width + 'px';								InfoBox.resizeTo( '', this.width + 'px', this.height + 'px', {animated:true} );							}						}					} ),					next = mkE( {						tag:'div',						prop:{							id:'galleryLargePictureNext',							onclick:function(){								n = n + 1;								img.src = D.Gallery.text2HTML[ object ][ pids[ n ] ].urlLarge;								showArrows();							}						},						els:[							mkE( {								tag:'div'							} )						]					} )				]			} )		]	} ).append( InfoBox3.content );	img.src = D.Gallery.text2HTML[ object ][ pid ].urlLarge;	showArrows();};