(function($) {
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
	
	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			var start = $.curCSS(fx.elem,'backgroundPosition');
			
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			
			start = toArray(start);
			
			fx.start = [start[0],start[2]];
			
			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];
			
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		//return;
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);























var t = null;
		
function mouseoutLeistungenDropdown(elem) {
	var _self = elem;
	if (_self[0].state == 'open') {
		_self[0].state = 'animating';
		_self.find('ul').hide('fast',function(){
			_self[0].state = 'closed';
		});
	} //else idle around
}

$(window).load(function(){
	var leistungen_link = $('.droppable_nav');
	$.extend(leistungen_link[0], {state: 'closed'});
	$.extend(leistungen_link[1], {state: 'closed'});
	leistungen_link.find('ul>li,a').bind('mouseover', function(){
		window.clearTimeout(t);
	});
	
	$(leistungen_link[1]).bind('mouseover', function(){
		var _self = this;
        $(leistungen_link[0]).trigger('mouseout');
		if (_self.state == 'closed') {
			_self.state = 'animating';
			$(this).find('ul').show('fast',function(){
				_self.state = 'open';
			});
		} //else idle around
	});
    
    $(leistungen_link[0]).bind('mouseover', function(){
		var _self = this;
        $(leistungen_link[1]).trigger('mouseout');
		if (_self.state == 'closed') {
			_self.state = 'animating';
			$(this).find('ul').show('fast',function(){
				_self.state = 'open';
			});
		} //else idle around
	});
	
	$(leistungen_link[0]).bind('mouseout', function(){
		t = window.setTimeout(function(){mouseoutLeistungenDropdown($(leistungen_link[0]));}, 125);
	});
	
	$(leistungen_link[1]).bind('mouseout', function(){
		t = window.setTimeout(function(){mouseoutLeistungenDropdown($(leistungen_link[1]));}, 125);
	});
	
	leistungen_link.bind('click', function(){
		$(this).trigger('mouseover');
	});
	
	//and fix the footer!
	init_fit_footer();
});

function fit_footer() {
    var win_height = $(window).height();
    var footer = $('#footer');
    var footer_height = footer.height();
    var cont_height = $('#base').height();
    var totalHeight = footer_height+cont_height;
    
    if(totalHeight < win_height) {
        var diff = win_height-totalHeight;
        footer.css('margin-top', diff+'px');
    }
}

function init_fit_footer() {
    fit_footer();
    $(window).resize(function(){
       fit_footer(); 
    });
}




function bind_contactform_effects() {
	var the_form = $('#contact_form');
	var is_first = true;
	var fadeDownTo = 0.62;
	the_form.find('input[type=text]').each(function(ind){
		var _self = $(this);
		_self.bind('focus',function(){
			$(this).parent().animate({opacity: 1, borderBottomWidth: '2px'}, 300);
		});
		
		_self.bind('focusout',function(){
			$(this).parent().animate({opacity: fadeDownTo, borderBottomWidth: '1px'}, 300);
		});
		
		if (is_first) {
			is_first = false;
			_self.focus();
		} else {
			_self.parent().fadeTo(0, fadeDownTo);
		}
	});
	
	the_form.find('textarea').each(function(ind){
		var _self = $(this);
		_self.bind('focus',function(){
			$(this).animate({opacity: 1, borderBottomWidth: '2px'}, 300);
		});
		
		_self.bind('focusout',function(){
			$(this).animate({opacity: fadeDownTo, borderBottomWidth: '1px'}, 300);
		});
		
		_self.fadeTo(0, fadeDownTo);
	});
}



headerSlider = {
	_holder: null,
	totalSlides: -1,
	currSlideNum: 0,
	width:952,
	
	init: function(num) {
		this._holder = $('#header_positioned');
		this.totalSlides = num;
		this.next();
	},
	
	next: function() {
		var possibleNxNum = this.currSlideNum+1;
		if (possibleNxNum > this.totalSlides) {
			possibleNxNum = 1;
		}
		
		this.currSlideNum = possibleNxNum;
		
		minusLeft = -1*(this.currSlideNum-1)*this.width;
		$(this._holder).animate({backgroundPosition: ''+minusLeft+'px 0px'}, 500);
		
		window.setTimeout(function(){
			headerSlider.next();
		},5750);
	}
};




