$(function() {
	$("a[href^='http:']:not([href*='"  + window.location.host + "']):not([href^='/']):not([href^='#']):not([href^='mailto:']):not([rel^='ceebox'])").click( function(e) {
	//$("a['href~=http://']:not([href~='<?php echo $_SERVER['HTTP_HOST'];?>']):not([href^='/']):not([href^='#']):not([href^='mailto:'])").click( function(e) {
		window.open(this.href);
		e.preventDefault();
	});
	//$("#kontaktform").validationEngine();
	$('textarea').not('.markitup').resizable();
	$('.markitup').markItUp(mySettings); //<textarea class="markitup" rows="10" cols="40"><\/textarea>
	$('input').attr({'autocomplete':'off'});
	$('a[rel=ceebox]').ceetip().ceebox();
	$('#aktionslinks').append('<a class="print" href="#">Drucken<\/a>');
	$('a.print').click(function(e){ e.preventDefault(); window.print(); });

	// Autocomplete UI http://net.tutsplus.com/tutorials/javascript-ajax/how-to-use-the-jquery-ui-autocomplete-widget/
	//attach autocomplete
	// http://www.unibytes.com/dKhaq3PKF1IB
	$("#search").autocomplete({
		//define callback to format results
		source: function(req, add){
			//pass request to server
			$.getJSON("autocomplete-suche.html?callback=?", req, function(data) {
				//create array for response objects
				var suggestions = [];
				//process response
				$.each(data, function(i, val){
				suggestions.push(val.angebot);
			});
			//pass array to callback
			add(suggestions);
		});
	},

	//define select handler
	select: function(e, ui) {
		//create formatted friend
		var angebot = ui.item.value,
			span = $("<span>").text(angebot),
			a = $("<a>").addClass("remove").attr({
				href: "javascript:",
				title: "Remove " + angebot
			}).text("x").appendTo(span);
		},
		//define select handler
		change: function() {}
	}).unbind("blur.autocomplete");
	
	// Hintegrundbild
	if($.browser.msie && $.browser.version.substr(0,1) <= '6'){
		$(document).ready(function(){
			$(document).pngFix();
		});
	}
	if(!$.browser.msie || ($.browser.msie && $.browser.version.substr(0,1) > '6')){
		var theImages = new Array();
		theImages[1] = '/layout/freiberg1.jpg';
		theImages[2] = '/layout/freiberg2.jpg';
		theImages[3] = '/layout/freiberg3.jpg';
		var x = Math.floor(Math.random() * theImages.length);
		if(x < 1){ x = 1; }
		if(x > theImages.length){ x = theImages.length; }
		//$('#content').html(x);
		var ThisRandomImage = theImages[x];

		$(document).bgStretcher({
			images: [ThisRandomImage], imageWidth: 2000, imageHeight: 1333
		});
	}
});

