/**
 * @author Alexander Farkas
 * v. 1.21
 *
 * Fixing IE8 buggyness
 * 
 */

(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);


$(function(){
	var b=window.location.hash;
	var d=$("#content");
	var a=$("#loading");
	if(b!=""){
		var c=b.substring(1);
		a.show();
		$.ajax({
			url:c,
			type:"GET",
			success:function(e){
				if(!$("#topheader").hasClass("folded")){
					$("#topheader")
						.animate({
							"font-size":"30px",
							"margin-top":"20px",
							"margin-bottom":"10px"
						},
						{
							duration:500
						})
						.addClass("folded");
				}
				d.html(e);
				d.show(1,function(){
					d.fadeIn(300);
				});
				$(".menulink").each(function(){
					if($(this).attr("href")==c){
						$(this).addClass("activelink")
					}
				});
				$(".menulink:not('.activelink')").fadeTo(500,0.2);
				$(".activelink").fadeTo(500,1);
				$("#ichtransparent").fadeTo(100,0.2);
				a.hide();
			}
		});
	}
	$(".menulink").live("click",function(){
		var e=$(this).attr("href");
		window.location.hash=e;
		a.show();
		d.fadeOut(100).hide(1,function(){
			$.ajax({
				url:e,
				type:"GET",
				success:function(f){
					if(!$("#topheader").hasClass("folded")){
						$("#topheader")
						.animate({
							"font-size":"30px",
							"margin-top":"20px",
							"margin-bottom":"10px"
						},
						{
							duration:500
						})
						.addClass("folded");
					}
					d.html(f);
					d.show(1,function(){
						d.fadeIn(300)
					});
					a.hide();
				}
			});
		});
		$(".menulink").removeClass("activelink");
		$(this).addClass("activelink");
		$(".menulink:not('.activelink')").fadeTo(500,0.2);
		$(".activelink").fadeTo(500,1);
		$("#ichtransparent").fadeTo(100,0.2);
		return false;
	});
	$(".entwicklung_naviul li a").live("click",function(){
		$(".entwicklung_topdiv").hide("slow");
		$(".active_entwicklungslink").removeClass("active_entwicklungslink");
		$(this).addClass("active_entwicklungslink");
		var e=$(this).attr("rel");
		$(".entwicklung_div").hide();
		$("#"+e).fadeIn(300);
		return false;
	});
	$("#KontaktKontaktForm").live("submit",function(){
		var f=$(this).serialize();
		var e=$(this).attr("action");
		$.ajax({
			url:e,
			data:f,
			type:"POST",
			success:function(g){
				$("#content").html(g);
				if($("#flashMessage").length){
					setTimeout('$("#flashMessage").fadeOut(2000)',3000);
				}
			}
		});
		return false;
	})
});
