var navi_ = {
	speed: 200,
	off: 0, 
	offTime: 200,
	
	init: function() {
		$("#navigation dt").mouseover(function(e) { navi.showmain(this); });
		$("#navigation dt:first").css("border", 0);
		$(".subnavigation dl").
			mouseover(function(e) { 
				clearTimeout(navi.off);
				navi.showsub(this) 
			}).
			mouseout(function(e) {
				navi.off = setTimeout(function() {
					navi.hidesub(this); 
				}, navi.offTime);
			});
	},
	showmain: function(dt) {
		var dd = $("+dd", dt);
		dd.slideDown(navi.speed);
		$("#navigation dd").each(function(t) {
			if(this != dd.get(0))
				$(this).slideUp(navi.speed);
		});
	},
	showsub: function(dl) {
		$(".subnavigation dl[@class='curr']").removeClass("curr").attr("curr", 1);
		$(".subnavigation dl").removeClass("over");
		$(dl).addClass("over");
	},
	hidesub: function(dl) {
		$(".subnavigation dl[@curr='1']").addClass("curr");
		$(".subnavigation dl").removeClass("over");
	}
}

var navi = {
	init: function() {
		$("#navigation dt:first").css("border", 0);
		
		$("#navigation dd p").mouseover(function(e) { 
			$(this).addClass("hover");
			$(this).stop().animate({paddingLeft:"1ex" }, 100)
		});
		$("#navigation dd p").mouseout(function(e) { 
			$(this).removeClass("hover");
			$(this).stop().animate({paddingLeft:"0.3ex"}, 100)
		});
	}
}	

var tools = 
{
	searchText: 'Search...',

	font: function(d) {
		if(!tools.fontSize)
			tools.fontSize = 12;
		if(d == 0)
			tools.fontSize = 12;
		else if(tools.fontSize + d > 9)
			tools.fontSize += d;
		$("body").css("fontSize", tools.fontSize);
	},
	print: function() {
		window.open(location.href + "?view=print");
	},
	textOnly: function() {
		location.search = "view=text";
	},
	init: function() {
		var s = $("#search_form input[type=text]");
		if(s.val() == '') 
			s.val(tools.searchText);
		s.focus(function() { if(this.value == tools.searchText) this.value = '';	});
	}
}

var productList = 
{
	speed:100,

	init: function() {
		$(".prod_details_link").click(function(e) {
			var det = $(this).next(".prod_details");
			var vis = det.css("display");
			$(".prod_details").hide();
			$(".prod_details_link").removeClass("prod_details_link_active");
			if(vis != "block") {
				det.slideDown(productList.speed);
				$(this).addClass("prod_details_link_active");
			}
		})
	}
}

var jobList = 
{
	speed:100,

	init: function() {
		$(".job_item > h3").click(function(e) {
			var div = $("div.job_details", $(this).parent());
			var vis = div.css("display");
			$(".job_item > div").hide();
			//window.scrollTo(0, div.offset().top);
			if(vis != "block") 
				div.slideDown(jobList.speed);
		})
	},
	
	openForm: function(link) {
		var title = $.trim($(link).parents(".job_item").find("h3:first").text());
		$(link).parent().append($("#job_form_box"));
		$("#job_form_box").show();
		$(link).hide();
		$("#f_job_title").val(title);
		$("#job_form_box form :button").click(function() { 
			$("#job_form_box").hide(); 
			$(link).show();
		});
	}
}

var selectbox = 
{
	init: function(obj) {
		if(obj) obj.click(function(e) {
			var div = $("div", this);
			if(div.css("display") == "none")
				div.css("display", "block");
			else
				div.css("display", "none");
		})
	}
}





$(function() {

	if(location.search && location.search.match(/\bprint\b/)) {
		$("#maincss").attr("href", "/fileadmin/css/print.css");
		return;
	}

	navi.init();

	selectbox.init($("#langmenu"));
	selectbox.init($("#jobs_countries"));
		
	$('img').each(function(n, img) {
		if(img.src.match(/_a\./)) {
			$(img).mouseover(function() { this.src = this.src.replace(/_a\./, "_z.") })
			$(img).mouseout(function() { this.src = this.src.replace(/_z\./, "_a.") })
		}
	});
	
	var replaceHead = (flh.flashVersion() > 8) && 
		($.browser.mozilla || ($.browser.msie && parseFloat($.browser.version) >= 7));
	
	if(replaceHead) {
		var h = flh.replaceHTML($("#bigtitle").get(0), "/fileadmin/flh.swf", "#ffffff", $("#bigtitle").css('backgroundColor'), 0);
		if(h) {
			var b = $("#bigtitle");
			b.html("<div>" + b.html() + "</div>");
			$("div", b).fadeOut(function() { b.html(h); });
		}
	}
	productList.init();
	jobList.init();
	tools.init();
	
	Forma.stdSubmit = function() {
		var ok = Forma.validate(this);
		if(!ok) {
			window.scrollTo(0, 0);
			$("#form_error").show();
		}
		return ok;
	}
	
});
