
var selectedPic = 0;

function hoverPic ( pic_id, site )
{
	if (selectedPic==0) return;
	if (selectedPic == pic_id) return;
	if (site==1)
		document.getElementById('p'+pic_id).style.borderLeft="4px solid blue";
	else
		document.getElementById('p'+pic_id).style.borderRight="4px solid blue";
}

function unHoverPic ( pic_id, site )
{
	if (selectedPic==0) return;
	if (selectedPic == pic_id) return;
	if (site==1)
		document.getElementById('p'+pic_id).style.borderLeft="0px solid blue";
	else
		document.getElementById('p'+pic_id).style.borderRight="0px solid blue";
}

function startSorting( pic_id, site )
{
	//alert( pic_id );
	if (selectedPic!=0 && site==0 && pic_id != selectedPic) return; 
	if (selectedPic==0)
	{
	selectedPic = pic_id;
	document.getElementById('p'+pic_id).style.border="1px solid green";
	} else
	{
	if (selectedPic==pic_id) // Gleiches bild
	{
		selectedPic=0;
		document.getElementById('p'+pic_id).style.border="0px solid green";
		return;
	}
	// Echt mal verschieben jetz. 
	//location.href=selfUrl+"&sortBilder&m1="+selectedPic+"&m2="+pic_id;
		document.getElementById('movePicFormPic1').value=selectedPic;
		document.getElementById('movePicFormPic2').value=pic_id;
		document.getElementById('movePicFormSite').value=site;
		document.getElementById('movePicForm').scrolling.value=document.documentElement.scrollTop;
		document.getElementById('movePicForm').submit();
	}
}

function openPic( picUrl )
{
	width = 1010;
	if (! picPopAds)
		width = 850;
	window.open(picUrl,'tt','width='+width+',height=728,screenX=0,screenY=0,scrollbars=yes,resizable=yes');
}
function eCl(id, ownUrl)
{
	var url = popupUrl;
	
	if ( ownUrl != null )
		url = ownUrl;
	window.open(url+'?popup=true&pid='+id+'&action=sendPhoto','ttmail','width=510,height=520,screenX=0,screenY=0,scrollbars=yes,resizable=no');
}
function eOv(item)
{
	item.style.backgroundImage="url("+web_stammverzeichnis+"bilder/"+portal+"/silk/email.png)";
}
function eOu(item)
{
	item.style.backgroundImage="url("+web_stammverzeichnis+"bilder/"+portal+"/silk/email_fade.png)";
}
function openUrlInOpener(url)
{
	try {
	/*	if (typeof opener != "undefined" && opener != null)*/
			var openerUrl = opener.location.href.replace(/http\:\/\/[0-9.]+/,"");
			var goUrl = url.replace(/http\:\/\/[0-9.]+/,"");
			if ( openerUrl != goUrl )
				opener.location.href=url;
			opener.focus();
	} catch(e)
	{
		window.open(url,"website");
	}
	window.close();
}


	var lastOver = 0;
	var showMausPopupTimer = 0;
	var mausPopupVisible = 0;
	var galPreviewLoaded = [];
	var hideMausPopupTimer = 0;
	function hideMausPopup()
	{
		lastOver = 0;
		clearTimeout ( showMausPopupTimer );
		if (mausPopupVisible != 0)
		{
			// document.getElementById( "mausPopupDiv"+mausPopupVisible).style.display="none";
			document.getElementById( "mausPopupDiv").style.display="none";
			mausPopupVisible = 0;
		}

	}
	function ovGalMouseOut( gal_id )
	{
		mouseOutGalerieVorschau(); /* Setzt den Ausblenden-Vorgang in Kraft */
		clearTimeout ( showMausPopupTimer );
		return;
		lastOver = 0;
		if (mausPopupVisible != 0)
		{
			// document.getElementById( "mausPopupDiv"+mausPopupVisible).style.display="none";
			document.getElementById( "mausPopupDiv").style.display="none";
			mausPopupVisible = 0;
		}
	}
	/**
	 * Arbeitet wie htmlspecialchars_decode()
	 * @param {String} str
	 * @returns String
	 */
	function unhtml( str )
	{
		str = str.replace(/&quot;/g, "\"")
			.replace(/&#039;/g,"'")
			.replace(/&amp;/g,"&")
			.replace(/&gt;/g,">")
			.replace(/&lt;/g,"<")
			;
		return str;
	}
	function ovGalMouseOver( gal_id )
	{
		mouseOverGalerieVorschau();	/* Hebt den Ausblendevorgang (falls an) auf   */
		if ( mausPopupVisible == gal_id) return; 
		// if ( mausPopupVisible > 0 ) return; // Ist noch eins offen
		if (mausPopupVisible > 0)
		{
			if (document.getElementById('galDiv'+mausPopupVisible) != null )
				document.getElementById('galDiv'+mausPopupVisible).style.textDecoration='';
		}
		clearTimeout ( showMausPopupTimer );
		// Cache?
		if ( typeof mPopUpCache != "undefined" )
			if ( mPopUpCache[ gal_id ] ) 
			galPreviewLoaded[ gal_id ] = unhtml( mPopUpCache[ gal_id ] );
	
		if ( galPreviewLoaded[ gal_id ] ==null)
			showMausPopupTimer = setTimeout( "showMausPopup("+gal_id+");", 150 );
		else
			showMausPopup(gal_id);
		/*
		showMausPopupTimer = setTimeout( "showMausPopup("+gal_id+");", 20 );*/
	}
	function showMausPopup( gal_id )
	{
		// alert(1);
		mausPopupVisible = gal_id;
	/*	document.getElementById( "mausPopupDiv"+gal_id).style.display="block";*/
		var m = document.getElementById( "mausPopupDiv");
		if ( m == null ) return; 
		m.style.display="block";
		m.innerHTML="<br />&nbsp; Lade...<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />";
		var s = document.documentElement.scrollTop - 160;
		if (s<=0) s=0;
		m.style.top=""+(s*1+20)+"px";
		if ( galPreviewLoaded[ gal_id] ==null)
		getPreview ( gal_id );
		else	document.getElementById('mausPopupDiv').innerHTML = galPreviewLoaded[ gal_id ];
		document.getElementById('mausPopupDiv').onmouseover=mouseOverGalerieVorschau;
		document.getElementById('mausPopupDiv').onmouseout=mouseOutGalerieVorschau;

		// document.getElementById('galDiv'+gal_id).style.textDecoration='underline';
	}
	
	
	function getPreview( gal_id )
	{
		var url = previewURL ;
		var pst = "getPreview=1&gid=" + gal_id; 
		var newFunc = new Function("transport", "var gal_id='"+gal_id+"';"
		+"var text = transport.responseText;"
//		+"document.getElementById('mausPopupDiv'+gal_id).innerHTML=text;"
		+"document.getElementById('mausPopupDiv').innerHTML=text;"
		+"galPreviewLoaded[ gal_id] = text;"
		);
		new Ajax.Request(url,
		{	"method": "post", 
			"postBody": pst, 
			onSuccess: newFunc
		}
		);
	}
	// Maus ist �ber die Vorschau gekommen, wenn sie wieder geht, soll die Vorschau automatisch verschwinden
	var mouseOutTimeout = 0;
	function mouseOverGalerieVorschau()
	{
		clearTimeout(mouseOutTimeout);
//		alert(1);
	}
	function mouseOutGalerieVorschau()
	{
		clearTimeout(mouseOutTimeout);
		mouseOutTimeout = setTimeout("hideMausPopup();",1000 );
//		alert(2);
	}

function picStartPersonMarkieren( popupUrl )
{
//	window.open(popupUrl, "personenSuche", "width=200, height=300,screenX=400,screenY=70,scrollbars=no,resizable=no ");
window.open( popupUrl, 'personenSuche', 'width=470, height=300,screenX=400,screenY=70,scrollbars=no,resizable=no '); 
return false;
	// picStartMarkieren();
}
var markingForUserId="";
var markingForUsername="";
function setMarkierungForUser( for_user_id, for_username, for_modul ) 
{
	if(for_modul == 'profil')
	{
		window.focus();
		document.getElementById('txtFriendUserId').value = for_user_id;
		document.getElementById('addFriend').submit();
	}
	else
	{
		window.focus();
		markingForUserId = for_user_id;
		markingForUsername = for_username;
		if ( $('markingUserName1') ) $('markingUserName1').innerHTML=for_username;
		if ( $('markingUserName2') ) $('markingUserName2').innerHTML=for_username;
		picStartMarkieren();
	}
}
function picStartMichMarkieren()
{
	setMarkierungForUser ( -1, "Ich");
}
function picStartMarkieren()
{
	$('pic_darkener').style.display="block";
	$('pic_kasten').style.display="block";
	if ( $('aMarkieren') )		$('aMarkieren').style.display="none";
	if ( $('aMarkierenExit') )		$('aMarkierenExit').style.display="block";
	if ( $('hideOnStartMarkieren') ) $('hideOnStartMarkieren').style.display="none";
	hideMarkierenMenu();
}
function picStopMarkieren()
{
	$('pic_darkener').style.display="none";
	$('pic_kasten').style.display="none";
	if ( $('aMarkieren') )		$('aMarkieren').style.display="block";
	if ( $('aMarkierenExit') )		$('aMarkierenExit').style.display="none";
	if ( $('hideOnStartMarkieren') ) $('hideOnStartMarkieren').style.display="inline";
}

var hideMarkierenMenuTimer = 0;
function hideMarkierenMenu()
{
	clearTimeout( hideMarkierenMenuTimer );
	document.getElementById("markierenMenu").style.display="none";
}
function markierenMenuOut()
{
	clearTimeout( hideMarkierenMenuTimer );
	hideMarkierenMenuTimer = setTimeout("hideMarkierenMenu()",300);
}
function markierenMenuOver()
{
	clearTimeout( hideMarkierenMenuTimer );
	document.getElementById("markierenMenu").style.display="block";
}


function picRemoveMark()
{

}
function picSubmitMark()
{
	$('picMarkSubmitForm').markX.value = ""+parseInt ( $('pic_kasten').style.left );
	$('picMarkSubmitForm').markY.value = ""+parseInt ( $('pic_kasten').style.top ); 
	$('picMarkSubmitForm').markSizeX.value = ""+parseInt ( $('pic_kasten').style.width );
	$('picMarkSubmitForm').markSizeY.value = ""+parseInt ($('pic_kasten').style.height );
	$('picMarkSubmitForm').markUserId.value = ""+parseInt ( markingForUserId );
	return true;
	return false;
}
function markLstOver( id )
{
	$('mark'+id).style.display="block";
}
function markLstOut( id )
{
	$('mark'+id).style.display="none";
}
function markPicOver( id )
{
	 markLstOver( id );
}
function markPicOut( id )
{
	 markLstOut( id );
}
//Das Objekt, das gerade bewegt wird.
var dragobjekt = null;

// Position, an der das Objekt angeklickt wurde.
var dragx = 0;
var dragy = 0;

// Mausposition
var posx = 0;
var posy = 0;

var global_no_select = false; //for IE



function draginit() {
 // Initialisierung der �berwachung der Events

  document.onmousemove = drag;
  document.onmouseup = dragstop;
}
draginit();

var global_dragResizeIt = false;
 
var overDiv;
var overDivCache;

function dragstart(element, resize) {
   //Wird aufgerufen, wenn ein Objekt bewegt werden soll.
  dragobjekt = element;
  if (resize) global_dragResizeIt = true;
   if (global_dragResizeIt)
    {
 	 dragx = posx - parseInt(dragobjekt.style.width);
     dragy = posy - parseInt(dragobjekt.style.height);
    }
	else
    {
 	 dragx = posx - dragobjekt.offsetLeft;
     dragy = posy - dragobjekt.offsetTop;
    }

  if (global_no_select) return false;
  return false; 
}


function dragstop() {
  //Wird aufgerufen, wenn ein Objekt nicht mehr bewegt werden soll.
 	if (overDiv != null)
	 {
	   document.body.removeChild(overDiv);
	   overDiv=null;
	 }
  global_dragResizeIt = false;
  dragobjekt=null;
  return false;
}

var minDragPosY = 0;
var minDragPosX = 0;

var minDragSizeX = 60;
var minDragSizeY = 60;
var maxDragSizeX = 200;
var maxDragSizeY = 400;

function drag(ereignis) {
  //Wird aufgerufen, wenn die Maus bewegt wird und bewegt bei Bedarf das Objekt.

  posx = document.all ? window.event.clientX : ereignis.pageX;
  posy = document.all ? window.event.clientY : ereignis.pageY;
  if(dragobjekt != null) {
/*
   if (overDiv == null)
   {
    if (overDivCache == null)
    {
	overDiv = document.createElement('div');
	overDivCache = overDiv;
    overDiv.style.zIndex = 10000;
	overDiv.style.position = "absolute";
	overDiv.style.left = "5px";
	overDiv.style.top = "5px";
    }
    else
    overDiv = overDivCache;
    overDiv.style.width = ( (window.innerWidth!=undefined?innerWidth:document.body.clientWidth) - 10 )+'px';
    overDiv.style.height = ( (window.innerHeight!=undefined?innerHeight:document.body.clientHeight) - 10)+'px';
   }
//  overDiv.style.background = "red";
	document.body.appendChild(overDiv);
  /**/
   var newPosX = (posx - dragx); // Bei resizen ist size
   var newPosY = (posy - dragy);
      if (global_dragResizeIt)
    {
	 if (newPosX<minDragSizeX) newPosX = minDragSizeX;
	 if (newPosY<minDragSizeY) newPosY = minDragSizeY;
	 if (newPosX>maxDragSizeX) newPosX = maxDragSizeX;
	 if (newPosY>maxDragSizeY) newPosY = maxDragSizeY;
	 if (newPosX>maxDragPosX-parseInt(dragobjekt.offsetLeft)) newPosX = maxDragPosX-parseInt(dragobjekt.offsetLeft);
	 if (newPosY>maxDragPosY-parseInt(dragobjekt.offsetTop)) newPosY = maxDragPosY-parseInt(dragobjekt.offsetTop);
	 dragobjekt.style.width = newPosX+'px';
	 dragobjekt.style.height = newPosY+'px';
	 if ($('selBorderDiv'))
	 {
	 	$('selBorderDiv').style.height = (newPosY-2)+"px";
	 	$('selBorderDiv').style.width = (newPosX-2)+"px";
		}
	}
   else
   {
		var objSizeX = parseInt(dragobjekt.style.width);
		var objSizeY = parseInt(dragobjekt.style.height);
	     if (newPosX<minDragPosX) newPosX = minDragPosX;
	     if (newPosY<minDragPosY) newPosY = minDragPosY;
	     if (newPosX+objSizeX>maxDragPosX) newPosX = maxDragPosX-objSizeX;
	     if (newPosY+objSizeY>maxDragPosY) newPosY = maxDragPosY-objSizeY;
		 dragobjekt.style.backgroundPosition="-"+newPosX+"px -"+newPosY+"px";
     	dragobjekt.style.left = newPosX + "px";
     	dragobjekt.style.top =  newPosY+ "px";
	}
  }
  if (global_no_select) return false;
}


