// ICSL.at Javascripts
// ---------------------------------

// allgemeines
var SLIDETIMER = 3;
var SLIDESPEED = 3;
var SCROLLTIMER = 3;
var SCROLLSPEED = 3;
var STARTINGOPACITY = 40;
var scrolllistpause='off'

// scrollt  nach oben
function scrollup() {
	var test = div.section - 1;
	slideContent(prefix + '-' + test,prefix,timer);
}

// toggelt ein div sicht/unsicht-bar
function togglebox(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
// verändert den Pause/Play Knopf auf der Startseite
function swapplaypause() {

	if(scrolllistpause == 'on'){
		var divplaypause = document.getElementById('scrollplaypausebutton');
		divplaypause.src = 'http://www.icsl.at/beta/images/scrolllist-bottom-right-pause.png';
   		autoScroll('scroll-list-right-newsslider','scroll-list-right-news',4,true);
   		scrolllistpause = 'off';
	}
	else {
		var divplaypause = document.getElementById('scrollplaypausebutton');
		divplaypause.src = 'http://www.icsl.at/beta/images/scrolllist-bottom-right-play.png';
		cancelAutoScroll('scroll-list-right-newsslider');
		scrolllistpause = 'on';
	}
}

// öffnet Popups
function admin_popup(file,w,h)
{
popupwindow = window.open(file,'_blank','width='+w+', height='+h+', resizable=yes, scrollbars=yes, menubar=no, location=no, toolbar=no');
popupwindow.focus();
return false;
}

// schliesst Popups und refresht eine Hauptseite
function admin_popup_close(url)
{
	window.opener.location.href=url;
	window.close();
}

// schliesst ein Popup einfach
function admin_popup_close_self(){
	window.close();
	return true;
}

// switcht die news unten rechts durch
function toggleswitch_bottom_right(id)
{
	lnk1=document.getElementById('rounded-big-bottom-right-menu-1');
	lnk2=document.getElementById('rounded-big-bottom-right-menu-2');
	lnk3=document.getElementById('rounded-big-bottom-right-menu-3');
	
	cnt1=document.getElementById('rounded-big-bottom-right-content-1');
	cnt2=document.getElementById('rounded-big-bottom-right-content-2');
	cnt3=document.getElementById('rounded-big-bottom-right-content-3');

	lnkact=document.getElementById('rounded-big-bottom-right-menu' + '-' + id);
	cntact=document.getElementById('rounded-big-bottom-right-content' + '-' + id);
	
	lnk1.style.backgroundImage = "url(http://www.icsl.at/beta/images/rounded-big-bottom-right-menu.png)";
	lnk1.style.color = "#000";
	lnk2.style.backgroundImage = "url(http://www.icsl.at/beta/images/rounded-big-bottom-right-menu.png)";
	lnk2.style.color = "#000";
	lnk3.style.backgroundImage = "url(http://www.icsl.at/beta/images/rounded-big-bottom-right-menu.png)";
	lnk3.style.color = "#000";
	
	cnt1.style.display = "none";
	cnt2.style.display = "none";
	cnt3.style.display = "none";
	
	lnkact.style.backgroundImage = "url(http://www.icsl.at/beta/images/rounded-big-bottom-right-menu-active.png)";
	lnkact.style.color = "#fff";
	
	cntact.style.display = "block";
}

// wechselt die news unten rechts automatisch durch
function toggleswitch_bottom_left(div)
{
var divs_left = ['toggleauto_content_1','toggleauto_content_2','toggleauto_content_3'];
for(var i=0; i<divs_left.length; i++)
{ obj=document.getElementById(divs_left[i]);
obj.style.display=(divs_left[i]==div) && !(obj.style.display=="block")? "block" : "none"; }
}

// gehört zum automatischen switch links unten auf der startseite
j = 0;
function toggle_bottom_left()
{
	var divs_left_act = ['toggleauto_content_1','toggleauto_content_2','toggleauto_content_3'];
	toggleswitch_bottom_left(divs_left_act[j]);
	if(j==divs_left_act.length-1)
	{
		j=0;
	}
	else
	{
		j++
	}
}

// sektion zu sektion scrollen
function slideContent(id,prefix,timer) {
  var div = document.getElementById(id);
  var slider = div.parentNode;
  clearInterval(slider.timer);
  slider.section = parseInt(id.replace(/\D/g,''));
  slider.target = div.offsetTop;
  slider.style.top = slider.style.top || '0px';
  slider.current = slider.style.top.replace('px','');
  slider.direction = (Math.abs(slider.current) > slider.target) ? 1 : -1;
  slider.style.opacity = STARTINGOPACITY * .01;
  slider.style.filter = 'alpha(opacity=' + STARTINGOPACITY + ')';
  slider.timer = setInterval( function() { slideAnimate(slider,prefix,timer) }, SLIDETIMER);
}

// animiere die slideshow
function slideAnimate(slider,prefix,timer) {
  var curr = Math.abs(slider.current);
  var tar = Math.abs(slider.target);
  var dir = slider.direction;
  if((tar - curr <= SLIDESPEED && dir == -1) || (curr - tar <= SLIDESPEED && dir == 1)) {
    slider.style.top = (slider.target * -1) + 'px';
	slider.style.opacity = 1;
	slider.style.filter = 'alpha(opacity=100)';
    clearInterval(slider.timer);
	if(slider.autoscroll) {
	  setTimeout( function() { autoScroll(slider.id,prefix,timer) }, timer * 1000);
	}
  } else {
	var pos = (dir == 1) ? parseInt(slider.current) + SLIDESPEED : slider.current - SLIDESPEED;
    slider.current = pos;
    slider.style.top = pos + 'px';
  }
}

// manuelles scrollen
function scrollContent(id,dir) {
  var div = document.getElementById(id);
  clearInterval(div.timer);
  var sections = div.getElementsByTagName('div');
  var length = sections.length;
  var limit;
  if(dir == -1) {
    limit = 0;
  } else {
    if(length > 1) {
      limit = sections[length-1].offsetTop;
    } else {
      limit = sections[length-1].offsetHeight - div.parentNode.offsetHeight + 20;
    }
  }
  div.style.opacity = STARTINGOPACITY * .01;
  div.style.filter = 'alpha(opacity=' + STARTINGOPACITY + ')';
  div.timer = setInterval( function() { scrollAnimate(div,dir,limit) }, SCROLLTIMER);
}

// scrollt
function scrollAnimate(div,dir,limit) {
  div.style.top = div.style.top || '0px';
  var top = div.style.top.replace('px','');
  if(dir == 1) {
	if(limit - Math.abs(top) <= SCROLLSPEED) {
	  cancelScroll(div.id);
	  div.style.top = '-' + limit + 'px';
	} else {
	  div.style.top = top - SCROLLSPEED + 'px';
	}
  } else {
	if(Math.abs(top) - limit <= SCROLLSPEED) {
	  cancelScroll(div.id);
	  div.style.top = limit + 'px';
	} else {
	  div.style.top = parseInt(top) + SCROLLSPEED + 'px';
	}
  }
}

// manuelles scrollen cancel
function cancelScroll(id) {
  var div = document.getElementById(id);
  div.style.opacity = 1;
  div.style.filter = 'alpha(opacity=100)';
  clearTimeout(div.timer);
}

// automatisches scrollen
function autoScroll(id,prefix,timer,restart) {
  var div = document.getElementById(id);
  div.autoscroll = (!div.autoscroll && !restart) ? false : true;
  if(div.autoscroll) {
    var sections = div.getElementsByTagName('div');
    var length = sections.length;
    div.section = (div.section && div.section < length) ? div.section + 1 : 1;
    slideContent(prefix + '-' + div.section,prefix,timer);
  }
}

// automatisches scrollen cancel
function cancelAutoScroll(id) {
	var divplaypause = document.getElementById('scrollplaypausebutton');
	divplaypause.src = 'images/scrolllist-bottom-right-play.png';
	var div = document.getElementById(id);
	div.autoscroll = false;
	scrolllistpause = 'on';
}
