// SCROLLER START
var move = 0;
var wfocus = 0;
var loaded = false;
var scrollframe_width = 0;

if (navigator.appName == "Microsoft Internet Explorer") {
        active_element = document.activeElement;
        document.onfocusout = whenBlur;
} else { window.onblur = whenBlur; }
 
function whenBlur() {
	if(loaded) {
		move=0;
		wfocus=0;
	}
}
window.onfocus=function () {
	if(loaded) {
		move=1;
		wfocus=1;
	}
}

function init(in_move,warning) {
  scrollframe_width=document.getElementById("scrollframe").style.width;
  window.setInterval("scroll()",40);  
  move=1;
  if(warning!='') {
    window.setTimeout("alert('"+warning+"')",1);
  }
  blur_it();
  loaded=1;
}

function scroll() {
   if(parseInt(document.getElementById("scrollcontent").style.left)<=-(parseInt(document.getElementById("scrollcontent").offsetWidth))) {
     document.getElementById("scrollcontent").style.left=scrollframe_width;
   }
   document.getElementById("scrollcontent").style.left=parseInt(document.getElementById("scrollcontent").style.left)-(3*move)+"px";
}
// SCROLLER ENDE


// MENU START
function jshow(id) {
var d = document.getElementById(id);
  for (var i = 1; i<=10; i++) {
    if (document.getElementById('smenu'+i) && (('smenu'+i)!=id)) {
      document.getElementById('smenu'+i).style.display='block';
      document.getElementById('smenu'+i).style.visibility='hidden';
    }
  }
  if (d) {
    d.style.visibility='visible';
  }
}
// MENU ENDE

// HOVER START
function findPos(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    curleft = obj.offsetLeft;
    curtop = obj.offsetTop;
    while (obj = obj.offsetParent) {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    }
  }
  return [curtop,curleft];
}
var timer=0;
function frhov(id,g) {
  if(timer)
    window.clearTimeout(timer);
  timer=window.setTimeout("hov("+id+",'"+g+"')",400);
}
function hov(id,g) {
  var a=document.getElementById('CB');
  a.style.display='none';
  var p=document.getElementById('a'+id); 
  var c=document.getElementById('ac'+id);
  if(p) {
    pos=findPos(p);
	 wid=p.style.width;
  }
  if(a) {
    a.innerHTML=c.innerHTML;
    a.style.top=pos[0]+'px';
    a.style.left=pos[1]+'px';
    a.className='cb'+g;
    a.style.display='block';
	 a.style.width=wid;
  }
}
function hide(id) {
  var a=document.getElementById(id);
  if(a)
     a.style.display='none';
}
// HOVER ENDE

// MISC START
function del_item(id,info,to) {
   var d=document.getElementById('item'+id);
   if(d) {
      var old_color=d.style.color;
      var old_class=d.className;
      d.style.color='red';
      d.className+=' del';
      if(confirm(info+' wirklich löschen?')) {
         window.top.location.href='index.php?c='+to+'_s&ds='+id;
      } else {
         d.style.color=old_color;
         d.className=old_class;
      }
   }

}

function blur_it() {
  var alla=document.getElementsByTagName('a');
  if(alla) {
    for(var i=0;i<alla.length;i++) {
      if(alla[i])
        alla[i].onfocus=new Function("if(this.blur)this.blur();");
    }
  }
}
// MISC ENDE


// NEWS START
function del_img(id,p,c) {
   var a=document.getElementById(p+id);
   if(a) {
      var tmp=a.style.border;
      a.style.border='1px solid red';
      if(confirm('Dieses Bild wirklich löschen?')) {
         window.top.location.href='index.php?c='+c+'_s&dbid='+id;
      } else {
         a.style.border=tmp;
      }
   }
}
function hide_bup(id) {
   var bup=document.getElementById('bup'+id);
   if(bup)
     bup.style.display='none';
}
function show_bup(id) {
   var bup=document.getElementById('bup'+id);
   if(bup)
     bup.style.display='block';
}
var eoi_open=0;
function edit_img(bid) {
   if(eoi_open==bid) {
     var d=document.getElementById('JS_FRAME');
     if(d.style.display=='block')
       d.style.display='none';
     eoi_open=0;
     return true;
   }
   eoi_open=bid;
   var d=document.getElementById('JS_FRAME');
   var c=document.getElementById('JS_FORM');
   var b=document.getElementById('b'+bid);
   var e=document.getElementById('c'+bid);
   if(b) {
      var pos=findPos(b);
   }
   if(d) {
      d.style.display='block';
      d.style.top=pos[0]+24+'px';
      if((pos[1]+32)<400) {
        d.style.left=pos[1]+32+'px';
      } else {
        d.style.left='420px';
      }
   }
   if(c) {
      var a="";
      a+='<p class="form_label" style="width:100px;">BILD INFO</p>';
      a+='<p class="form_input"><textarea name="info" cols="40" rows="5">'+e.innerHTML+'</textarea></p>';
      a+='<div class="spacer"></div>';
      a+='<input type="hidden" name="b_id" value="'+bid+'">';
      c.innerHTML=a;
   }
   return true;
}
function close_this() {
  var d=document.getElementById('JS_FRAME');
  d.style.display='none';
  eoi_open=0;
}
function del_item(id,p,c,PID) {
   var a=document.getElementById(p+id);
   if(a) {
      var tmp=a.style.border;
      a.style.border='1px solid red';
      if(confirm('Dieses Element und alle ggf. vorhandenen Unterelemente wirklich löschen?')) {
         if(PID)
           window.top.location.href='index.php?c='+c+'_s&p='+PID+'&did='+id;
         else
           window.top.location.href='index.php?c='+c+'_s&did='+id;
      } else {
         a.style.border=tmp;
      }
   }
}


// NEWS ENDE

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function getPageScroll() {
	if (self.pageYOffset) {
		return this.isFrame ? parent.pageYOffset : self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		return document.documentElement.scrollTop;
	} else if (document.body) {
		return document.body.scrollTop;
	}
}
function openMp3Player(pid) {
	arrayPageSize = getPageSize();
	
	document.title=document.title.replace(/#.*/g,'');
	
	if($('overlay')) 
		$('overlay').remove();
	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objOverlay.onclick = function() { closeMp3Player();}
	objBody.appendChild(objOverlay);	
	
	$('overlay').style.width=arrayPageSize[0]+"px";
	$('overlay').style.height=arrayPageSize[1]+"px";	
	
  new Ajax.Request('index.php?c=getmp3player&p='+pid,
  {
   method:'POST',
   requestHeaders:{'Cache-control':'no-cache'},
   onComplete: function (obj) {
		if(obj.responseText!="") {					
			move=0; // disable ticker
			new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.6 });
			$('mp3playercontent').innerHTML=obj.responseText;
			$('mp3player').style.top = (getPageScroll() + (getPageSize()[3] / 3)) + "px";
			$('mp3player').style.display="block";
		} else {
			alert('Bitte zuerst einloggen!');
		}
   }
  }); 
}
function closeMp3Player() {
	$('mp3playercontent').innerHTML="";
	$('mp3player').style.display="none";
	$('overlay').remove();
	move=1; // reenable ticker
}