$(document).ready(function(){
	// $(document).pngFix();

	$('.nav ul li:first-child').addClass('first');
	
	// $('#fwHead .nav ul li ul li:first-child, #fwRightNav>ul>li:first-child, #fwFooterNav ul li:first-child').addClass('first');
	$('#fwHead .nav ul li ul li:last-child').addClass('last');

	// $('#fwHead .nav ul li').hover(function(){
	// 	$(this).addClass('hover');
	// }, function(){
	// 	$(this).removeClass('hover');
	// });

	// alignHeights('#fwContentBottom .bii');
	// alignHeights('#fwContentMain .bii, #fwContentRight, .bii'); // Funktioniert nicht ganz richtig.

	// var lh = $('#fwContentMain .bii').height();
	// var rh = $('#fwContentRight .bii').height();
	// if(lh<rh) {
	// 	$('#fwContentMain .bii').height(rh);
	// }

	// $('#fwContentMain img').each(function(){
	// 	wrapInBox(this);
	// });

	// $('.b').each(function(){
	// 	addShadows(this);
	// });

	$('#fwContentMain a, #fwContentBottom a').each(function(){
		var linkType = 0;
		var linkType2 = 0;
		var href = $(this).attr('href');
		
		if(href.search(/:\/\//i)>-1) {
			// external
			linkType = 'external';
		} else {
			// internal
			// linkType = 'internal';
	
			// email
			if(href.search(/@/)>-1 || href.search(/linkTo_UnCryptMailto/i)>-1) {
				linkType = 'email';
			}
	
			// file
			var fileSuffixes = new Array(/\.pdf$/i, /\.exe$/i, /\.zip$/i);
			for(x=0; x<fileSuffixes.length; x++) {
				if(href.search(fileSuffixes[x])>-1) {
					linkType = 'file';
					// linkType2 = fileSuffixes[x];
				}
			}
		}
	
		if(linkType) {
			console.log(linkType);
			$(this).addClass('icon').addClass(linkType);
			if(linkType2) {
				$(this).addClass(linkType2);
			}
		}
		
	});

});

function wrapInBox(el) {
	var cssFloat = $(el).css('float'); // get float of element to be wrapped
	$(el).css('float', ''); // remove float
	var b = $('<div />').addClass('b').addClass('nc'); // new wrapper element
	if(el.tagName.toLowerCase()=='img') { // add img class if this is an image
		b.addClass('img');
	}
	if(cssFloat=='left' || cssFloat=='right') { // add float class back if needed
		b.addClass(cssFloat);
	}
	$(el)
		.wrap(b)
		.wrap('<div class="bi" />')
		.wrap('<div class="bii" />');
}

function addShadows(el) {
	var shadowSize = 5;
	var bw = $(el).width() + shadowSize;
	var bh = $(el).height() + shadowSize;

	var st = $('<div></div>').addClass('s').addClass('st').css('width',  (bw)+'px');
	var sb = $('<div></div>').addClass('s').addClass('sb').css('width',  (bw)+'px');

	var sr = $('<div></div>').addClass('s').addClass('sr').css('height', (bh)+'px');
	var sl = $('<div></div>').addClass('s').addClass('sl').css('height', (bh)+'px');

	$(el).append(st).append(sb).append(sr).append(sl);
}

function alignHeights(sel) {
	if($(sel).length>1) {
		var highest = 0;
		$(sel).each(function(){
			var thisHeight = $(this).height();
			if(thisHeight>highest) {
				highest = thisHeight;
			}
		});
		$(sel).height(highest);
	}
}
