function show_popup_at(x, y, element){
	var cell_elem = $("c" + x + "-" + y);
	element.setStyle({'position': 'absolute', 'top': cell_elem.cumulativeOffset()[1] + 'px', 'left' : cell_elem.cumulativeOffset()[0] + 'px'});
		document.body.insert(element);
		new Effect.Puff(element.id, {'duration': 0.3});
		setTimeout("$('" + element.id + "').remove()", 1000);
}
function show_gadget_popup_for(player_guid, x, y, name, title) {
	if(PLAYER_GUID == '' || player_guid == PLAYER_GUID) {
		//Sound.play(ASSET_HOST + '/sounds/new_gadget.mp3');
		var popup_id = 'gadget_' + x + '_' + y + '_' + Math.floor(Math.random()*10000);
	
		var gadget = new Element('div', {'id': popup_id, 'class' : 'gadget_popup'});
		gadget.innerHTML = title;
		show_popup_at(x, y, gadget);
	}
}
function show_omg_for(player_guid, x, y, text) {
	if(PLAYER_GUID == '' || player_guid == PLAYER_GUID) {	
		var popup_id = 'popup_' + x + '_' + y + '_' + Math.floor(Math.random()*10000);
	
		var popup = new Element('div', {'id': popup_id, 'class' : 'omg_popup'});
		popup.innerHTML = text;
		show_popup_at(x, y, popup);
	}
}
function show_impact_for(x, y, pl_guid){
	var elem = $("c" + x + "-" + y);
	var expl_id = 'explosion_' + x + '_' + y + '_' + Math.floor(Math.random()*10000);
	var src = 'bomb';
	if(PLAYER_GUID == '' || pl_guid == PLAYER_GUID) {
		src = 'loser';
	}
	var expl = new Element('img', {'id': expl_id});
	set_cell_img(expl, src);
	expl.setStyle({'position': 'absolute', 'top': elem.cumulativeOffset()[1] + 'px', 'left' : elem.cumulativeOffset()[0] + 'px'});
	document.body.insert(expl);
	new Effect.Puff(expl_id, {'duration': 0.3});
	setTimeout("$('" + expl_id + "').remove()", 1000);
}
function shake_field_for(pl_guid){
	if(PLAYER_GUID == '' || pl_guid == PLAYER_GUID) {
		new Effect.Shake('field', {'duration': 0.1, 'distance':3});
		//new Effect.Highlight('field_container', {startcolor : '#ff0000'});
	}
}
function show_win_for(player_guid) {
	var popup_id = 'gadget_' + '_' + Math.floor(Math.random()*10000);

	var win;
	if(player_guid == PLAYER_GUID){
	 	win = new Element('div', {'id': popup_id, 'class' : 'win_popup'});
		win.innerHTML = 'WIN!';
	}else{
		win = new Element('div', {'id': popup_id, 'class' : 'lose_popup'});
		win.innerHTML = 'YOU LOST';
	}
	show_popup_at((FIELD_WIDTH / 2).floor(), (FIELD_HEIGHT / 2).floor(), win);
}
function blink(color) {
	new Effect.Highlight(document.body, { startcolor: color});
}
function set_player_order(array){
	var was_first = Sortable.sequence('player_list')[0];
	Sortable.setSequence("player_list", array);
	if (was_first != array[0]){
		new Effect.Highlight("player_li_" + array[0])//, {startcolor: '#90EE90'});
	}
}