$(document).ready(function() {
  $('.teaser').click( function(){
    tmp = $(this).attr("id").split("_");
    updateAktuelles(tmp[1]); 
  }); 
}); 

function popup(urli,w,h)
{
	window.open(urli,'Bild','width='+w+',height='+h+',status=yes,scrollbars=no,resizable=yes');
}

	  
	function foo(){
		//styles anpassen
		if(listObj.firstChild.nodeName == "LI") //IE
			leObj = listObj.firstChild;	
		else //FF
			leObj = listObj.firstChild.nextSibling; 
		
		
		var hoehe = 0;
		var elemente = listObj.childNodes;
		for(i=0;i<elemente.length;i++)
		{
			//alert("addiere "+elemente[i].offsetHeight);
			if(elemente[i].offsetHeight != undefined)
				hoehe+= parseInt(elemente[i].offsetHeight);
		}

		//var hoehe = sizesdiv.offsetHeight ? parseInt(sizesdiv.offsetHeight) : 0;
		hoehe+= 14;

		if(hoehe == 34)
			hoehe = 20;
		leObj.style.backgroundColor = "#ACADAD";
		leObj.style.borderColor = "#FFFFFF";
		listObj.style.height = hoehe+"px";
		listObj.style.backgroundColor = "#ACADAD";
		listObj.style.top = "-13px";
		listObj.style.paddingTop = "13px";
		leObj.style.color = "#FFFFFF";
		

		pos = getPosition(listObj.id);
		
		//erstelle ein div. .. 
		div = document.getElementById("dasTransparenteDiv");
		div.style.left = pos+"px";
		div.style.display = "block";
	}
	
	function stopOverlay(listObj)
	{
	  
	}
	
	function foo2(){
		//styles anpassen
		if(listObj.firstChild.nodeName == "LI") //IE
			leObj = listObj.firstChild;	
		else //FF
			leObj = listObj.firstChild.nextSibling; 

		if(leObj.className != "firstdg")
		{
			leObj.style.backgroundColor = "#FFFFFF";
		}
		leObj.style.borderColor = "#000000";
		leObj.style.color = "#000000";
		listObj.style.height = "20px";
		listObj.style.top = "0px";
		listObj.style.paddingTop = "0px";		
		
		listObj.style.backgroundColor = "#FFFFFF";
		transdiv = document.getElementById("dasTransparenteDiv");
		if(transdiv)
			transdiv.style.display = "none"; //transdiv.parentNode.removeChild(transdiv);
		
	}	
	
	function getPosition(div_id)
	{
		nr = parseInt(div_id.substr(3));
		start = 57; //131
		num = nr - 1;
		pos = start + (num * 94);
		return pos;
	}
		
	function getPageCoords (elementId) 
	{
    var element;
    if (document.all)
      element = document.all[elementId];
    else if (document.getElementById)
      element = document.getElementById(elementId);
    if (element) 
    {
	    var coords = {x: 0, y: 0};
	    do 
	    {
	    	if(element.currentStyle)
	      {
	      	if(element.currentStyle.position!='relative')
	        {
	        	coords.x += element.offsetLeft;
	          coords.y += element.offsetTop;
	        }
	      }
	      else
	      {
	        coords.x += element.offsetLeft;
	        coords.y += element.offsetTop;
	      }
	      element = element.offsetParent;
	    }
	    while (element)
	    return coords;
  	}
    else
     return null;
	}  	
	
	function updateAktuelles(id){
	  $.get(BASEPATH +'inc/ajax.loadAktuell.php?id='+id, function(text){
	    
	    akt = "";
	    beitrag = Array(); 
  	  zuweisungen = text.split("###");
  	  for(i=0;i<zuweisungen.length;i++){
  	    tmp = zuweisungen[i].split("~|~");
  	    key = tmp[0];
  	    val = tmp[1];
  	    beitrag[key] = val;
  	  }	  

  	  akt+= '<p class="datum">'+beitrag['created']+'</p>';
  	  akt+= '<h2>'+beitrag['headline']+'</h2>';
  	  if(beitrag['picture']){
    	  akt+= '<a href="#" onclick="popup(\''+BASEPATH+'site_php/popup_pics.php?p='+beitrag['picture']+'\','+(beitrag['w'] ? beitrag['w'] : '200')+','+(beitrag['h'] ? beitrag['h'] : 100)+');"><img src="'+BASEPATH+'img/uploaded/'+beitrag['picture']+'" alt="'+beitrag['pictext']+'" title="'+beitrag['pictext']+'" class="floatleft margr5" '+(beitrag['correctwidth'] ? 'width="'+beitrag['correctwidth']+'"' : '')+'/></a>';
      }        
      akt+= beitrag['content_text'];   	    
	    $('#aktuelles-main').html(akt);
	  });

	}
	
	function updateAktContent()
	{
	  var res = ajaxObject.response;
	  //key~|~wert###key~|~wert###
	  
	  beitrag = Array();
	  zuweisungen = res.split("###");
	  for(i=0;i<zuweisungen.length;i++)
	  {
	    tmp = zuweisungen[i].split("~|~");
	    key = tmp[0];
	    val = tmp[1];
	    beitrag[key] = val;
	  }	  
	  
	  //div holen
	  div = document.getElementById("akt_contentbox");
	  if(!div)
	    return;
	  
	  div.innerHTML = '';
	  div.innerHTML+= '<p class="datum">'+beitrag['created']+'</p>';
	  div.innerHTML+= '<h2>'+beitrag['headline']+'</h2>';
	  if(beitrag['picture'])
	  {
  	  div.innerHTML+= '<a href="#" onclick="popup(\''+BASEPATH+'site_php/popup_pics.php?p='+beitrag['picture']+'\','+(beitrag['w'] ? beitrag['w'] : '200')+','+(beitrag['h'] ? beitrag['h'] : 100)+');"><img src="'+BASEPATH+'img/uploaded/'+beitrag['picture']+'" alt="'+beitrag['pictext']+'" title="'+beitrag['pictext']+'" class="floatleft margr5" '+(beitrag['correctwidth'] ? 'width="'+beitrag['correctwidth']+'"' : '')+'/></a>';
    }        
    div.innerHTML+= beitrag['content_text'];   
	}


function startAV(galID)
{
  opts = 'width=980,height=750,status=yes,scrollbars=no,resizable=yes';
  win = window.open(BASEPATH+'site_php/autoviewer.php?gal='+galID,'Galerie',opts);
}
