var EWItools = {
	// Rollover fuer Elemente mit rolloverClass
	rollover: function(rolloverClass, hoverSuffix) {
		var elems = $("." + rolloverClass);
		elems.each(function() {
			var src = $(this).attr("src");
			var filetype = src.substr(src.lastIndexOf("."));
			var name = src.substring(0, src.lastIndexOf("."));
			$(this).hover(function() {
				this.src = name + hoverSuffix + filetype;
			}, function() {
				this.src = src;
			});
		});
	},
	// Textfield-Werte zuruecksetzen
	resetInputs: function() {
		var textfields = $("input:text");
		textfields.focus(function() { if (this.value == this.defaultValue) this.value = ""; });
		textfields.blur(function() { if (this.value == "") this.value = this.defaultValue; });
	}
};


function galleryFocus() {
	$("div.galerie").hover(function() {
		$(this).siblings().find("a").stop().fadeTo(400, 0.5);
	}, function() {
		$(this).siblings().find("a").stop().fadeTo(400, 1);
	});
}
function lightboxInit() {
	$("div.galerie a").lightBox({
		// txtImage: 'Bild',
		// txtOf: 'von',
		keyToClose: 'x',
		containerBorderSize: 9,
		fixedNavigation: false,
		imageLoading: '/js/knowledge_regions/jquery-lightbox-0.5/images/lightbox-ico-loading_wb.gif',
		imageBtnClose: '/js/jquery-lightbox-0.5/images/icon_close.gif',
		imageBtnPrev: '/js/jquery-lightbox-0.5/images/lightbox-btn-prev.gif',
		imageBtnNext: '/js/jquery-lightbox-0.5/images/lightbox-btn-next.gif'
	});
}

function setNavFirstChild() {
	var serviceNav = $("ul#serviceNav");
	if (serviceNav.length != 0) {
		serviceNav.find("li:first-child").addClass("first-child");
	}
}

function hoverOpacity(div) {
	var div = $("#" + div);
	if (div.length != 0) {
		var links = div.find("a");
		links.click(function() {
			window.open(this.href);
			return false;
		});
		var imgs = div.find("img");
		imgs.hover(function() {
			$(this).stop().fadeTo(250, 0.5);
		}, function() {
			$(this).stop().fadeTo(250, 1);
		});
	}
}

function highlightSiblings () {
	// $("ul#subNav li.current").siblings("li").addClass("sibling");
	var subNavLinks = $("ul#subNav a")
	subNavLinks.each(function() {
		var $this = $(this);
		if (this.href.indexOf(window.location.pathname) != -1) {
			$this.addClass("CURRENT");
			$this.parent("li").siblings().addClass("SIBLING");
			$this.parents("ul").siblings("a").addClass("PARENT");
		}
	});
}

/* Nur der aktuelle Link bekommt die Klasse current, nur die direkten Geschwister erhalten die sibling Klasse */
function navStructureStyle() {
	// if ($("li.current.level1").length > 0 && $("li.current.level2").length > 0) {
	// 	$("li.current.level1").removeClass("current");
	// 	$("li.level1").addClass("parent");
	// 	$("li.level1").siblings("li").removeClass("sibling");
	// }
}

// function ie6mainNavHover() {
// 	if ($.browser.msie && $.browser.version == "6.0") {
// 		var mainNavLinks = $("ul#mainNav li");
// 		mainNavLinks.hover(function() {
// 			$(this).find("span").css({
// 				background: "url(/img/knowledge_regions/header/mainNav_current.png) no-repeat 100% 0.5em"
// 			});
// 		}, function() {
// 			$(this).find("span").css({
// 				background: "none"
// 			});
// 		});
// 	}
// }

function mainContentSWFstyle() {
	// if ($.browser.msie && $.browser.version == "6.0") {
		$("div#mainContent object").wrap('<div id="mainContentSWF"></div>');
	// }
}


$(document).ready(function() {
	EWItools.rollover("rollover", "_hover");
	EWItools.resetInputs();
	galleryFocus();
	lightboxInit();
	setNavFirstChild();
	hoverOpacity("supporter");
	highlightSiblings();
	navStructureStyle();
	// ie6mainNavHover();
	mainContentSWFstyle();
});
