$( document ).ready( function()
{
	function decodeMail( m ){ for( var r = "", i = 0; i<m.length; i++ ) r += String.fromCharCode(m.charCodeAt(i)-3+2); return r; }
	
	$.fn.fixPng = function( settings )
	{
		if( document.all && !window.opera )
		{
			this.each( function( i )
			{
				if (this.src.substring(this.src.lastIndexOf(".")) == ".png")
				{
					this.style.height = this.offsetHeight+"px";
					this.style.width = this.offsetWidth+"px";
					this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "',sizingMethod='scale')";
					this.src = settings.src;
				};
			});
		};
	};
	 
	var ColorFade = at.leichtgewicht.color.ColorFade;
	
	var fader = new ColorFade( { saturation: 0.43, brightness: 0.64, cycle: 50000,
		rules: {
			"h1 a, #line": ["background-color"],
			"#searchWrapper": ["border-bottom-color"],
			"#sideInformation, a": ["color"],
			".proud-to-introduce": ["background-color"]
		}
	} );
	
	var darkerFader = new ColorFade( { saturation: 0.3, brightness: 0.3, cycle: 50000,
		rules: {
			"a:hover, #myadress:hover": ["color"],
			"div.script.submit:hover img": ["background-color"],
			"input:focus": ["border-bottom-color"]
		}
	} );

	var brighterFader = new ColorFade( { saturation: 0.1, brightness: 0.95, cycle: 50000,
		rules: { "div.script.submit:hover img": ["border-color"]}
	} );
	
	$("#search .submit").addClass("script");
	$('<img src="'+templatePath+'/images/start_search.gif" style="height:'+(10/12)+'em; width:'+(10/12)+'em;" class="button" />').appendTo("#search .submit");
	
	$("#myadress").html( decodeMail( "ni'$y51<mfjdiuhfxjdiu/bu" ) );
	$("#myadress").click( function() { document.location.href="mailto:"+decodeMail( "niAmfjdiuhfxjdiu/bu" ); });
	$("#wrapper").append("<div id=\"line\"><img src=\""+templatePath+"/images/gradient.png\" height=\"250\"/></div>");
	$("img").fixPng({src:templatePath+"/images/transparent.gif"});
	$("body").addClass("scriptEnabled");
	$("#wrapper").focus();

       dp.SyntaxHighlighter.ClipboardSwf = templatePath+'js/syntax/clipboard.swf';
       dp.SyntaxHighlighter.HighlightAll('code');

	$(".hidden .dp-highlighter").each( function( c, elem ) {
		var button = $("<a href=\"#\">Source Code</a>");
		$( elem ).before( button );
		$( elem ).hide();
		$( button ).click( function() {
			$(elem).toggle();
		});
	});
	$("#tweets").jTwit({
		username: 'leichtgewicht',
		updatefrequency: 60000,
		showfriends: false,
		sizetofit: false,
		maxtweets: 1 
	});
	var lightBoxPath = templatePath+"/js/jquery-lightbox-0.5/images/";
	$(".imagelist a").lightBox({
		imageLoading: lightBoxPath + 'lightbox-ico-loading.gif',
		imageBtnPrev: lightBoxPath + 'lightbox-btn-prev.gif',
		imageBtnNext: lightBoxPath + 'lightbox-btn-next.gif',
		imageBtnClose: lightBoxPath + 'lightbox-btn-close.gif',
		imageBlank: lightBoxPath + 'lightbox-blank.gif'
	});
});