$(document).ready(function() {
	if (self != top) top.location.href=self.location.href;
	if(is_ie) {
		var menu = document.getElementById('oben').getElementsByTagName('ul');
		var i = menu.length;
		do {
			menu[i].setAttribute("id","menu"+i);
			if (menu[i].parentNode.nodeName == "LI") {
				menu[i].parentNode.onmouseover = function () {this.lastChild.style.display = "block";}
				menu[i].parentNode.onmouseout = function ()  {this.lastChild.style.display = "none";}
			}
		} while (--i);
	}
	if (document.getElementById('referenzfenster')) {
		$('#referenzen').cycle({ 	
			fx:      'scrollHorz',
			delay:   -4000 
		});
	}
	if (document.getElementById('mp3_1')) {
		$("#mp3_1").jmp3({
			backcolor: "000000",
			forecolor: "00ff00",
			width: 150	
		});
		$("#mp3_2").jmp3({
			width: 25,
			showdownload: false
		});
	}
	if (document.getElementById('flv_0')) {
		flowplayer("player", "/jquery/flowplayer-3.1.5.swf"); 
	}
	if (document.getElementById('popup')) {
		 $('#popup .lb').lightBox();
	}
	if (document.getElementById('ad-gallery')) {
		var galleries = $('.ad-gallery').adGallery({
		  thumb_opacity: 1, 						// Opacity that the thumbs fades to/from, (1 removes fade effect)
		  slideshow: { enable: false },
		  callbacks: {								// Executes right after the internal init, can be used to choose which images
			init: function() {  this.preloadAll();	 // preloadAll uses recursion to preload each image right after one another
			}
		  }
		});
	}
	else if (document.getElementById('galleria')) {
		$('.gallery ul').galleria({
			history   : false,				// activates the history object for bookmarking, back-button etc.
			clickNext : true, 				// helper for making the image clickable
			insert    : '#hauptansicht',			// the containing selector for our main image
			onImage   : function(image,caption,thumb) {	// let's add some image effects for demonstration purposes
				if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
					image.css('display','none').fadeIn(500);
				}
				caption.css('display','none').fadeIn(500);						// fade in the image & caption
				var _li = thumb.parents('li');									// fetch the thumbnail container
				_li.siblings().children('img.selected').fadeTo(500,0.3);		// fade out inactive thumbnail
				thumb.fadeTo('fast',1).addClass('selected');					// fade in active thumbnail
				image.attr('title',thumb.attr('title'));						// add a title for the clickable image
			},
			onThumb : function(thumb) { 										// thumbnail effects goes here
				var _li = thumb.parents('li');									// fetch the thumbnail container
				var _fadeTo = _li.is('.active') ? '1' : '0.3';					// if thumbnail is active, fade all the way.
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(500);		// fade in the thumbnail when finnished loading
				thumb.hover(													// hover effects
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
				)
			}
		});
		var div = $('#galleria'),				//Get our elements for faster access and set overlay width
			ul = $('#galleria ul'),
			ulPadding = 15;
		var divWidth = div.width();				//Get menu width
		div.css({overflow: 'hidden'});			//Remove scrollbars	
		var lastLi = ul.find('li:last-child');	//Find last image container
		div.mousemove(function(e){				//When user move mouse over menu
			var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;		//As images are loaded ul width increases, 
			var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;	//so we recalculate it each time
			div.scrollLeft(left);
		});
	}
});
function gb_verify() {
	var verify = Math.random();
	if (document.getElementById('gb_verify')) document.getElementById('gb_verify').innerHTML ='<input type="hidden" name="verify" value="'+verify+'" />';
}
function addSmiley(id) {
	if (document.selection && document.selection.createRange().text != '') {
		document.selection.createRange().text = document.selection.createRange().text + "["+id+"]";
	} else {
		document.getElementsByTagName('textarea')[0].value += "["+id+"]";
		document.getElementsByTagName('textarea')[0].focus();
}	}
function edit(start,end,id) {
	var textfield = document.getElementsByTagName('textarea')[0];
	if (textfield.selectionStart || textfield.selectionStart == '0') {
		textfield.focus();
		var startPos = textfield.selectionStart;
		var endPos = textfield.selectionEnd;
		strSelection = start + textfield.value.substring(startPos, endPos)+ end;
		textfield.value = textfield.value.substring(0, startPos) + strSelection + textfield.value.substring(endPos, textfield.value.length);
	}
	else if (document.selection && document.selection.createRange().text != '') {
		document.selection.createRange().text = start + document.selection.createRange().text + end;
	} else {
		if (document.getElementById(id).style.color=="#aaa") {
			textfield.value += end;
			document.getElementById(id).style.color="blue";
		} else {
			textfield.value += start;
			document.getElementById(id).style.color="#aaa";
}	}	}
function header() {edit("[h]","[/h]","header");}
function list() {edit("[list]","[/list]","list");}
function url() {
	url = prompt("Bitte geben Sie die gewünschte URL ein:", "http://");
	edit("[url="+url+"]","[/url]","url");
}
function color(color) {edit("[color="+color+"]","[/color]","color");}
function fett() {edit("[b]","[/b]","fett");}
function italic() {edit("[i]","[/i]","italic");}
function uline() {edit("[u]","[/u]","uline");}
function vorschau() {
	var textarea = document.getElementsByTagName('textarea')[0].value.split('[');
	vorschautext = textarea[0];
	for (var i=0; i<textarea.length; i++) {
		bracket = textarea[i].split(']')[0];
		if (bracket == 'b') {vorschautext += '<span style="font-weight: bolder;">' + textarea[i].split('b]')[1].split('/b]')[0];}
		if (bracket == 'i') {vorschautext += '<span style="font-style: italic;">' + textarea[i].split('i]')[1].split('/i]')[0];}
		if (bracket == 'u') {vorschautext += '<span style="text-decoration: underline;">' + textarea[i].split('u]')[1].split('/u]')[0];}
		if (bracket == '/b' || bracket == '/i' || bracket == '/u') {vorschautext += '</span>' + textarea[i].split(']')[1];}
		else {
			if (document.getElementById(bracket) && bracket != '') 	vorschautext +=  '<img src="'+document.getElementById(bracket).src+'">'+textarea[i].split(']')[1];
	}	}
	vorschau_window = window.open('',"Vorschau","toolbar=no,width=500,height=200,directories=no,scrollbars,status=no,menubar=no,resizable=yes");
	vorschau_window.document.open();
	vorschau_window.document.writeln('<html><head>');
	vorschau_window.document.writeln('<title>Vorschau</title>');
	vorschau_window.document.writeln('</head><body onblur="self.close()">');
	vorschau_window.document.writeln('<p>'+vorschautext.replace('\n','<br />')+'</p>');
	vorschau_window.document.writeln('<div style="position:absolute;right:3px;bottom:3px;"><a href="javascript:" onclick="self.close()">Schließen</a></div>');
	vorschau_window.document.writeln('</body></html>');
	vorschau_window.document.close();
	vorschau_window.focus();
}
