/*

             ////////////////\
            ////////////////  \
           /// \\\\\\\\\///   /              Thanks for watching my js-code.
          ///  //////\'///   /
         ///  //////  ///   /              # Your Feedback is always welcome. #
        ///  //////  ///   /                 Don't hesitate to send a message
       ///   \\\\\\ ///   /
      ///   /''''''///   /                   ________________________________
     ///   /      ///   /
    ///   /      ///   /                     :: Hubert
    \\\  /       \\\  /
     ''''         ''''

*/

debug = new Function("message", "color", "\
    if($('debugWindow') && debugmode == true) {\
	var color = color ? color : '#FFF';\
	if (!window.debugmsg){\
	    window.debugmsg = [];\
	    for (var i = 0, l = 40; i < l; ++i) {\
		window.debugmsg.push(['','']);\
	    }\
	    new Draggable($('debugWindowWrap'), { handle:'debugHandle', snap: [1, 0] });\
	}\
	window.debugmsg.push([message,color]);\
	var msgs = '';\
	for (var index = 0, len = window.debugmsg.length; index < len; ++index) {\
	    if (index >= 1) {\
	    stat = index;\
		var span = \"<span style='color:\"+\
		    window.debugmsg[index][1]\
		    +\";opacity:\"+\
		    index / (window.debugmsg.length / 4)\
		    +\";'>\"+\
		    window.debugmsg[index][0]+\"</span><br/>\";\
		var msgs = msgs + span;\
		if (index >= 40) {\
		    window.debugmsg.shift()\
		}}}\
    $('debugWindow').innerHTML = msgs;\
    }\
");

/*
function enDbg() {
    if($('debugWindow')) { $('debugWindow').style.display='block'; }    debugmode = true;
}

function deDbg() {
    if($('debugWindow')) { $('debugWindow').style.display='none'; }    debugmode = false;
}
debugmode = false;
enDbg();
*/

function getSpeed(x1,y1,x2,y2) { //                                                                   // GET SPEED
    function vektor(z1,z2){
	var d = z1 > z2 ? z1-z2 : z2-z1;return d
    }
    var pythagoras = Math.sqrt( Math.pow(vektor(x1,x2),2) + Math.pow(vektor(y1,y2),2) );
    return pythagoras;
}

function findPos(obj) { //                                                                             //  FINDPOS
    var curleft = curtop = 0;
    if (obj.offsetParent) {
	do {
	    curleft += obj.offsetLeft;
	    curtop += obj.offsetTop;
	} while (obj = obj.offsetParent);
	return [curleft,curtop];
    }
}

function scrollUp() { //                                                                             //  SCROLL UP
    //debug("scrollUp()");
    new Effect.ScrollTo('headWrap', {offset: 50});
}

Position.getWindowSize = function(w) {
    var width, height;
    var w = w ? w : window;
    var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
    var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);

    return { width: width, height: height };
}

/* KLASSEN
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////
////////////////////             MAINPAGE    ----      Laden der Unterseiten, location.hash anpassen,
                                                       aenden der History, Inhalt beim skalieren resizen
*/

var MainPageClass = Class.create();
MainPageClass.prototype = {
    initialize: function(title) {
	this.locked = null;
	if (typeof(window.historyitems) == 'undefined'){ window.historyitems = []; }
	this.scrollAnchor = $('C_scrollAnchor');
	this.stage = $('stage');
	this.wrapper = $('C_wrapper');
	this['home'] = {  // default page Object
	    'active'    : 1,
	    'height'    : 1000,
	    'activePage': 'home',
	    'title'     : 'home',
	    'obj'       : $('C_home'),
	    'path'      : '/',
	    'id'        : 'C_home',
	    'loaded'    : 1,
	    'callback'  : '',
	    'navitem'   : "<span>&crarr;</span><a href='/' onclick=\"window.MainPage.goto('home','/'); return false;\">home</a>"
	};
	this.active = this['home'];

	this.breadcrumb = new BreadcrumbClass();
	if (!window.PeriodicalExecute) { //                                                      // PERIODICAL EXECUTE
	    this.PeriodicalExecute = new PeriodicalExecuter(function(pe) {
		////debug("PeriodicalExecuter()","#FF0");
		if ( this.prevlocation != window.location.hash && this.locked != 1) {
		    this.prevlocation = window.location.hash;
		    //debug('PeriodicalExecute(): Fire !',"#F00");
		    loadURL();
		}
		// Scroll head
		if (window.walzeTop == -649) {
		    window.walzeTop = 0;
		}
		window.walzeTop = window.walzeTop - 1;
		window.walzeObj.style.top = window.walzeTop+'px';
	    }, 0.5);
	    this.PeriodicalExecute.locked = 1;
	    this.PeriodicalExecute.prevlocation = window.location.hash;
	}


    }, //---------------------------------------------------------------------------------------------------- goto
    ////  Hauptwrapper der die funktionen zum laden und scrollen aufruft

    goto: function(title,path,callback,style) {

	this.locked = 1;
	this.PeriodicalExecute.locked = 1;
	this.PeriodicalExecute.prevlocation = '#'+path;

	//debug('goto'); //################################# //DEBUG
	//debug("MainPage / goto ("+title+","+","+path+","+(!!callback)+")","#00F");
	//this.callback = callback ? callback : '';

	if(!this[title]) {  // new page Object
	    this[title] = {
		'id'       : 'C_'+title,
		'path'     : path,
		'callback' : callback,
		'loaded'   : 0,
		'title'    : title,
		'obj'      : $('C_'+title),
		'navitem'  : "<span>&crarr;</span><a href="+path+" onclick=\"window.MainPage.goto('"+title+"','"+path+"'); return false;\">"+title+"</a>"
	    };
	}

	if(this[title] != this.active) {

	    this.active = this[title];
	    this.scrollhead();
	    if (style != 'jump'){

		window.location.hash = path;
		var www=/www/g;
		
		if (www.test(window.location.toString())) {
		    window.location.href = 'http://www.berezowski.de/#'+path;
		} else {
		    window.location.href = 'http://berezowski.de/#'+path;
		}
		document.title = 'berezowski.de / '+this.active.title;
	    }

	    if(style != 'jump') {
		window.MainPage.breadcrumb.select(this.active.title);
	    } else {
		window.MainPage.breadcrumb.select(this.active.title,'jump');
	    }
	    if(this.active.loaded == 0) {
		this.active.loaded = 1;
		this.get(title);
	    } else {
		this.locked = null;
		this.history(this.active.title);
		if (this.active.callback) {
		    var cb = new Function(this.active.callback); cb();
		}
	    }

	    this.PeriodicalExecute.locked = null;
	    this.scroll(this.active.title,style);

	} else {
	    this.resizePage();
	    if (this.active.callback) {
		var cb = new Function(this.active.callback); cb();
	    }
	}
    }, //---------------------------------------------------------------------------------------------------- jump
    ////  jump to this element without further ado, assume object is loaded; may break the page... more testing
    jump: function(title,path,callback) {
	if(title) {
	    this.active        = new Object;
	    this.active.id     = 'C_'+title;
	    this.active.obj    = $('C_'+title);
	    var iconbar        = this.active.obj.select('[class=iconBar]');
	    this.active.height = iconbar[0].offsetTop;
	    this.active.height = this.active.height - (this.active.obj.offsetTop - 140);
	    this.locked        = null;
	} else {
	    var title    = title    ? title    : this.active.title   ;
	    var path     = path     ? path     : this.active.path    ;
	    var callback = callback ? callback : this.active.callback;
	    //debug('jump('+title+','+path+','+callback+')')  //                  DEBUG
	}
	this.scroll(title, 'jump');


    }, //------------------------------------------------------------------------------------------------- history
    ////  change history

    history: function(title) {
	//debug("MainPage / history ("+title+")","#00F");
	window.historyitems.unshift(this.active.navitem);
	if (window.historyitems.length > 1) {
	    var links = "<span class='back'>zur&uuml;ck:</span>";
	} else {
	    var links = '';
	}
	for (var index = 0, len = window.historyitems.length; index < len; ++index) {
	    if (index >= 1) {
		var span = "<span class='historyAge_"+index+"'>"+window.historyitems[index]+"</span>";
		var links = links + span;
		if (index >= 8) {
		    window.historyitems.pop()
		}}}

	var historycontainer = $(this.active.id).select('[title=history]');
	if(historycontainer[0]) {
	    for (var index = 0, len = historycontainer.length; index < len; ++index) {
		historycontainer[index].innerHTML=links;
	    }
	}
    }, //----------------------------------------------------------------------------------------------------- get
    ////  Seite vom Server holen

    get: function(title) {
	//debug("MainPage / get ("+title+")","#00F");
	//var active = window.MainPage[title];
	var active = this.active;
	var wrap = $(active.id);
	var loader = wrap.select('div');
	var ContentWrap = $(active.id+'_fx');
	var callback = active.callback;
	loader[0].style.display='block';
	new Ajax.Request('/', {
	    method: 'get',
	    parameters: $H({
		'arbeit':'arbeit',
		'locationhash':this[title].path,
		'standaloneTemplate':'1'
	    }),
	    onSuccess: function(transport) {
		ContentWrap.style.display="none";
		ContentWrap.innerHTML=(transport.responseText);
		var iconbar = ContentWrap.select('[class=iconBar]');
		this.fadein = new Effect.Appear(
		    active.id+'_fx', {
			duration: 0.3,
			afterFinish: function(){
			    //debug('onsuccess: appear');
			    this.cb = new Function(active.callback); this.cb();
			    active.height = iconbar[0].offsetTop;
			    // uewes fragen wieso dass funktioniert --
			    // auf wrap sollte man hier doch gar nicht zugreifen koennen
			    // den callback erreiche ich doch hier auch nicht
			    if(window.MainPage.locked == null) {
				//debug('onsuccess: resize');
				window.MainPage.resizeContent();
			    }
			    wrap.removeChild(loader[0]);
			    window.MainPage.locked = null;
			    //setActiveFixed(title);
			}})
		window.MainPage.history(active.title);
	    }
	});

    }, //---------------------------------------------------------------------------------------------- scrollhead
    ////  Seite zum Logo scrollen / falls ein pagereload folgt Seite ganz nach oben scrollen

    scrollhead: function() {
	////debug("MainPage / scrollhead()","#00F");
	if (($('headWrap').viewportOffset()[1] != -50) && (window.location.hash != '')) {
	    new Effect.ScrollTo('headWrap', {offset: 50});
	} else { if ((window.location.hash == '') && ($('headWrap').viewportOffset()[1] != 0)){
	    new Effect.ScrollTo('headWrap');
	}}
    }, //-------------------------------------------------------------------------------------------------- scroll
    ////  Focus auf das Fenster schieben

    scroll: function(title,style) {
	//debug("MainPage / scroll ("+title+")","#00F");
	//debug('scroll(1','#F22'); //############################# //DEBUG
	var wrapper = this.wrapper;
	var isty = wrapper.scrollTop;
	var istx = wrapper.scrollLeft;
	var soll = findPos(this.active.obj);
	var speed = Math.pow(getSpeed(soll[0],soll[1],istx,isty) /7000,0.5);
	//debug('scroll(2','#F22'); //############################# //DEBUG
	////debug(speed+' speed','#FFE'); //############################################################# //DEBUG
	if(style != 'jump') {
	//debug('scroll(3','#F22'); //############################# //DEBUG
	    this.tweeny = new Effect.Tween(wrapper, isty, soll[1]-wrapper.offsetTop ,{duration: 1.0},'scrollTop' );
	    this.tween = new Effect.Tween(wrapper, istx, soll[0] , {duration: 1.0,afterFinish: function(){
	//debug('scroll(4','#F22'); //############################# //DEBUG
		if(window.MainPage.locked == null) {
		    //debug('tween resize')
		    window.MainPage.resizeContent();
		}
	//debug('scroll(5','#F22'); //############################# //DEBUG
		//debug('tween lock'+window.MainPage.locked);
		window.MainPage.locked = null;
	    }},'scrollLeft');
	} else {
	    wrapper.scrollTop = soll[1]-wrapper.offsetTop;
	    wrapper.scrollLeft = soll[0];
	    if(window.MainPage.locked == null) {
		//debug('jump resize')
		window.MainPage.resizeContent();
	    }
	    //debug('jump lock'+window.MainPage.locked);
	    window.MainPage.locked = null;
	}

    }, //--------------------------------------------------------------------------------------------- resize Page
    ////  Einzelne Wrapper auf Fenstergreosse skalieren

    resizePage: function() {
	//debug("MainPage / resizePage ()","#00F");

	var windowSize = Position.getWindowSize();
	var windowWidth = (windowSize.width < 950) ? 950 : windowSize.width;
	var children = this.wrapper.select('[class="ajaxContentWrapper"]');
	this.scrollAnchor.style.width = windowWidth * 7+'px';
	this.stage.style.width = windowWidth+'px';

	for (var index = 0, len = children.length; index < len; ++index) {
	    children[index].style.width = windowWidth+'px';
	}
	this.jump(this.active.title);

    }, //------------------------------------------------------------------------------------------ resize Content
    ////  Wrapper auf contentgreosse aufblaehen

    resizeContent: function() {
	//debug("MainPage / resizeContent () height="+'newheight'+"","#00F");
	if ( navigator.appName == "Microsoft Internet Explorer" ) {
	    var iconbar = this.active.obj.select('[class=iconBar]');
	    var newheight = iconbar[0].offsetTop + 70;
	} else {
	    var newheight = this.active.height - (this.active.obj.offsetTop - 200);
	}
	var windowSize = Position.getWindowSize().height;
	var newheight = (windowSize < newheight) ? newheight : windowSize;

	this.stage.style.height = newheight+'px';
	this.wrapper.style.height = newheight+'px';

    //}
    }
}
/*
      MAINPAGE
                                                                                             /////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////
////////////////////             BREADCRUMB   ----      Element das den aktuellen Pfad zeigt - zeigt immer
                                                        die aktuelle Seite an.
*/
var BreadcrumbClass = Class.create();
BreadcrumbClass.prototype = {
    initialize: function(title) {
	//debug("breadcrumbinit("+title+")","#3FF");
	if ( navigator.appName == "Microsoft Internet Explorer" ) {
	    this.browserOffset = 6;
	} else { this.browserOffset = 20; }

	this.breadcrumb = $('pathBreadcrumbJs')
	this.activeTitle = title ? title : '/';
	this.items = this.breadcrumb.select('a');
	this.itemParent = this.breadcrumb.select('ul');
	this.itemElement = new Object;
	this.fixednavi = $('fixedNavigation');
	this.fixednaviItems = this.fixednavi.select('a');
	for (var index = 0, len = this.items.length; index < len; ++index) {
	    this.itemElement[this.items[index].title] = this.items[index];
	}
	for (var index = 0, len = this.itemParent.length; index < len; ++index) {
	    this.itemParent[index].locked = 0;
	}
	this.show();
	if (title) { this.select(title); }

    }, //---------------------------------------------------------------------------------------------------- show
    ////  Statischen Breadcrumb durch Javascript Version die alle Elemente enthaelt tauschen

    show: function() {
	//debug("breadcrumbshow()","#3FF");


	$('pathBreadcrumb').style.display = 'none';
	this.breadcrumb.style.display = 'block';
    }, //-------------------------------------------------------------------------------------------------- unlock
    ////  Alle Elemente zum aus dem focus schieben freigeben

    unlock: function() {
	//debug("breadcrumbSelectDown()","#7FF");
	for (var index = 0, len = this.itemParent.length; index < len; ++index) {
	    this.itemParent[index].locked = 0;
	}

	$('pathBreadcrumb').style.display = 'none';
	this.breadcrumb.style.display = 'block';
    }, //-------------------------------------------------------------------------------------------------- select
    ////  Breadcrumb Zum aktiven Element scrollen

    select: function(title,style) {
	//debug(''); //################################# //DEBUG
	var style = style ? style : '';
	//debug("breadcrumbSelect("+title+","+style+")","#3FF");

	// Navigationelement auf selected stellen
	for (var index = 0, len = this.fixednaviItems.length; index < len; ++index) {
	    this.fixednaviItems[index].className='none';
	}

	if (this.activeTitle != title) {
	    this.activeTitle = title ? title : '/';
	    if(title != 'home') {
		var title = title;
		this.select_down(title,style);
	    }

	    this.select_up(title,style);
	    this.itemElement[title].className = 'selected';
	}
	
    }, //--------------------------------------------------------------------------------------------- select_down
    ////  Breadcrumbpfad anpassen / aktive Elemente in den Focus schieben

    select_down: function(title,style) {
	var style = style ? style : '';
	//debug("breadcrumbSelectdown("+title+","+style+")","#3FF");


	if (title != "home" ) {
	    this.fixednavi.select('[title='+title+']')[0].className='selected'
	    var iterUl = this.itemElement[title].parentNode.parentNode;
	    iterUl.locked = 1;

	    var iterItem = this.itemElement[title];
	    iterItem.className='none';

	    var iterNext = iterUl.parentNode.childNodes[0].title;

	    if (navigator.appName == "Microsoft Internet Explorer") {
		var soll = iterUl.style.top.replace("px", "") - iterItem.offsetTop + this.browserOffset ;
	    } else {
		var offset = iterItem.parentNode.offsetTop;
		var soll = - ( offset + this.browserOffset );
	    }

	    if (style == 'jump') {
		this.select_down(iterNext,style);
		iterUl.style.top = soll+'px';
	    } else {
		this.select_down(iterNext);
		iterUl.morph('top:'+soll+'px');
	    }

	} else {
	    this.itemElement[title].className = 'none';
	}

  }, //------------------------------------------------------------------------------------------------- select_up
  ////  Breadcrumbpfad anpassen / Kind Elemente aus dem Weg raeumen

    select_up: function(title,style) {
	var style = style ? style : '';
	//debug("breadcrumbSelectUp("+title+","+style+")","#3FF");



	for (var index = 0, len = this.itemParent.length; index < len; ++index) {
	    if(this.itemParent[index].locked == 0) {
		if(style=='jump') {
		    //this.itemParent[index].style.top = soll+'px';
		} else {
		    this.itemParent[index].morph('top:'+0+'px');
		}
	    }
	}
	this.unlock();

    }, //---------------------------------------------------------------------------------------------------- jump
    ////  Springe zum aktiven Pfad ohne Animation

    jump: function(title) {
	//debug("breadcrumbJump()","#3FF");
	this.select(title,'jump')
    }
};

/*
       BREADCRUMB
                                                                                             /////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////
////////////////////          GALLERY IMAGE   ----      Alles was mit der Gallery zu tun hat
*/
var GalleryClass = Class.create();
GalleryClass.prototype = {
    initialize: function(kategorie,technik,arbeit) {
	//debug(''); //################################# //DEBUG
	//debug(technik+' / initialize','#FFE'); //########################################################### //DEBUG
	this.kategorie = kategorie;
	this.technik = technik;
	this.wrap = $(kategorie+'_'+technik+'_ContentSubSlider');
	this.thumbNails = $(technik+'_description');
	this.lis = this.wrap.select('li');

    }, //-------------------------------------------------------------------------------------------------- unhide
    ////  Alle Subcontainer ( in die das aktive Bild mit beschreibung geladen wird ) einblenden

    unhide: function() {
	//debug(this.kategorie+' / unhide','#FFC'); //######################################################## //DEBUG
	if (this.lis[0].style.display="none") {
	    for (var index = 0, len = this.lis.length; index < len; ++index) {
		this.lis[index].style.display="block";
	    }}
    }, //-------------------------------------------------------------------------------------------------- scroll
    ////  Zum Subcontainer mit entsprechender 'pk_[arbeitid]' scrollen

    scroll: function(arbeitid,offset) {
	//debug('scroll('+arbeitid+','+arbeitid+','+offset+'/ scroll','#FFA'); //############################# //DEBUG

	if (arbeitid) {
	    var targetid = 'pk_'+arbeitid;
	} else {
	    var arbeitid = this.thumbNails;
	    var targetid = this.wrap;
	}

	if(offset) {
	    var offset = offset;
	} else {
	    var offset = $(targetid).offsetTop - this.wrap.offsetTop;
	}

	var currtop = this.wrap.scrollTop;
	var targetObj = $(targetid);
	var arbeitid = arbeitid ? arbeitid : undefined;

	var speed = Math.pow(getSpeed(0,offset,0,currtop) /5000,0.5);
	//debug(speed+' / Pythagoras','#FFE'); //############################################################# //DEBUG
	window.scroll = new Effect.Tween(this.wrap, currtop, offset, {duration: speed},'scrollTop' );

	var loaderIcon = $(targetid).select('[class=mainImageLoader]');
	if(loaderIcon[0]){
	    this.loadArbeit(arbeitid,targetid);
	}

    }, //---------------------------------------------------------------------------------------------- loadArbeit
    ////  Bild mit beschreibung in Subcontainer laden

    loadArbeit: function(arbeitid,targetid) {
	//debug(arbeitid+' / loadArbeit','#FF8'); //########################################################## //DEBUG
	var aid = arbeitid;
	//window[arbeitid] = arbeitid;
	window[arbeitid] = new GalleryImageClass(aid,targetid,this.kategorie,this.technik);
	window[arbeitid].load(arbeitid,targetid);
    }, //---------------------------------------------------------------------------------------------------------
    ////

    Overview: function() {

    }
};

/*
      GALLERY
                                                                                             /////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////
////////////////////            GALLERY IMAGE
*/

var GalleryImageClass = Class.create();
GalleryImageClass.prototype = {
    initialize: function(arbeitid,targetid,kategorie,technik) {
	//debug('GALLERY IMAGE           ','#FF6'); //######################################################## //DEBUG
	//debug('initialize('+arbeitid+","+targetid+","+kategorie+","+technik+')','#FF6'); //################# //DEBUG
	this.arbeitid = arbeitid;
	this.targetid = targetid;
	this.kategorie = kategorie;
	this.technik = technik;

    }, //---------------------------------------------------------------------------------------------------- load
    ////  1

    load: function(arbeitid,targetid) {
	//debug(''); //################################# //DEBUG
	//debug('load('+arbeitid+','+targetid+') / galleryImage / init load','#FF4'); //###################### //DEBUG

	this.arbeitid = arbeitid;
	new Ajax.Request('/arbeiten/json/updateArbeit/', {
	    method: 'get',
	    parameters: $H({
		'kategorie':this.kategorie,
		'technik':this.technik,
		'arbeit':this.arbeitid
	    }),

	    onSuccess: function(transport){
		$(targetid).innerHTML=transport.responseText;
		window[arbeitid].fade(arbeitid)
		//window.loader = arbeitUpdate_mainImageA(targetid);
	    }
	});
    }, //---------------------------------------------------------------------------------------------------- fade
    ////
    
    fade: function(arbeitid) {
	//debug('fade('+arbeitid+' / galleryImage / fade','#FF2'); //######################################### //DEBUG
	var targetobj = $(this.targetid);
	this.targetImage = targetobj.select('[class=mainImageA]')[0];
	var url = this.targetImage.select('[class=url]')[0];

	this.ImageElement = new Image;
	this.ImageElement.onload = function loaded(){
	    this.parent = window[arbeitid]
	    this.ImageElement = this.parent.ImageElement;

	    var imageLoader = this.parent.targetImage.select('[title=ImageLoader]')[0];
	    imageLoader.style.display = 'block';
	    this.ImageElement.style.display = 'none';
	    this.ImageElement.id = this.parent.targetid+'imageA';
	    imageLoader.id = this.parent.targetid+'Loader';

	    this.parent.targetImage.appendChild(this.ImageElement);


	    new Effect.Fade(
		imageLoader.id , {
		    duration: 1.0 ,
		    afterFinish: function(){
			imageLoader.parentNode.removeChild(imageLoader);
			imageLoader.title = 'quedForRemoval';
		    }});

	    new Effect.Appear(
		this.ImageElement.id , {
		    duration: 0.3,
		    afterFinish: function(){
		    }});
	}
	      this.ImageElement.src = url.innerHTML;
    }
};

/*

*/
var accordeonClass = Class.create();
accordeonClass.prototype = {
    initialize: function() {
	this.todolist = new Object;
	for (var index = 0, len=$('categoryWysiwyg').select('[class="serviceSubCategory"]').length; index < len; ++index) {
	    $('categoryWysiwyg').select('[class="serviceSubCategory"]')[index].style.height=30+'px';
	    $('categoryWysiwyg').select('[class="serviceSubCategory"]')[index].style.display='block';
	}
	/*
	this.closelist = new Object;
	this.open = new Object;
	this.open.id = '';
*/
    }, //---------------------------------------------------------------------------------------------------- load
    //// 
    addtolist: function(openid) {
	for (var i in this.todolist) {
	    this.todolist[i].soll = 3;
	}
	this.todolist[openid] = new Object;
	//var current = this.todolist[openid];
	
	this.todolist[openid].obj = $(openid);
	this.todolist[openid].wrap = this.todolist[openid].obj.select('[class="p"]')[0];
	this.todolist[openid].wrap.style.display='block';
	this.todolist[openid].obj.style.display='block';
	this.todolist[openid].obj.className='serviceSubCategory selected';
	this.todolist[openid].soll = 34;
	this.todolist[openid].ist = this.todolist[openid].obj.style.height.replace("px", "");
	this.todolist[openid].ist = Math.ceil(this.todolist[openid].ist/10);
	this.todolist[openid].ist++;
	//

	this.counter();

    },

    counter: function() {
	if (!this.countDown) {
	    this.countDown = new PeriodicalExecuter(function(pe) {
		_parent = window.accordeon;
		for (var i in _parent.todolist) {
		    targetobj = _parent.todolist[i];

		    if (_parent.todolist[i].ist == 3) {
			_parent.todolist[i].obj.className='serviceSubCategory';
			_parent.todolist[i].wrap.style.display='none';
			delete _parent.todolist[i];
			break;
		    }

		    if (_parent.todolist[i].soll < _parent.todolist[i].ist) {
			_parent.todolist[i].ist -= 1;
		    } else if (_parent.todolist[i].soll > _parent.todolist[i].ist) {
			_parent.todolist[i].ist += 1;
		    }

		    //_parent.scale(targetobj.obj, Math.sin((targetobj.ist/30.)*(Math.PI*2)));
		    _parent.scale(_parent.todolist[i].obj, _parent.todolist[i].ist);
		    


		}

		//pe.stop();
		//delete _parent.countDown;
	    }, 0.03);
	}
	
    },
    
    scale: function(obj, size) {
	obj.style.height = size*10+'px';
	//wrap = $(id).select('[class="p"]')[0];
	//wrap.style.height = size+'px';
    }
};

/*
                                                                                             /////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                                    : KLASSEN */

function categorySwitch(elementId) {
    if (!window.accordeon) {
	window.accordeon = new accordeonClass();
    }
    window.accordeon.addtolist(elementId);
}

function loadNavigation(technik,kategorie,pagenumber) { //                               //  LOAD NAVIGATION
    //debug("loadNavigation()");
    if (! $('nav_'+technik+'_'+pagenumber).childNodes[1]) {
	new Ajax.Request('/arbeiten/json/updateNavigation/', {
	    method: 'get',
	    parameters: $H({
		'technik': technik,
		'kategorie': kategorie,
		'pagenumber': pagenumber
	    }),
	    onSuccess: function(transport) {
		$('nav_'+technik+'_'+pagenumber).innerHTML = transport.responseText;
	    }
	});
    }
    //return false;
}

function arbeitenUpdateNavigation(technik,kategorie,direction) { //                    //  ARBEITEN UPDATE NAVIGATION
    //debug("arbeitenUpdateNavigation()");
    index = $(technik+'_index');
    maxIndex = $(technik+'_maxIndex');
    currentPage = parseInt(index.innerHTML);
    maxPage = parseInt(maxIndex.innerHTML);

    buttons = $('nav_'+technik+'_buttons')
    nextbutton = buttons.select('[title=next]');
    backbutton = buttons.select('[title=back]');

    if (direction == "next") {
	if (currentPage < maxPage) {
	    newIndex = currentPage+1;
	    if (newIndex == maxPage){
		nextbutton[0].style.display="none";
	    }
	    backbutton[0].style.display="inline";
	}
    }

    if (direction == "back") {
	if (currentPage > 1) {
	    newIndex = currentPage-1;
	    if (newIndex == 1){
		backbutton[0].style.display="none";
	    }
	    nextbutton[0].style.display="inline";
	}
    }
    index.innerHTML = newIndex;
    loadNavigation(technik,kategorie,newIndex);
    targetScroll = $('nav_'+technik+'_scroll');
    targetOffset = $('nav_'+technik+'_'+newIndex).offsetLeft - targetScroll.offsetLeft;
    new Effect.Tween(targetScroll, targetScroll.scrollLeft, targetOffset, 'scrollLeft' );



}

function arbeitenCallback(kategorie,technik,arbeit,offset){ //                               //  ARBEITEN CALLBACK
    //debug("arbeitenCallback("+kategorie+","+technik+","+arbeit+","+offset+")");
    if (!window[technik+'_Gallery']) {
	window[technik+'_Gallery'] = new GalleryClass(kategorie,technik);
	window[technik+'_Gallery'].unhide();
    }
    if (offset) {
	window[technik+'_Gallery'].scroll(arbeit,offset);
    }
    if (arbeit) {
	window[technik+'_Gallery'].scroll(arbeit);
    }
}

function getLinkParams(uri,hash) {
    //debug("getLinkParameter()");
    var navigationlinks = $('mainNavigation').select('a');
    for (var index = 0, len = navigationlinks.length; index < len; ++index) {
	if(uri == navigationlinks[index].href){
	    var hashlink = navigationlinks[index];
	    var title = hashlink.title.toString();
	    
	    if(hash){
		var path = hash.replace("#", "");
	    } else {
		var www=/www/g;
		if (www.test(window.location.toString())) {
		    var path = uri.toString().replace("http://www.berezowski.de", ' ');
		} else {
		    var path = uri.toString().replace("http://berezowski.de", ' ');
		}
	    }
	    var callback = /(arbeitenCallback.*)"/.exec(hashlink.onclick.toString());

            var params = new Array(4);

		if (callback != null) {
		    params['callback'] = callback[1];
		}

	    params['title'] = title;
	    params['path'] = path;

            return params;
	}
    }
}

function submit_kontaktFormular() {
    form_data = $('kontaktFormular').serialize(true);
    $('kontaktFormular').disable();
    //submit = $('kontaktFormular').select('[type=submit]');
    //submit[0].disabled = true;

    form_data['ajaxForm'] = 1;
    new Ajax.Request('/kontakt/', {
	
	method: 'post',
	parameters: $H(form_data),
	onSuccess: function(transport) {
	    var patt=/messagesuccess/g;
	    if (patt.test(transport.responseText)) {
		
		$('successWrap').innerHTML = transport.responseText;
		//this.kontaktTween = new Effect.Tween($('successWrap'), -400, 0 ,{duration: 1.0},'style.margin-left' );
		var kml = $('kontaktScrollAnchor').morph('margin-left:-200px;');
		var wi = $('kontaktWrap').morph('width:500px;');
		var ml = $('successWrap').morph('margin-left:40px;');
		var es = new Effect.Scale($('kontaktFormWrap'), 70);
	    } else {
		$('kontaktFormWrap').innerHTML = transport.responseText;
	    }
	}
    });
}


function changeDynamicExample() {
    $('dynamicWebText').innerHTML = $('dynamicWebAdmin').value;
}

function initialloadUrl(hash){ //                                                              //  INITIAL LOAD URL
    //debug("inititalloadUrl()");
    var www=/www/g;
    if (www.test(window.location.toString())) {
	uri = 'http://www.berezowski.de'+hash.replace("#", "");
    } else {
	uri = 'http://berezowski.de'+hash.replace("#", "");
    }
    var params = getLinkParams(uri,hash);
    window.MainPage.resizePage();
    window.MainPage.goto(params.title,params.path,params.callback,'jump');
}


function initialiseStateFromURL(){ //                                                           //  STATE FROM URL
    //debug("initialiseStateFromURL()");
    if (window.location.hash != ''){
	//debug("jump to hash "+window.location.hash);
	var initialTab = window.location.hash;
	initialloadUrl(initialTab);
    } else {
	//debug("jump to url "+window.location);
	uri = window.location.toString()
	//window.MainPage.resizePage();
	params = getLinkParams(uri);
	//debug(params['title']+" = title;"+	      params['path']+" = path;"+	      params['callback']+" = callback;")
	//window.MainPage.breadcrumb.jump(params['title']);

	window.MainPage.active.title=params['title'];
	window.MainPage.active.path=params['path'];
	if (params['callback'] != undefined) {
	    window.MainPage.active.callback=params['callback'];
	}
	window.MainPage.resizePage();
    }
}

    function jumpToContent(x,x,x,x) {} // alte funktion, aus templates entfernen



function loadURL(){ //  wird beim betaetigen des back buttons auf der Seite aufgerufen                 // LOAD URL
    //debug("loadurl()");
    var url = window.location.hash;
    var navigationlinks = $('mainNavigation').select('a');
    var www=/www/g;
    if (www.test(window.location.toString())) {
	fullhash = 'http://www.berezowski.de'+url.replace("#", "");
    } else {
	fullhash = 'http://berezowski.de'+url.replace("#", "");
    }
    for (var index = 0, len = navigationlinks.length; index < len; ++index) {
	if(fullhash == navigationlinks[index].href){
	    var hashlink = navigationlinks[index]
	    hashlink.onclick()
	}
    }
}

Event.observe(window, 'load', function() { //                                                            // ONLOAD
    ////debug("Event.load()","#F00");
    if (!window.historyitems){
	window.historyitems = [];
    }
    if (!window.MainPage){
	window.MainPage = new MainPageClass();
    }
    
    if (!window.walzeObj) {
	window.walzeTop = 0;
	window.walzeObj = $('walzeBack');
    }

    contentWraps = $('C_scrollAnchor').select('[class="ajaxContentWrapper"]');
    for (var index = 0, len = contentWraps.length; index < len; ++index) {
	var item = contentWraps[index];
	item.style.display="block";
    }
    initialiseStateFromURL();
});

Event.observe(document.onresize ? document : window, "resize", function() { //                         // ONRESIZE
    //debug("Event.resize()");
    window.MainPage.resizePage();
});




// THE END
/*
                      This feature full of mystery and suspense has been brought to you by

                                               www.berezowski.de



                                              Thanks for watching
*/

