
Element.extend({
	setBackgroundPosition: function(x,y){
		var style = this.getComputedStyle();
		if (window.ie) {
			if (x != undefined) this.style.backgroundPositionX = x;
			if (y != undefined) this.style.backgroundPositionY = y;
		} else {
			var xy = style.backgroundPosition.split(' ');
			if (x != undefined) xy[0] = x;
			if (y != undefined) xy[1] = y;
			this.style.backgroundPosition = xy.join(' ');
		}
		return this;
	}
});

function infoPopup(el,evt) {
	
	el = $(el);
	if (el) {
		el.setStyle('position','absolute');
		el.setStyle('display','block');
	}
	
}
function attendantsInfoPopup(el,evt,counter_container) {
	
	var domel = $(el);
	var count_cnt = $(counter_container);
	infoPopup(el,evt);
	
	new Ajax('/cgi-bin/users.cgi',{
		data: { op: 'ATTENDANTS_LIST' },
		onComplete: function(){
			var rslt = Json.evaluate(this.response.text);
			if (rslt.success && eval(rslt.success)) {
				try { domel.getElement('img[id=_spinner_attlist]').remove(); } catch(ex) {}
				try { domel.getElement('table').remove(); } catch(ex) {}
				var table = new Element('table',{ 'cellpadding': 6, 'cellspacing': 0 });
				var tbody = new Element('tbody').inject(table);
				var tr = null;
				var run_count = 0;
				rslt.users.each(function(u) {
					if (!tr) { tr = new Element('tr').inject(tbody); }
					new Element('td').adopt(
						new Element('img',{
							'styles': { 'margin-right': 6 },
							'src': u.avatar, 
							'width': '50', 'height': '50',
							'align': "top"
						}),
						new Element('a',{ 'href': "/my/users.html?"+u.uid }).setText(u.nick)
					).inject(tr);
					if (++run_count % 6 == 0) tr = null;
				});
				table.inject(domel);
				count_cnt && count_cnt.setText(rslt.users.length);
			}
			try { rslt.msg && alert(rslt.msg) } catch(ex) {};
		}
	}).request();
	
}


function createCurtain(el2hide,applyIE6SelFix) {

	if ($(el2hide)) {
		
		var dim = $(el2hide).getCoordinates();
		
		var curtain = new Element('div', {
			'styles': {
				'position': 'absolute',
				'z-index': 1000,
				'top': dim.top + 'px',
				'left': dim.left + 'px',
				'width': dim.width + 'px',
				'height': dim.height + 'px',
				'background-color': '#fff',
				'opacity': 0.6,
				'filter': 'alpha(opacity=60)'
			}
		});
		
		curtain.injectTop(document.body);
		
		if (applyIE6SelFix && 
			navigator.userAgent.match(/MSIE/) &&
			parseInt(navigator.appVersion.match(/^\d+/)) <= 6) {
			$ES('select',el2hide).each(function(sel) {
				sel.style.visibility = 'hidden';
				//sel.disabled = true;
			});
			curtain.ie6fixApplied = true;
			curtain.hiddenElement = el2hide;
		}
		return curtain;
	}

	return null;

}

function destroyCurtain(curtain) {
	
	if (curtain) {
	
		if (curtain.ie6fixApplied) {
			$ES('select',curtain.hiddenElement).each(function(sel) {
				sel.style.visibility = '';
				//sel.disabled = false;
			});
		}
		curtain.remove();
	}
	
}

function hookHoverBehaviour() {

	$(document.body).getElements('*[hoverclass]','nocache').each(function(el){
		$(el).set({
			events: {
				'mouseenter': function() {
					this.addClass(this.getProperty('hoverclass'));
				},
				'mouseleave': function() {
					this.removeClass(this.getProperty('hoverclass'));
				}
			}
		});
	});

}

function pngfix() {
	
	if (navigator.userAgent.match(/MSIE/) &&
		parseInt(navigator.appVersion.match(/^\d+/)) <= 6) {
		
		if ($$('base') && $$('base').getProperty('href')) {
			alert($$('base').getProperty('href'));
		}
		
		$(document.body).getElements('img[src$=png]').each(function(el,idx){
			var s = el.getSize();
			var src = el.getProperty('src');
			el.setStyles({
				filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"')",
				width: s.size.x,
				height: s.size.y
			});
		});
		
	}
	
}

function makeModalDiv(opacity,fill) {

	fill = fill || '#000';
	opacity = parseInt(opacity) || 75;

	var wsz = self.getSize();
	var padTop = parseInt($(document.body).getComputedStyle().paddingTop);
	var padLeft = parseInt($(document.body).getComputedStyle().paddingLeft);

	var shutter = new Element('div', {
		'styles': {
			'position': 'fixed',
			'z-index': 1000,
			'top': -padTop,
			'left': -padLeft,
			//'width': wsz.size.x + padLeft,
			//'height': wsz.size.y + padTop,
			'width': 10000,
			'height': 10000,
			'background-color': fill,
			'opacity': opacity/100,
			'filter': 'alpha(opacity='+opacity+')'
		}
	});
/*
	new Element('div', {
		'styles': {
			'position': 'fixed',
			'z-index': 1000,
			'top': 100,
			'left': 100,
			'width': 300,
			'height': 300,
			'background-color': '#fff'
		}
	}).inject(document.body);

*/	
	shutter.injectTop(document.body);
	

}

function destroyGame(g,id) {
	new Ajax('/cgi-bin/board-game.cgi',{
		data: {
			'game': g,
			'destroy': id
		},
		onComplete: function() {
			// alert(this.response.text);
		}
	}).request();
}































