$(document).ready(function() {
	
	$("div.tx-comments-pi1 h3").click(function(){
		$(this).toggleClass("open");
		$("div.tx-comments-pi1 fieldset").slideToggle();
	});

	$("div#login p.loginclose").click(function(){
		$("div#login").slideToggle("slow");
	});
	$("div#topfunc li.loginboxopen").click(function(){
		$("div#login").slideToggle("slow");
	});
	
	
	$("div.startpage #banner div.csc-textpic").mouseover(function(){
		$(this).find("div.csc-textpic-imagerow:first").hide();
		$(this).find("div.csc-textpic-imagerow:last").show();
	});
	$("div.startpage #banner div.csc-textpic").mouseout(function(){
		$(this).find("div.csc-textpic-imagerow").show();
		$(this).find("div.csc-textpic-imagerow-last").hide();
	});

	$("div.startpage #banner div.csc-textpic div.csc-textpic-imagewrap").click(function(){
		$(this).parent().find("div.csc-textpic-text").toggle();
		$(this).parent().find("div.csc-textpic-imagerow").toggleClass("csc-textpic-imagerow-last");
	});

	$("p.ein_aus").click(function(){
		$(this).toggleClass("open");
	});

	$("div.mm-forum-list h1").click(function(){
		$(this).parent().find("dl").slideToggle("fast");
		$(this).toggleClass("act");
	});
	// captions for branches on start page
	$(".third-sec .other .textpicwrap").live("mouseover",function(){
		$(this).find('.csc-header').stop(false,true).animate({top:52},{duration:400, easing: 'easeOutQuart'});
	});
	$(".third-sec .other .textpicwrap").live("mouseleave",function(){
		$(this).find('.csc-header').stop(false,true).animate({top:100},{duration:400, easing: 'easeOutQuart'});
	});
	// change pics & text of branches on start page
	$(".third-sec .other .textpicwrap").live("click",function(){
		$(this).clone().replaceAll(".third-sec .first .textpicwrap");
		$(".third-sec .other .textpicwrap").find(".csc-textpic-imagewrap").removeClass("act");
		$(this).find(".csc-textpic-imagewrap").addClass("act");
	});
	// toggle helpdesk on startpage
	$(".helpdesk-bt").click(function(){
		$("#helpdesk").fadeIn("slow");
		h = $("#all").height();
		$("#fader").height(h);
		$("#fader").fadeIn("slow");
	});
	$("#fader").click(function(){
		$("#helpdesk").fadeOut();
		$("#fader").fadeOut();
	});
	$("#helpdesk-close").click(function(){
		$("#helpdesk").fadeOut();
		$("#fader").fadeOut();
	});
	/* 
		margin-bug in opera
	*/
	if ($.browser.opera) {
		$("#maincontent").css("margin-left","20px");
		$("#banner").css("margin-left","20px");
		$(".startpage #bodywrapper").css("margin-left","20px");
	}
	/* 
		margin-bug in Firefox; dedects Gecko 1.8 = Firefox 1.5 & 2
	*/
	jQuery.each(jQuery.browser, function(i, val) {
	  if(i=="mozilla" && jQuery.browser.version.substr(0,3)=="1.8") {
		$("#maincontent").css("margin-left","20px");
		$("#banner").css("margin-left","20px");
		$(".startpage #bodywrapper").css("margin-left","20px");
	}
	});
});




/* -----------------------------------
   rotating home page items
   ----------------------------------- */
var image_count;
var current_image=0;

$(document).ready(function(){
  image_count = $("div#slideshow div.csc-textpic").hide().size();
  $("div#slideshow  div.csc-textpic:eq("+current_image+")").show();
  setInterval(feature_rotate,4500); //time in milliseconds

});


function feature_rotate() {
  old_image = current_image%image_count;
  new_image = ++current_image%image_count;
  $("div#slideshow div.csc-textpic:eq(" + new_image + ")").fadeIn("slow", function() {
    $("div#slideshow div.csc-textpic:eq(" + old_image + ")").fadeOut("slow");
  });
}
