$(document).ready(function () {
    $("#navigation a").prepend("<span></span>");
    $("#content_wrapper h3").append("<span></span>");
    $("#navigation a").mousedown(function () {
        $(this).addClass("hilite")
    }).mouseup(function () {
        $(this).removeClass("hilite")
    }).mouseleave(function () {
        $(this).removeClass("hilite")
    });
    $.easing.bouncy = function (f, g, e, j, i) {
        var h = 1.70158;
        if ((g /= i / 2) < 1) {
            return j / 2 * (g * g * (((h *= (1.525)) + 1) * g - h)) + e
        }
        return j / 2 * ((g -= 2) * g * (((h *= (1.525)) + 1) * g + h) + 2) + e
    };
    $.tools.tooltip.addEffect("bouncy_up", function (e) {
        this.getTip().animate({
            top: "-=15"
        }, 500, "bouncy", e).show()
    }, function (e) {
        this.getTip().animate({
            top: "+=15"
        }, 500, "bouncy", function () {
            $(this).hide();
            e.call()
        })
    });
    $.tools.tooltip.addEffect("bouncy_down", function (e) {
        this.getTip().animate({
            top: "+=15"
        }, 500, "bouncy", e).show()
    }, function (e) {
        this.getTip().animate({
            top: "-=15"
        }, 500, "bouncy", function () {
            $(this).hide();
            e.call()
        })
    });
    $.tools.tooltip.addEffect("bouncy_cv", function (e) {
        this.getTip().animate({
            left: "-=15",
            top: "+=15"
        }, 500, "bouncy", e).show()
    }, function (e) {
        this.getTip().animate({
            left: "+=15",
            top: "-=15"
        }, 500, "bouncy", function () {
            $(this).hide();
            e.call()
        })
    });
    $("#logo a").tooltip({
        effect: "bouncy_down",
        offset: [-43, 0],
        position: "top center",
        tipClass: "tooltip logo"
    });
    $("#navigation a").tooltip({
        effect: "bouncy_up",
        offset: [20, 0],
        position: "bottom center"
    });
    $("#moi").tooltip({
        effect: "bouncy_cv",
        offset: [-15, 10],
        position: "top center",
        tipClass: "tooltip logo"
    });
    jQuery.fn.collapse = function () {
        return this.each(function () {
            jQuery(this).stop().animate({
                borderWidth: "0",
                margin: 0,
                opacity: 0,
                padding: 0,
                width: 0
            }, 350)
        })
    };
    jQuery.fn.expand = function (e) {
        return this.each(function () {
            jQuery(this).stop().animate({
                borderWidth: "1px",
                margin: "8px",
                padding: "14px",
                opacity: 1,
                width: e
            }, 350)
        })
    };

    function b(e) {
        e = e.toLowerCase();
        e == "alles" ? $("#portfolio li").expand(a) : $("#portfolio li").not("." + e).collapse().end().filter("." + e).expand(a)
    }
    if (!$.browser.msie) {
        $("#portfolio li").mouseenter(function () {
            $(this).find("img").stop().animate({
                opacity: 0.65
            }, 300).end().find(".project_visit").fadeIn("fast")
        }).mouseleave(function () {
            $(this).find("img").stop().animate({
                opacity: 1
            }, 150).end().find(".project_visit").fadeOut("fast")
        })
    } else {
        $("#portfolio li").mouseenter(function () {
            $(this).find("img").stop().animate({
                opacity: 0.65
            }, 300).end()
        }).mouseleave(function () {
            $(this).find("img").stop().animate({
                opacity: 1
            }, 150).end()
        })
    }
    $("#tags a").click(function (e) {
        e.preventDefault();
        $(this).parent().parent().find("li a").removeClass("active").end().end().end().addClass("active");
        window.location.hash = $(this).text().replace(" ", "-");
        b($(this).text().replace(" ", "-"));
        /*$("a.sort").each(function () {
			abc = this.href.substr(0, this.href.indexOf("#"))
			
			this.href = this.href.replace(this.href, abc + window.location.hash)
        })*/
    });
    var a = $("#portfolio li:first").width(),
        d = window.location.hash;
    if (d != "") {
        d = d.split("#");
        b(d[1]);
        $("#tags").find(".active").removeClass("active").end().find(".filter_" + d[1].toLowerCase()).addClass("active")
    }
    /*$("a.sort").each(function () {
		if (d != "") {
			if (d[1].length > 0){
				this.href = this.href.replace(this.href, this.href + "#" + d[1])
			}
		}
    });*/
	if($.browser.msie && (jQuery.browser.version == "6.0" || jQuery.browser.version == "7.0")){
		nColorBoxHeight = "575";	
	} else {
		nColorBoxHeight = "550";
	}
	
    $(".project_screenshot, .project_visit, .project_title").colorbox({
        height: nColorBoxHeight,
        iframe: true,
        opacity: 0.75,
        scrolling: false,
        width: "830"
    });

    function c() {
        if (!document.getElementsByTagName) {
            return
        }
        var g = document.getElementsByTagName("a");
        for (var f = 0; f < g.length; f++) {
            var e = g[f];
            if (e.getAttribute("href") && e.getAttribute("rel") == "external") {
                e.target = "_blank"
            }
        }
    }
    c()
});
function validateField(hash,min_length,email){
	field_val = $("#frm_" + hash).val();
	
	if (field_val.length == 0){
		$("#status_" + hash).removeClass('success').removeClass('error');
	} else {
		if (field_val.length < min_length){
			$("#status_" + hash).removeClass('success').addClass('error');
		} else {
			if (email === true && !validateEmail(field_val)){
				$("#status_" + hash).removeClass('success').addClass('error');
			} else {
				$("#status_" + hash).removeClass('error').addClass('success');
			}
		}
	}
}
function validateEmail(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}