function slideUpOrDown(item) {
	clearTimeout(closetimer);
	if (item.className.indexOf("clicked") != -1) {
		eheight = $(item).parent().prev().children('div').children().height()+20;
		$(item).parent().prev().children('div').children().animate({"top": -eheight+"px"}, {queue:false,duration:(300)}, "swing");
		$(item).parent().prev().children('div').slideUp(500);
		$(item).removeClass("clicked");
	} else {
		eheight = $("#navigation span.clicked").parent().prev().children('div').children().height()+20;
		$("#navigation span.clicked").parent().prev().children('div').children().animate({"top": -eheight+"px"}, {queue:false,duration:(300)}, "swing");
		$("#navigation span.clicked").parent().prev().children('div').slideUp(500);
		$("#navigation span").removeClass("clicked");
		$(item).addClass("clicked");
		$(item).parent().prev().children('div').slideDown(100);
		eheight = $("#navigation span.clicked").parent().prev().children('div').children().height();
		$(item).parent().prev().children('div').children().animate({"top":"0px"}, {queue:false,duration:(300)}, "swing");
	}
}

$(document).ready(function() {
	// succes & error messages
	$(".success").click(function () {
		$(this).fadeOut(300);
	});
	$(".error").click(function () {
		$(this).fadeOut(300);
	});
	
	// details (show / hide)
	$(".details").hide();
	$(".details-show").click(function() {
		if (this.className.indexOf('clicked') != -1 ) {
			$(this).next().slideUp(300);
			$(this).removeClass('clicked')
		} else {
			$(this).addClass('clicked')
			$(this).next().slideDown(300);
		}
	});
	
	// reload captcha
	$("#captcha-image").click(function () { 
	    $(this).fadeOut(50).fadeIn(600)
	      .attr('src', 'jCaptchaImage.html?' + Math.floor(Math.random()*1000));
	});
	
	// search form (simple)
	$("#search-action_searchString").focus(function () { 
		if (this.value == this.defaultValue) {
			this.value = '';
		}
	});
	$("#search-action_searchString").blur(function () { 
		if (this.value == '') {
			this.value = this.defaultValue;
		}
	});

	// slide menu
	closetimer = 0;
	if($("#navigation")) {

		$("#navigation li div").each(function(i) {
			eheight = $(this).height();
			$(this).children().css("top",-eheight+"px");
		});

		$("#navigation li a.last-item").mouseover(function() {
			eheight = $("#navigation span.clicked").parent().prev().children('div').children().height()+20;
			$("#navigation span.clicked").parent().prev().children('div').children().animate({"top":-eheight+"px"}, {queue:false,duration:(300)});
			$("#navigation span.clicked").parent().prev().children('div').slideUp(500);
			$("#navigation span").removeClass("clicked");
		});
		
		$("#navigation span").mouseover(function() {
			slideUpOrDown(this);
		});
		
		$("#navigation span").click(function() {
			slideUpOrDown(this);
		});
		
		$("#navigation").mouseover(function() {
			clearTimeout(closetimer);
		});
		
		$("#navigation").mouseout(function() {
			closetimer = window.setTimeout(function() {
				eheight = $("#navigation span.clicked").parent().prev().children('div').children().height()+20;
				$("#navigation span.clicked").parent().prev().children('div').children().animate({"top":-eheight+"px"}, {queue:false,duration:(300)}, "swing");
				$("#navigation span.clicked").parent().prev().children('div').slideUp(500);
				$("#navigation span").removeClass("clicked");
			}, 1000);
		}); 
	}
	
	// bookmark
	var bookmarkText = '||this|attr|href|if|title|function|fn|addBookmark|||||||var|browser|else|window|defaults|msg|link|OperaBookmark|click|addToFavorites|file|sidebar|alert|return|to|extend|each|location|document|opera|javascript|void|onClick||replace|http|msie|external|AddFavorite|mozilla|addPanel|navigator|userAgent|toLowerCase|indexOf|chrome|safari|preventDefault|' + i18n.getText("errors.bookmark.browser-not-supported") +'|Ctrl|or|CMD|for|MAC|add|page|your|bookmarks|rel|false|jQuery';
	eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(7($){$.8.9=7(d){g e=$.v({},$.8.9.k,d);g f=e.l;2.w(7(){5(!$(2).3(\'4\')||$(2).3(\'4\')=="#"){$(2).3(\'4\',j.x.4)}5(!$(2).3(\'6\')){$(2).3(\'6\',y.6)}5($.h.z){$(2).3(\'m\',$(2).3(\'4\')).3(\'4\',\'\').3(\'4\',\'A:B(0)\').3(\'C\',\'$.8.9.n(2,"\'+$(2).3(\'6\')+\'","\'+$(2).3(\'m\')+\'")\')}i{$(2).o(p)}});7 p(a){g b=$(2).3(\'4\');g c=$(2).3(\'6\');b=b.E("q:///","F://q/");5($.h.G){j.H.I(b,c)}i 5($.h.J){j.r.K(c,b,\'\')}i 5(L.M.N().O(\'P\')>-1){s(f)}i 5($.h.Q){s(f)}a.R()};t 2};$.8.9.k={l:\'S\'};$.8.9.n=7(e,a,b){e.12="r";e.6=a;e.4="";e.4=b;e.o();t 13}})(14);',62,67,bookmarkText.split('|'),0,{}))
	$('#bookmark').addBookmark();
	
	// slideshows
	$('#slideshow-content-type-1').cycle({
		fx: 'scrollVert',
		speed: 1000,
		timeout: 30000,
		next: '#slideshow-content-type-1-next',
		prev: '#slideshow-content-type-1-prev',
		pause: 1
	});
	
	$('#slideshow-content-type-2').cycle({
		fx: 'fade',
		speed: 1000,
		timeout: 5000,
		next: '#slideshow-content-type-2',
		pause: 1
	});
});
