window.addEvent('domready', function() {
	new UvumiDropdown('unav');

	var gdivs = $$('div[class=galleria]');
	if ( gdivs[0] != null ) {
		loadGallery( gdivs[0] );
	} else {
		var ginps = $$('input[name=galleria_id]')
		if ( ginps[0] != null ) {
			createGallery( ginps[0] );
		}
	}
	
	
	
});

function clearDefault( input, defaultValue ) {
	if ( input.value == defaultValue ) {
		input.value = "";
		input.setStyle('color', 'black');
	}
}

function loadGallery( gdiv ) {
	
	var hReq = new Request.HTML({
		url: '?m=gallery&a=xload&gid='+gdiv.id,
		evalScripts: false,
		evalResponse: false,
		onSuccess: function( tree, elems, html, js ) {
			
			gdiv.set('html', html);
			$exec(js);
			$$(document.links).filter(function(el) {
				return el.rel && el.rel.test(/^lightbox/i);
			
            }).slimbox({ initialWidth: 820 }, null, function(el) {
                $('lbCenter').setStyle('margin-left', $('lbBottomContainer').getStyle('margin-left'));
                return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
            });
			
		}
	}).send();
	
}

function createGallery( gin ) {
	
	var hReq = new Request.HTML({
		url: '?m=gallery&a=xload&gid='+gin.value,
		evalScripts: false,
		evalResponse: false,
		onSuccess: function( tree, elems, html, js ) {
			
			gdiv = new Element('div', { id: 'gallery_'+gin.value });
			gdiv.set('html', html);
			gdiv.inject(gin, 'after');
			
			$exec(js);
			$$(document.links).filter(function(el) {
				return el.rel && el.rel.test(/^lightbox/i);
			
            }).slimbox({ initialWidth: 820 }, null, function(el) {
                $('lbCenter').setStyle('margin-left', $('lbBottomContainer').getStyle('margin-left'));
                return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
            });
			
		}
	}).send();
	
}
