window.onload = function ( eve ) {
// -----------------------------------------------------

$('#Loading').detach();

MA_SCROLLS.ID = 0;
function MA_SCROLLS () {
	
	var _scrolls = this.scrolls = {};
	$('#PAGE .MA_SCROLLABLE').each( function ( i,e ) {
		var height = $(this).height();
		//console.info(height,$(this));
		if ( height > -1 ) {
			//console.info(1,$(this).height(),$(this).outerHeight(true),$(this));
			height = 21 * ( 1 + parseInt(height/21));
			$(this).css({'height':height+'px!important'}); //,'border-bottom':'1px solid red'});
			//$(this).css('height',height+'px','border-bottom','20px solid black');
			//console.info(2,$(this).height(),$(this).outerHeight(true));
			//console.info(2,$(this).css('border-bottom'));


			MA_SCROLLS.ID += 1;
			var id = ( new Date ).getTime() +'_'+ MA_SCROLLS.ID;
			var $div = $(this);
			var control_ID = 'control_'+ id;
			var $control = $('<div id="'+ control_ID +'" class="MA_SCROLL_control-panel"><img class="N" src="images/N.mouseout.jpg" width="20" height="20" title="" /><img class="S" style="margin-top:320px;" src="images/S.mouseout.jpg" width="20" height="20" title="" /></div>');
			$control.css({
				'width': '20px',
				'height': '360px',
				'float': 'right'
			});
			var target_ID = 'target_'+ id;
			var $target = $('<div id="'+ target_ID +'" class="MA_SCROLL_div">'+ $(this).html() +'</div>');
			$target.css({
				'width': ''+($div.outerWidth() - 20)+'px'
			});

			$(this).html($control);
			$(this).append($target);

			_scrolls[id] = new MA_SCROLL(id);
			//console.info('scrolls key',id,_scrolls[id]);
			/*$('.MA_SCROLL_control-panel  img.N').each( function ( i,e ) {
				$(this).bind('mouseover', function ( eve ) { $(this).attr('src','images/N.mouseover.jpg'); });
				$(this).bind('mouseout', function ( eve ) { $(this).attr('src','images/N.mouseout.jpg'); });
				$(this).bind('click', function ( eve ) { //console.info ('scroll N click'); });
			});
			$('.MA_SCROLL_control-panel  img.S').each( function ( i,e ) {
				$(this).bind('mouseover', function ( eve ) { $(this).attr('src','images/S.mouseover.jpg'); });
				$(this).bind('mouseout', function ( eve ) { $(this).attr('src','images/S.mouseout.jpg'); });
				$(this).bind('click', function ( eve ) { //console.info ('scroll S click'); });
			});*/
		}
	});
}

function MA_SCROLL ( ID ) {
	this.ID = ID;
	this.targed_ID = 'target_'+ ID;
	this.control_ID = 'control_'+ ID;
	this.a = 0;
	var sel = '#'+this.control_ID+' .N , #'+this.control_ID +' .S';
	//console.info( sel );
	//console.info( $(sel) );
	$(sel).bind( 'mouseover mouseout', function ( e ) {
		//console.info($(this));
		var d = $(this).attr('class');
		$(this).attr('src', 'images/'+ d +'.'+ e.type +'.jpg');
		switch ( e.type ) {
			case 'mouseover': window.ma_scrolls.scrolls[ID].begin ( d ); break;
			case 'mouseout': window.ma_scrolls.scrolls[ID].stop (); break;
		}
	});
	this.begin = function ( d ) { //console.info('begin');
		this.place = (function ( d ) {
			var idHash = { N: '-', S: '+' };
			return idHash[d] + '=21px';
		})( d );
		//console.info('#target-'+ ID,$('#target_'+ ID));
		//console.info('$("#target_'+ ID +'").scrollTo("'+ this.place +'");');
		//this.a = window.setInterval('$("#target_'+ ID +'").scrollTo("'+ this.place +'");', 100);
		this.a = window.setInterval('$("#target_'+ ID +'").scrollTo("'+ this.place + '");', 100);

	}
	this.stop = function ( ) { window.clearInterval(this.a); }
}


/*
				var Scrolls = function () {

				}

				var mmScrollBar = new ScrollBar ( );


		*/


function MA_SLIDESHOW_CONTROL() {
	var $ALL = $('.MA_SLIDESHOW');
	this.ALL = [];
	if ( $ALL.length > 0 ) {
		var ALL = this.ALL;
		$ALL.each( function ( i,e ) {
			ALL.push( new MA_SLIDESHOW($(this)) );
		});
	}
	this.start = function () {
		for ( var i=0 ; i<this.ALL.length ; i+=1 ) {
			var slideshow = this.ALL[i];
			slideshow.start();
			if ( slideshow.modus === 'auto' ) {
				var diaShowName = 'ma_diaShow_'+i;
				window[diaShowName] = slideshow;
				window[diaShowName].start();
				window.setInterval('window["'+diaShowName+'"].next()', slideshow.interval);
			} else if ( slideshow.modus === 'controls' ) {
				if ( slideshow.$frames.length > 1 ) {
					slideshow.$control.show();
				}
			}
		}
		if ( slideshow.modus === 'controls' ) {
			$('.MA_SLIDESHOW_control-panel  img.back').each( function ( i,e ) {
				$(this).bind('mouseover', function ( eve ) { $(this).attr('src','images/Pfeil-links_aktiv.jpg'); });
				$(this).bind('mouseout', function ( eve ) { $(this).attr('src','images/Pfeil-links_passiv.jpg'); });
				$(this).bind('click', function ( eve ) { window.ma_ssc.ALL[i].back(); });
			}); 
			$('.MA_SLIDESHOW_control-panel  img.next').each( function ( i,e ) {
				$(this).bind('mouseover', function ( eve ) { $(this).attr('src','images/Pfeil-rechts_aktiv.jpg'); });
				$(this).bind('mouseout', function ( eve ) { $(this).attr('src','images/Pfeil-rechts_passiv.jpg'); });
				$(this).bind('click', function ( eve ) { window.ma_ssc.ALL[i].next(); });
			});
		}
	};
}

function MA_SLIDESHOW($div) {
	//console.info('make2',$div);
	this.ID = 'MA_SLIDESHOW-'+ ( new Date ).getTime();
	this.ACTUAL = -1;
	this.ACTIVE = false;
	this.$frames = [];
	this.T = 0;
	this.$control = null;
	this.$div = $div;
	this.status = 'MA_SLIDESHOW-standby';
	this.$div.addClass(this.status);
	//this.modus = $div.hasClass('controls') ? 'controls' : 'auto';
	this.modus = $div.attr('ma:modus');
	this.interval = parseInt($div.attr('ma:interval'));
	this.fadeIn = parseInt($div.attr('ma:fadein'));
	this.fadeOut = parseInt($div.attr('ma:fadeout'));
	this.delay = parseInt($div.attr('ma:delay'));
	
	var $frames = this.$frames;
	var $control = this.$control;
	$div.children('div,img').each( function ( i,e ) {
		//console.info($(this));
		if ( $(this).hasClass('MA_SLIDESHOW_control-panel') ) {
			//console.info('control-panel',$(this));
			$control = $(this);
		} else { $frames.push($(this)); }
		$(this).css('position','absolute');
		$(this).hide();
	});
	this.$control = $control;
	this.T = this.$frames.length;
	//console.info(this.ID, this.modus, this.$frames, $div = $div);


	this.hide = function () { this.$frames[this.ACTUAL].fadeOut(this.fadeOut); }
	this.show = function () { this.$frames[this.ACTUAL].delay(this.delay).fadeIn(this.fadeIn);  }
	this.next = function () {
		//console.info('next (interval/in/out/delay)', this.interval, this.fadeIn, this.fadeOut, this.delay);
		this.hide();
		this.ACTUAL += 1;
		if ( this.ACTUAL === this.T ) this.ACTUAL = 0;
		this.show();
	}
	this.back = function () {
		//console.info('back (interval/in/out/delay)', this.interval, this.fadeIn, this.fadeOut, this.delay);
		this.hide();
		this.ACTUAL -= 1;
		if ( this.ACTUAL === -1 ) this.ACTUAL = this.T - 1;
		this.show();
	}
	this.start = function () {
		this.ACTUAL = 0;
		this.show();
		this.setStatus('MA_SLIDESHOW-'+ this.modus + '-started');
	}
	this.setStatus = function (newStatus) {
		this.$div.removeClass(this.status);
		this.$div.addClass(newStatus);
		this.status = newStatus;
	};
}
/*
((([^]+)\.([a-z]+))#([+A-Z]+))
(([^\/]+)\.([a-z]+))#([+A-Z]+)
(([^\/]+)\.([a-z]+))#([+A-Z]+)
*/
MA.ID = 0;
MA.ssc = null;
MA.scrolls = [];

function MA (maco,cols) { //console.info(MA.ID);
	this.ID = ++MA.ID;
	this.co = maco;
	this.COLS = cols;
	this.growing = 0;
	this.modus = { MA:false , PREVIEW:false , EDIT:false };
	var href = document.location.href;
	href.match( /^(.*)\/(([^\/]+)\.([a-z]+)){0,1}(#([+A-Z]+))*$/ );
	this.doc = {
		href: href,
		href_base: RegExp.$1,
		params: RegExp.$6,
		file: {
			name: RegExp.$2,
			base: RegExp.$3,
			type: RegExp.$4
		}
	};
	var content_file_base_name = this.doc.file.base.toUpperCase();
	var content_file_name = content_file_base_name +'.'+ this.doc.file.type;
	this.doc.content = {
		href: this.doc.href_base + '/content/' + content_file_name,
		file: {
			name: content_file_name,
			base: content_file_base_name,
			type: this.doc.file.type
		} 
	};
	if ( this.doc.params ) {
		var params = this.doc.params.split('+');
		for ( var i=0 ; i<params.length ; i+=1 ) {
			for ( var m in this.modus ) {
				this.modus[m] = this.modus[m] || m === params[i];
			}
		}
		this.CONTENT_FILE = RegExp.$2
	}


	//console.info('MA',this.MA);
	//console.info('PREVIEW',this.PREVIEW);
	var PID = ' [#PAGE: '+ window.MA.page.id +']';
	//console.info(PID);
/*
	this.setMaxHeight = function () {
		var maxHeight = 0;
		var maxCol = -1;
		$('#VIEW > div').each( function ( col,e ) {
			var height = $(this).height();
			if ( height > maxHeight ) {
				maxHeight = height;
				maxCol = col;
			}
		});
		if ( maxCol > -1 ) {
			$('#VIEW > div').each( function ( col,e ) {
				$(this).css('height',maxHeight+'px');
			});
		}
	}
*/

	this.make_DIASHOW = function ( $div , json ) {
		var def = { // aults :)
			modus: (json.modus || 'controls'),
			interval: (json.interval || '5500'),
			fadeIn: (json.fadeIn || '500'),
			fadeOut: (json.fadeOut || '500'),
			delay: (json.delay || '0')
		};

		switch (def.modus) {
			case 'controls':
				var id =
				$('<div class="MA_SLIDESHOW_control-panel"><img class="back" src="images/Pfeil-links_passiv.jpg" width="20" height="20" title="" /><!--div id="'+ id +'" class="MA_SLIDESHOW_View">1/4</div--><img class="next" src="images/Pfeil-rechts_passiv.jpg" width="20" height="20" title="" /></div>')
					.prependTo($div)
				;
				$('')
				break;
			case 'auto':
				break;
			default:
				break;
		}
		$div.addClass('MA_SLIDESHOW '+ def.modus);
		$div.removeAttr('ma:make');
		$div.attr('ma:modus',def.modus);
		$div.attr('ma:interval',def.interval);
		$div.attr('ma:fadein',def.fadeIn);
		$div.attr('ma:fadeout',def.fadeOut);
		$div.attr('ma:delay',def.delay);

		//console.info('make_DIASHOW for', $div, json);
	}
	this.make_NAVIG = function ( $div , json ) {
		var def = { // aults :)
			link: (json.link || 'h2'),
			title: (json.title || 'h2'),
			href: (json.href || 'div'),
			target: (json.target || ''),
			width: (json.width || 1),
			position: (json.position || 0)
		};
		var ID = (( new Date ).getTime());
		var groupID = 'group-'+ID+'-0';
		var $navig = $('<div ma:width="1" class="COL '+( def.target.match(/^\./) ? (def.target.replace(/^./,'')+' ') : '' )+'SUBMENU '+groupID+'"><div class="Navig Itens"></div></div>');
		//if ( def.position == 1 ) {
		//	$('#COL1').detach();
		//	$navig.attr('id','COL1');
		//}
		$div.before($navig);
		this.fit();
		$div.children(def.link).each( function ( index,e ) {
			var link = $(this).html();
			var subPageClass = link.replace( /^([a-zA-Z]+)(.*)/, "$1" );
			//var title = link;
			var title = '';
			var href = 'page-'+ID+'-' + (index+1);
			var HREF = '#'+ href;
			$(this).replaceWith('<a style="display:none; width:0px!important" id="'+href+'" name="'+href+'"></a>');
			//$(this).detach();
			var $next = $(HREF).next();
			if ( link ) {
				$('<div class="Item'+( (index === 0) ? ' Actual' : '' )+'"><a href="'+HREF+'" title="'+title+'">'+link+'</a></div>').appendTo($navig.children('div'));
			}
			$(HREF).prependTo($next).removeAttr('id');
			$next.attr('id',href);
			//console.info($(HREF));
			$next.addClass(groupID +' '+ subPageClass).css('position', 'absolute');
			$next.css('position','absolute');
			//$next.css('position','absolute');
			if ( index === 0 ) { $next.addClass('Actual'); }
			else { $next.hide(); }
			//else { $next.css('display','none'); }
			//console.info($(this));
		});
		$div.removeAttr('ma:make');
		//console.info('Actual:',$('.SUBMENU.'+ groupID +' .Item.Actual'));
		$('.SUBMENU.'+ groupID +' .Item  a').click( function ( eve ) {
			var href = $(this).attr('href');
			//console.info(href);
			var is_Actual = $(href).hasClass('Actual');
			if ( is_Actual ) {
				//console.info('Actual');
				$(href).hide().fadeIn(500);
			} else {
				//console.info('NOT Actual');
				var $actual = $('.CONTENT .'+ groupID +'.Actual');
				$('.SUBMENU.'+ groupID +' .Item.Actual').removeClass('Actual');
				$actual.removeClass('Actual').fadeOut(500);
				if ( $actual.hasClass('Reservierungssystem') ) {
					$actual.hide();
				}
				$(this).parent().addClass('Actual');
				$(href).addClass('Actual').fadeIn(500);
				$('.SUBMENU .Navig').trigger('click');
		}

			return false;
		});

		//$('.SUBMENU.'+ groupID).find('.Item.Actual').removeClass('Actual');
		//console.info($(this));
		//$('#VIEW .'+ groupID).find('.Actual').removeClass('Actual');
		//});
		$navig.children('a').each( function (i,e) {
			//console.info('$navig.children("a").each', $(this));
		});
	};
	this.make = function ( $div ) {
		var makeSTR = $div.attr('ma:make');//MA.href = document.location.href;
		if ( makeSTR ) {
			var makes = makeSTR.replace(/^[;\s]+/,'').replace(/[;\s]+$/,'').replace(/\s*;\s*/g,';').split(';');
			for ( var i in makes ) {
				var make = makes[i];
				//console.info('make:',make);
				if ( make.match( /^([A-Z]+)\((.*)\)$/ ) ) {
					var command = RegExp.$1;
					var json_STR = RegExp.$2;
					var json = {};
					if ( json_STR ) {
						try { json = jQuery.parseJSON(json_STR); }
						catch ( ex ) { json = {}; throw new Error('make(): *** Errr catched:"'+ ex +'" [json_STR:'+json_STR+']'+ PID); }
					}
					switch ( command ) {
						case 'SUBMENU': this.make_NAVIG( $div, json ); break;
						case 'SLIDESHOW': this.make_DIASHOW( $div, json ); break;
						default: throw new Error('MA.make(): Warning: Command [ma:make="'+ command +'"] not found!'+ PID); break;
					}
				} else { throw new Error('MA.make(): Syntax ERRR [ma:make="'+ make +'"]'+ PID); }
			}
		}
	};
	this.grow = function () {
		var $div = ( arguments.length === 0 ) ? $('#VIEW > div') : $(arguments[0]);
		//console.info('growiiiiiiiiiiing', $div);
		if ( $div.length === 0 ) {} //throw new Error('grow(): *** Nothing growing...'+ PID); }
		else {
			this.growing += 1;
			var growing = this.growing;
			var ma = this;
			$div.each( function ( i,e ) {
				$(this).attr('ma:growing',growing);
				for ( var i=1; i<6; i+=1 ) {
					if ( $(this).hasClass('COL'+i) ) { $(this).addClass('COL'); break; }
				}
				//console.info('ma:growing',growing, $(this));
				ma.dispatch($(this));
				ma.make($(this));
			});
			//console.info('this.grow:','$div.children.length:',$div.children('div').length);
			ma.grow($div.children('div'));
		}
	};
	this.dispatch = function () {
		var $div = ( arguments.length === 0 ) ? $('#VIEW > div') : $(arguments[0]);
		//console.info('dispatch:',$div);
		var ma = this;
		$div.each( function ( i,e ) {
			var dispatch = $(this).attr('ma:dispatch');
			if ( dispatch ) {
				//console.info('dispatching for:', dispatch);
				if ( dispatch.match(/^([0-6]):([A-Z]+)\((.*)\)$/) ) {
					var deep = RegExp.$1;
					var command = RegExp.$2;
					var json_STR = RegExp.$3;
					var param = '('+ json_STR +')';
					$div.removeAttr('ma:dispatch');
					if ( deep === '0' ) {
						var make_old = $div.attr('ma:make');
						var make_new = (command + param) + (make_old ? (';'+ make_old) : '');
						$div.attr('ma:make', make_new);
						//ma.make($div);
					} else {
						deep -= 1;
						$div.children('div').each( function ( i,e ) {
							//console.info('deep', deep, 'for',$(this));
							$(this).attr('ma:dispatch', deep +':'+ command + param);
						});
					}
					//console.info('message ok! deep:', deep, ' ', command, '(',json_STR,')' );
				} else { throw new Error('MA.dispatch(): Syntax ERRR: dispatch attribute do not match: '+ dispatch +' '+ PID); }
			}
		});
	};
	this.fit = function () {
		var colWidth = this.co;
		var freeCols = this.COLS;
		var freePixels = colWidth * freeCols;
		var $divs = $('#VIEW > div');
		var lastCol = $divs.length - 1;
		$divs.each( function ( col,e ) {
			var ma_width = $(this).attr('ma:width');
			var width;
			if ( ma_width ) {
				if ( ! ma_width.match(/^(\d?[,.]\d+|[,.]\d+|\d+)\s*(Logo-Width|maco)?/)) {
					throw new Error('MA.fit() Syntax ERRR: attribute ma:width="'+ ma_width +'" not match! '+ PID); alert('WOW!!!! That shouldn\'t be happening... Wer war das???'); return;
				} else { width = parseInt(colWidth * parseFloat(RegExp.$1)); }
			} else {
				if ( col !== lastCol ) { width = colWidth; }
				else { width = freePixels; }
			}
			$(this).css({'float':'left', 'width':(width)+'px'});
			//console.info('this.fit:','col',col,width,'px');
			freeCols -= 1;
			freePixels -= width;
		});
		//this.setMaxHeight();
	};	
	this.clone = function () {
		var its = arguments.length === 0 ? {
			'#Navig > div': [ 'body #HEADER' , 'body #FOOTER' ],
			'#Content > div': [ '#VIEW' ]
		} : arguments[ 0 ];
		for ( var block in its ) {
			for ( var target in its[block] ) {
				$(block).clone().appendTo(its[block][target]);
				//console.info('clone "'+ block +'" and append to "'+ its[block][target] +'"');
			}
		}
		/*console.info('this.MA: ',this.MA);
		if ( this.MA ) {
		
			$('#'+'M'+'A').show();
			$('.Navig .Item a').each( function ( i,e ) {
				var a = $(this);
				var href = a.attr('href');
				if ( ! href.match( /#MA$/ ) ) {
					a.attr('href',href + '#MA');
				}
			});
		}
		*/
	};
}

   //___________________________________________________________________________
  //                                                                    BEGIN   
 //   ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ




 /*
	var m = function ($M) {
		console.info($M);
		console.info('outerWidth(true)',$M.outerWidth(true));
		console.info('outerHeight(true)',$M.outerHeight(true));
		console.info('----------------------');
	};
	*/


	// :) :) :) :) :) :) :) :) :) :) :) :)
	//var ma = new M_v2 (185,5);
	
	//$('#MA').hide();
	//$('#PAGE').show();
	
	var ma = new MA (185,5);
	ma.clone();
	ma.fit();
	ma.grow();

	// :) :) :) :) :) :) :) :) :) :) :) :)

	//console.info('ma2.ID',ma2.ID);
	//console.info('MA.ID',MA.ID);



	$(':header + p').each( function ( i,e ) {
		$(this).css('margin-top','0px');
	});


	// GMAPS ###################################################################
	var $a = $('.KONTAKT #PAGE .GMAP-START');
	if ( $a.length > 0 ) {
		var $map = $('<iframe id="GMAP" src="'+ $a.attr('href') +'"></iframe>');
		var $start = $('<span id="GMAP-START" class="'+ $a.attr('class') +'">'+ $a.html() +'</span>');
		//var $on = $('<span id="GMAP-ON">zurück</span>');
		$start.insertAfter($a);
		$a.detach();
		$('#GMAP-START').click( function ( eve ) {
			if ( $('#GMAP').length > 0 ) {
				//$('#GMAP-ON').fadeIn();
				$('#GMAP').fadeIn(500);
			} else {
				$map.prependTo($('#PAGE .CONTENT'));
				$('#GMAP').fadeIn();
				//$('#FOOTER').prepend($on);
				//$('#GMAP-ON').click( function ( eve ) {
				//	$('#GMAP-ON').fadeOut();
				//	$('#GMAP').fadeOut();
				//});
				$('.SUBMENU .Navig').click( function ( eve ) {
					//$('#GMAP-ON').fadeOut();
					$('#GMAP').fadeOut(500);
				});
			}
		});
	}

	// SLIDESHOW################################################################
	if ( $('#PAGE .MA_SLIDESHOW').length > 0 ) {
		window.ma_ssc = new MA_SLIDESHOW_CONTROL;
		window.ma_ssc.start();
	}

	// SCROLL###################################################################
	if ( $('#PAGE .MA_SCROLLABLE').length > 0 ) {
		window.ma_scrolls = new MA_SCROLLS;
	}

	$('body.INDEX .COL1 p').delay(2000).fadeIn(5500);

	if ( ma.modus.MA ) {
		$('#MA #Navig a').each( function( i,e ) {
			var href_MA = $(this).attr('href') + '#MA';
			$(this).attr('href', href_MA);
			console.info($(this).attr('href'));
		});
		$('#MA').show();
	}

   //___________________________________________________________________________
  //                                                         windows onload end
 //   ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
}; 




