// JavaScript Document

function check_pa()
{
	if ( $('pa_me_1').checked == true || $('pa_me_2').checked == true ) return true;
	alert('Bitte gib an ob du auf dem Bild zu sehen bist!');
	return false;
}

function do_nothing(e)
{
	Event.stop(e);
}

function pic_link_mark_create(data,x,y)
{
	Element.insert('pic_marks',{'bottom':'<a id="pl'+data['id']+'" href="profil.php?id='+data['id']+'" class="pic_mark '+data['geschlecht']+'" onclick="return profil(this.href)"  onmouseover="$(\'pi'+data['id']+'\').show()" onmouseout="$(\'pi'+data['id']+'\').hide()" style="top:'+y+'px; left:'+x+'px;"><div class="pic_mark_b"></div></a><div id="pi'+data['id']+'" class="pic_mark_info" style="top:'+y+'px; left:'+x+'px; display:none;"><strong class="'+data['geschlecht']+'">'+data['name']+'</strong><br />'+data['ort']+'</div>'});
	$('pic_link_whois_box').show();
	$('pic_link_whois').insert ({'top':'<a id="pl_whois_'+pl['id']+'" href="profil.php?id='+data['id']+'" onclick="profil(this.href); return false;" target="_blank" class="usrLink '+data['geschlecht']+'">'+data['name']+'</a> '} ); 
}

function pic_link_cancel()
{
	$('pa_me_1').checked=false;
	$('pa_me_2').checked=false;
	//$('pa_public_1').checked=false;
	//$('pa_public_2').checked=false;	
	$('partyalbum').hide();	
	$('partyalbum_link').show();
	pic_link_clear(); 
	pic_link_stop();
}

function eventHandlerFunction(e) 
{
	var element = Event.element(e);
	var mouseX = Event.pointerX(e), mouseY = Event.pointerY(e);
	Event.stop(e);
	pic_link_mark_create(pl,mouseX,mouseY)
	$('mouse_x').value=mouseX;
	$('mouse_y').value=mouseY;
	$('pic_mark_edit_you').hide();
	$('partyalbum').style.zIndex=30;
	$('pic_wrapper').style.zIndex=0;
	$('pic_mark_edit').style.zIndex=0;
}

function pic_link_get_friends(q)
{
	new Ajax.Updater('pl_friends','ajax/partypics_link_friend.php',{method:'post', parameters:{pic_id:pl['pic_id'],query:q}});
}


function eh_friend(e) 
{
	var element = Event.element(e);
	var mouseX = Event.pointerX(e), mouseY = Event.pointerY(e);
	$('pic_mark_edit').show();
	Event.stop(e);
	Element.insert('pic_marks',{'bottom':'<'+'a id="pl_tmp_pic_link" href="#" onclick="return false;" class="pic_mark m" style="top:'+mouseY+'px; left:'+mouseX+'px;"><div class="pic_mark_b"></div></a'+'><div id="pi_tmp_pic_link" class="pic_mark_info" style="top:'+mouseY+'px; left:'+mouseX+'px;"><form><input name="a" type="text" class="txt" onkeyup="pic_link_get_friends(this.value)" /><select id="pl_friends" size="7"></select><input type="button" class="btn" onclick="return pic_link_set('+pl['pic_id']+',$(\'pl_friends\').value,'+mouseX+','+mouseY+')" value="OK">&nbsp;<input type="button" class="btn" onclick="pic_link_stop(); return false;" value="Abrechen"></form></div>'});
	pic_link_get_friends('');
	Event.stopObserving('partypic', "click", eh_friend );
	Event.observe('partypic', "click", do_nothing );
}

function pic_link_set(pic_id,id,x,y)
{
	if ( $('pl_tmp_pic_link') ) $('pl_tmp_pic_link','pi_tmp_pic_link').invoke('remove');
	new Ajax.Request('ajax/partypics_link_set.php?pic_id='+pic_id+'&id='+id+'&x='+x+'&y='+y, {method: 'post', onSuccess: function(t) { data = t.responseText.evalJSON(true); pic_link_mark_create(data,x,y); } });
	pic_link_stop();
	return false;
}

function pic_friend_link_start(pic_id)
{
	Event.stopObserving('pic_wrapper','mouseout');
	Event.observe('partypic', "click", eh_friend );
	$('partypic').style.cursor='crosshair';
	$('over','pic_mark_edit').invoke('show');
}

function pic_link_start()
{
	Event.stopObserving('pic_wrapper','mouseout');
	Event.observe('partypic', "click", eventHandlerFunction );
	$('partypic').style.cursor='crosshair';
	$('over').show();
	$('pic_mark_edit_you').show();
}

function pic_link_confirm_start()
{
	Event.stopObserving('pic_wrapper','mouseout');
	$('over').show();
}

function pic_link_clear()
{
	if ( $('pl_whois_'+pl['id']) ) $('pl_whois_'+pl['id']).remove();
	if ( $('pl'+pl['id']) ) $('pl'+pl['id']).remove();
	$('mouse_x').value=0;
	$('mouse_y').value=0;
}

function pic_link_stop()
{
	$('pic_wrapper').style.zIndex=50;
	$('pic_mark_edit').style.zIndex=30;
	$('partyalbum').style.zIndex=0;
	Event.observe('pic_wrapper','mouseout', function(e){$('pic_marks').hide()} );
	if ( $('pl_tmp_pic_link') ) $('pl_tmp_pic_link','pi_tmp_pic_link').invoke('remove');
	Event.stopObserving('partypic', 'click');
	$('partypic').style.cursor='default';
	$('over','pic_mark_edit').invoke('hide');
}
