/*////////////////////////////////////////////////////////////*/
/* MatthiasSchuetz.com JavaScript | (C) 2009 Matthias Schuetz */
/*////////////////////////////////////////////////////////////*/

/*
 * jQuery EasIng v1.1.2 - http://gsgd.co.uk/sandbox/jquery.easIng.php
 *
 * Uses the built In easIng capabilities added In jQuery 1.1
 * to offer multiple easIng options
 *
 * Copyright (c) 2007 George Smith
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 */
jQuery.extend( jQuery.easing,
{
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	}
});

/**
 * @author Alexander Farkas
 * v. 1.02
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == "string") {
                var start = $.curCSS(fx.elem,"backgroundPosition");
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            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];

           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]];
           }
        }
	});
})(jQuery);

$(document).ready(function(){
	$(function(){
		$("#searchbox")
			.focus(function(){
				searchValue = $(this).attr("value");
				if (searchValue == "Suchbegriff") { $(this).attr({ value: "" }) };
			})
			.blur(function(){
				inputValue = $(this).attr("value");
				if ($.trim(inputValue) == "") { $(this).attr({ value: searchValue }) };
			})

		function slideFX(mnuName, xPos, yPos, xPosAni, yPosAni) {
			$(mnuName)
				.css({ backgroundPosition:xPos+" "+yPos })
				.mouseover(function(){
					$(this).stop().animate({ backgroundPosition:"("+xPosAni+" "+yPosAni+")"}, 500, "easeOutExpo");
				})
				.mouseout(function(){
					$(this).stop().animate({ backgroundPosition:"("+xPos+" "+yPos+")"}, 1400, "easeOutExpo");
				})
		}
		slideFX(".mnu_start", "-265px", "-302px", "0px", "-302px");
		slideFX(".mnu_artikel", "-265px", "-348px", "0px", "-348px");
		slideFX(".mnu_projekte", "-265px", "-401px", "0px", "-401px");
		slideFX(".mnu_extras", "-265px", "-454px", "0px", "-454px");
		slideFX(".mnu_kontakt", "-265px", "-507px", "0px", "-507px");

		if ($.browser.msie) {
			$(".imagelink")
				.mouseover(function(){
					$(this).css({ opacity: 0.5, marginLeft: "-3px" });
				})
				.mouseout(function(){
					$(this).css({ opacity: 1 });
				})
			
			$(".projectlink, .extralink")
				.css({ backgroundPosition:"-10px -146px" })
				.mouseover(function(){
					$(this).stop().animate({ backgroundPosition:"(-10px 0)"}, 50);
					$(this).children("img").stop().animate({ opacity: 0.5 }, 20);
				})
				.mouseout(function(){
					$(this).stop().animate({ backgroundPosition:"(-10px -146px)"}, 10);
					$(this).children("img").stop().animate({ opacity: 1 }, 50);
				})
		} else {
			$(".imagelink")
				.mouseover(function(){
					$(this).stop().fadeTo(200, 0.5);
				})
				.mouseout(function(){
					$(this).stop().fadeTo(650, 1);
				})
			
			$(".projectlink, .extralink")
				.css({ backgroundPosition:"-10px -146px" })
				.mouseover(function(){
					$(this).stop().animate({ backgroundPosition:"(-10px 0)"}, 120);
					$(this).children("img").stop().animate({ opacity: 0.5 }, 140 );
				})
				.mouseout(function(){
					$(this).stop().animate({ backgroundPosition:"(-10px -146px)"}, 10);
					$(this).children("img").stop().animate({ opacity: 1 }, 600);
				})	
		}

		function crossfadeFX(itemName, pos) {
			$(itemName)
				.css({ backgroundPosition: pos })
				.prepend("<div class=\"hoverimage\"></div>")
				.append("<div class=\"hoverarea\"></div>");
			$(itemName + " .hoverimage").css({ opacity: 0 })
			$(itemName + " .hoverarea")
				.mouseover(function(){
					$(this).parent().find("div.hoverimage").stop().animate({ opacity: 1 }, 250);
				})
				.mouseout(function(){
					$(this).parent().find("div.hoverimage").stop().animate({ opacity: 0 }, 850) ;
				})
		}
		crossfadeFX(".webdesigntools #rankcheck", "0 0");
		crossfadeFX(".webdesigntools #werkzeugkoffer", "0 -134px");
		crossfadeFX(".webdesigntools #javascriptmatrix", "0 -268px");
		crossfadeFX("#pageslider .pslogo", "-496px 0");

		try {
			$("#showcased").attr({ href: window.location.href + "#showcased" })
			$("#showcased, .featuredbox")
				.mouseover(function(){
					$(".featuredbox").css({ display:"block" })
					$(".featuredbox").stop().animate({ opacity: 1 }, 240);
				})
				.mouseout(function(){
					$(".featuredbox").stop().animate({ opacity: 0 }, 300, function(){ $(".featuredbox").css({ display:"none" }) });
				})
			
			$(".rssfeedbox, .delicious, .wong")
				.mouseover(function(){
					$(this).stop().animate({ paddingLeft: "35px", opacity: 0.7 }, 240, "easeOutExpo");
				})
				.mouseout(function(){
					$(this).stop().animate({ paddingLeft: "28px", opacity: 1 }, 240, "easeOutExpo");
				})
			
			adressLocation = window.location.href;
			
			if (adressLocation.search(/matthiasschuetz.com\/projekte/) != -1) {
				if (adressLocation.search(/projekte#grafikdesign/) != -1) {
					activeTabNum = 2;
				} else {
					activeTabNum = 1;
				}
				
				$.jtabber({
					mainLinkTag: "#tabs_projekte a",
					activeLinkClass: "tabactive",
					hiddenContentClass: "tabbed",
					showDefaultTab: activeTabNum,
					showErrors: false,
					effect: "fade",
					effectSpeed: "medium"
				});
			}

			if (window.location.href.toString().substr(-7) == "/extras") {
				$.jtabber({
					mainLinkTag: "#tabs_extras a",
					activeLinkClass: "tabactive",
					hiddenContentClass: "tabbed",
					showDefaultTab: 1,
					showErrors: false,
					effect: "fade",
					effectSpeed: "medium"
				});
			}

			$("body").append("<style type=\"text/css\">div.tabbed { display:none; }</style>");
			slideFX("#projekte_1", "0px", "0px", "0px", "-40px");
			slideFX("#projekte_2", "-95px", "0px", "-95px", "-40px");
			slideFX("#projekte_3", "-206px", "0px", "-206px", "-40px");
			slideFX("#projekte_4", "-275px", "0px", "-275px", "-40px");
			slideFX("#projekte_5", "-417px", "0px", "-417px", "-40px");
			slideFX("#extras_1", "0px", "0px", "0px", "-40px");
			slideFX("#extras_2", "-93px", "0px", "-93px", "-40px");
			slideFX("#extras_3", "-197px", "0px", "-197px", "-40px");
			slideFX("#extras_4", "-299px", "0px", "-299px", "-40px");
			slideFX("#extras_5", "-399px", "0px", "-399px", "-40px");
			$(".projectlink").fancybox({ "zoomSpeedIn": 400, "zoomSpeedOut": 200, "frameWidth": 550, "frameHeight": 350, "overlayShow": true, overlayopacity:  0.8, "hideOnContentClick": true });
		} catch(e) {}

		try {
		$("p.articleimage > a")
			.prepend("<div style='position:absolute;right:0px;bottom:0px;width:32px;height:32px;background:url(images/zoom.gif) no-repeat;'></div>")
			.mouseover(function(){
				$(this).stop().animate({ opacity: 0.7 }, 240, "easeOutExpo");
			})
			.mouseout(function(){
				$(this).stop().animate({ opacity: 1 }, 240, "easeOutExpo");
			})
			.fancybox({ "zoomSpeedIn": 400, "zoomSpeedOut": 200, "frameWidth": 550, "frameHeight": 350, "overlayShow": true, overlayopacity:  0.8, "hideOnContentClick": true });
		} catch(e) {}
	});
});

function showsource(sourcecode) {
	var source = document.getElementById(sourcecode).parentNode.parentNode.innerHTML;
	source = source.replace(/(&nbsp;)/ig, " ");
	source = source.replace(/(\t)/ig, "");
	source = source.replace(/(Quelltext)/ig, "");
	if ($.browser.msie) {
		source = source.replace(/(tab>)/ig, ">\t");
		source = source.replace(/(tab>)/ig, ">\t");
		source = source.replace(/(tab>)/ig, ">\t");
		source = source.replace(/(tab>)/ig, ">\t");
		source = source.replace(/(tab>)/ig, ">\t");
		source = source.replace(/(tab>)/ig, ">\t");
		source = source.replace(/(tab>)/ig, ">\t");
		source = source.replace(/(tab>)/ig, ">\t");
		source = source.replace(/(<BR>)/ig, "BR");
		source = source.replace(/(<([^>]+)>)/ig, "");
		source = source.replace(/(BR)/ig, "\n");
	} else {
		source = source.replace(/(tab">)/ig, "\">\t");
		source = source.replace(/(tab">)/ig, "\">\t");
		source = source.replace(/(tab">)/ig, "\">\t");
		source = source.replace(/(tab">)/ig, "\">\t");
		source = source.replace(/(tab">)/ig, "\">\t");
		source = source.replace(/(tab">)/ig, "\">\t");
		source = source.replace(/(tab">)/ig, "\">\t");
		source = source.replace(/(tab">)/ig, "\">\t");
		source = source.replace(/(\<br\>)/ig, "BR");
		source = source.replace(/(<([^>]+)>)/ig, "");
		source = source.replace(/(BRBR)/ig, "\n");
		source = source.replace(/(BR)/g, "");
	}
	source = "<pre>" + source + "</pre>";
	windowX = screen.width/2 - 400;
	windowY = screen.height/2 - 300;
	var sourceWindow = window.open("about:blank", "popup", "toolbar=no, width=800, height=600, top=" + windowY + ", left=" + windowX + ", resizable=yes, scrollbars=yes"); 
	sourceWindow.document.write(source);
	sourceWindow.document.close();
};

function showresult(result) {
	resultImage = (result.indexOf("b") != -1) ? result.slice(0, 4) : result;
	if (result.indexOf("c") != -1) { resultImage = "res" + result.slice(5, 6); result = result.slice(0, 4); }
	var resultBox = "<div id='resultbox' style='position:absolute;top:-195px;right:-1px;width:300px;height:178px;background:url(/content/artikel/jquery_tut2_" + resultImage + ".gif) no-repeat;border:5px #f9f6ee solid;z-index:3;'></div>";
	$("#" + result)
		.after(resultBox)
		.mouseout(function(){
			$("#resultbox").stop().animate({ opacity: 0 }, 500, "easeOutExpo", function(){ $(this).remove(); });
		})
		.click(function(){
			$("#resultbox").stop().animate({ opacity: 0 }, 500, "easeOutExpo", function(){ $(this).remove(); });
		});
};