Event.observe(window, 'load', initializeFocus, false);

var focus = Class.create();

focus.prototype = {

	initialize: function(ctrl) {
		this.elem = ctrl;
		if(this.elem.getAttribute('type')=='checkbox'){
			this.elem = this.elem.parentNode
		}
		if(this.elem.getAttribute('class')!='button'){
    		Event.observe(this.elem, 'focus', this.addFocus.bind(this), false);
    		Event.observe(this.elem, 'blur', this.removeFocus.bind(this), false);
		}
	},

	addFocus:function (){
		new Effect.Highlight(this.elem, {startcolor:'#ffffff', endcolor:'#fff7c0', restorecolor:'#fff7c0'})
	},

	removeFocus:function (){
		new Effect.Highlight(this.elem, {startcolor:'#fff7c0', endcolor:'#ffffff', restorecolor:'#ffffff'})
	}
}

function initializeFocus(){

	var fields = $$('input','textarea', 'select');

	fields.each(function(value) {
		if(value.getAttribute('type')!='submit' && value.getAttribute('type')!='image'){
			focusing = new focus(value);
		}
	});

}

var BigImage = {

  showInline: function(img_url)
  {
    this.showOverlay(img_url);
    this.setWindowPosition();
   /* new Effect.Fade('BI_loading', {delay: 0.5, duration: 0.3}); */
    new Effect.Appear('BI_window', {duration: 0.4, queue: 'end'});
    Element.scrollTo('BI_window');

  },

  close: function()
  {
    new Effect.Fade('BI_window', {duration: 0.4});
    new Effect.Fade('BI_overlay', {duration: 0.4});
  },

  showOverlay: function(img_url)
  {

    new Insertion.Bottom(document.body, '<div id="BI_bigimage" align="center"><div id="BI_window" style="display: none;"><a class="meta" href="#" onclick="BigImage.close(); return false;"><img src="'+img_url+'" /></a></div><div id="BI_overlay" style="display: none;"></div></div>');


    this.setOverlaySize();
    new Effect.Appear('BI_overlay', {duration: 0.4, to: 0.6, queue: 'end'});
  },

  setOverlaySize: function()
  {
    if (window.innerHeight && window.scrollMaxY)
    {
      yScroll = window.innerHeight + window.scrollMaxY;
    }
    else if (document.body.scrollHeight > document.body.offsetHeight)
    { // all but Explorer Mac
      yScroll = document.body.scrollHeight;
    }
    else
    { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
      yScroll = document.body.offsetHeight;
    }
    $("BI_overlay").style['height'] = yScroll +"px";
  },

  setWindowPosition: function()
  {
    var pagesize = this.getPageSize();

    $("BI_window").style['width'] = '60em';
    $("BI_window").style['height'] = '60em';

    var dimensions = Element.getDimensions($("BI_window"));
    var width = 600; //dimensions.width;
    var height = 600; // dimensions.height;

    $("BI_window").style['left'] = ((pagesize[0] - width)/2) + "px";
    $("BI_window").style['top'] = ((pagesize[1] - height)/2) + "px";
  },


  getPageSize: function() {
    var de = document.documentElement;
    var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
    var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;

    arrayPageSize = new Array(w,h)
    return arrayPageSize;
  }

}


/* Crossfading */
var actImg = 0;

var imgArray = new Array();

function nextImage(){
    oldImg = $('visualSmall'+actImg)
    oldImgLightbox = $('lightboxPic'+actImg)
	Effect.Fade(oldImg, { duration:1, from:1.0, to:0.0 });
	actImg++;
	newImg = $('visualSmall'+actImg);
	newImgLightbox = $('lightboxPic'+actImg)
	if(!newImg) {
	   actImg = 0;
	   newImg = $('visualSmall'+actImg);
	   newImgLightbox = $('lightboxPic'+actImg)
	}

	oldImgLightbox.style.display = "none";
	newImgLightbox.style.display = "inline";

	Effect.Appear(newImg, { duration:1, from:0.0, to:1.0 });
}

function prevImage(){
    oldImg = $('visualSmall'+actImg)
    oldImgLightbox = $('lightboxPic'+actImg)
	Effect.Fade(oldImg, { duration:1, from:1.0, to:0.0 });
	actImg--;
	newImg = $('visualSmall'+actImg);
	newImgLightbox = $('lightboxPic'+actImg)
	if(actImg < 0){
	   actImg = 10;
	   while (!newImg){
	       actImg--
	       newImg = $('visualSmall'+actImg);
	       newImgLightbox = $('lightboxPic'+actImg)
	   }
	}

    oldImgLightbox.style.display = "none";
	newImgLightbox.style.display = "inline";

	Effect.Appear(newImg, { duration:1, from:0.0, to:1.0 });
}








startList = function() {
    if (document.all&&document.getElementById) {
        navRoot = document.getElementById("serviceNav");
        for (i=0; i<navRoot.childNodes.length; i++) {
            node = navRoot.childNodes[i];
            if (node.nodeName=="LI") {
                node.onmouseover=function() {
                    this.className+=" over";
                }
                node.onmouseout=function() {
                  this.className=this.className.replace	(" over", "");
                }
            }
        }
    }
}
window.onload=startList;

/**
* Seite drucken.
*/
function printPage() {
	window.print();
	return false;
}

/* Umschalter fuer Katalogbestellung */
function toggleSecondaryForm() {
    Effect.toggle('secondaryFieldset', 'blind');
}

/* Umschalter fuer Callback-Formular */
function toggleCallbackTime(caller) {
	var elems = $('callbackTime').getElementsByTagName('select');
	for(i = 0; i < elems.length; i++) {
	    elems[i].disabled = caller.checked;
	}
    Effect.toggle('callbackTime', 'slide');
}


function changeMainTeaser(imgSrc, link){
    $('mainTeaserImg').src = imgSrc;
	if($('mainTeaserLink')){
        $('mainTeaserLink').href = link;
	}
}

document.preload = new Array();

function preloader(img){

    if(document.images) {
        var temp = new Image();
        temp.src = img;
        document.preload.push()
    }
}


var mainTeaserImg;
var mainTeaserLink;

function setMainTeaserImg(img){
    mainTeaserImg = img;
}

function setMainTeaserLink(link){
    mainTeaserLink = link;
}

function restoreMainTeaser(){
    $('mainTeaserImg').src = mainTeaserImg;
    $('mainTeaserLink').href = mainTeaserLink;
}
