$(document).ready(function() {
	/* Dropdown-Navigation */
	var nav = new DickerFisch('#navigation', {
		NavTimeout: 100
	});
	
	/* Die secondlevelnavi ist nur bei ausgeschaltetem Javascript sichtbar */
	$(".secondlevelNavi").hide();
	$(".secondlevelNaviSpace").hide();
	$(".breadcrumbs ul").css("top","99px");
	
	/* Themen-Blätter-Navigation */
	$(".thema_1 .boxBrowser").css("display","block");
	$(".thema_1 .prev").fadeTo(0,0.33);	
	var i = 0;
	
	$(".boxBrowser .next").click(function () { 		
		var items = $(this).parent().children("span").length;
		var themeClass = $(this).parent().parent().attr("class");
		if (i < items) {
			i+=1;
		}
		$(".thema_1 .prev").fadeTo(0,1.0); 
		if(themeClass != "thema_" + (items)) {
			$(".thema_"+i).hide();
		}
		$(".thema_"+(i+1)).show();
		$(".boxBrowser").show();
		if(themeClass == "thema_" + (items-1)) {
			$(".thema_4").show();
			$(".thema_4 .next").fadeTo(0,0.33);
			//i = items;			
		}
		if(themeClass == "thema_" + (items)) {
			i = items-1;			
		}	
		return false;
    });
	
	$(".boxBrowser .prev").click(function () {
		var items = $(this).parent().children("span").length;
		var themeClass = $(this).parent().parent().attr("class");
		$(".thema_1 .prev").fadeTo(0,0.33);		
		if(themeClass != "thema_1") {				
			$(".thema_" + (i+1)).hide();
			$(".thema_" + (i)).show();
			i-=1;
		}		
		return false;	
    });
	
	/* optische Korrektur an Tabnavi */
	$("li.tabs-selected").prev().children().children("a").css("background-image","none");
	$(".tabNavi li a").hover(
      function () {
	    $(this).parent().parent().prev().children().children("a").css("background-image","none");
		$(this).css("background-image","url(/images/shadow_tabs.gif)");
      }, 
      function () {
        $(this).parent().parent().prev().children().children("a").css("background-image","url(/images/bg_tabs.gif)");
		$(this).parent().parent().prev().children().children("li.tabs-selected a").css("background-image","url(/images/shadow_tabs.gif)");
		$(this).css("background-image","url(/images/bg_tabs.gif)");
		$("li.tabs-selected").prev().children().children("a").css("background-image","none");
      }
    );
	
	/* Mouseover-Verhalten der 2nd-Level-Navi (Drop-Down-Menupunkte */
	$("#navigation ul li ul.dropdownMenu li").hover(
      function () {
	    $(this).css({'background-color' : '#35689c'});
		$(this).children('a').css({'color' : '#fff'});
      }, 
      function () {
        $(this).css({'background-color' : 'transparent'});
		$(this).children('a').css({'color' : '#022A51'});
      }
    );
	
	/* Fokus-Verhalten der 2nd-Level-Navi (Drop-Down-Menupunkte */
	$("#navigation ul li ul.dropdownMenu li a").focus(
      function () {
	    $(this).parent('li').css({'background-color' : '#35689c'});
		$(this).css({'color' : '#fff'});
      }
    );
	
	/* Blur-Verhalten der 2nd-Level-Navi (Drop-Down-Menupunkte */
	$("#navigation ul li ul.dropdownMenu li a").blur(
      function () {
        $(this).parent('li').css({'background-color' : 'transparent'});
		$(this).css({'color' : '#022A51'});
      }
    );
	
	/**Start Tab Navigation */
	if($('.netzwerk .left .tabContainer').is("div")) {
		$('.tabContainer').tabs(0);		
	}

	/**Function for carousel initialisation**/	
	/****************************************/

	/**Member Array**/
	var mycarousel_itemList = new Array();
		
	for(i=0;i<$('#newmemberscarousel li').length; i++) {
		mycarousel_itemList[i] = ($($('#newmemberscarousel li')[i]).html());
	}


	function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {
	
	    // The index() method calculates the index from a
	    // given index who is out of the actual item range.
	
	    var idx = carousel.index(i, mycarousel_itemList.length);
	    carousel.add(i, mycarousel_itemList[idx-1]);
	};

	function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
		//reset i - otherwise IE and Opera will decimate the items list
		i = $('#newmemberscarousel li').length;
	    carousel.remove(i);
	};
	/**Start Member Carousel**/
	if($('#newmemberscarousel').is("ul")) {
		$('#newmemberscarousel').jcarousel({
			scroll: 1,
			wrap: 'circular',
			itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
			itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}

		});
	}
	
	$("#marginal .containerSearch .textInput").focus(function () {
         $(this).attr("value","");
    });
	
	if($.browser.msie && $.browser.version == "6.0"){
	   $(".dropdownMenu").bgIframe();
	}

	/**Hide Submit for manual Tag Selection*/
	if ($('.JStrigger').is("div")) {
		$('.JStrigger').removeClass("JStrigger");
	}
		
	if ($('.JStriggerOff').is("div")) {
		$('.JStriggerOff').addClass("JStrigger");
	}
	
	/**Init Checkbox Window im FavoriteBox */
	if($('a.dialogTriggerBox').is("a")) {
		$.fn.createDialog.defaults = {
			progress: true,
			center: true,
			opacity: 0.7,
			bg: '#000'
		}
		$(".dialogTriggerBox").createDialog({
			addr: '/community/tags.html',
			bg: '#000'
		});
	}
	
	/**Init News Window */
	if($('a.dialogNews').is("a")) {
			
		$.fn.createDialog.defaults = {
			progress: true,
			center: true,
			opacity: 0.7,
			bg: '#000',
			alwaysLoad: true
		}
		
		news = $('a.dialogNews');
		for(i=0;i<$(news).length;i++) {
		    // Starts with new_?
			if (news[i].id.match('^news_')) {
				$(news[i]).createDialog( {
					addr: '/new.html?id='+news[i].id.substring(5),
					bg: '#000'
				});
			}
		}
	}
	
	/**Init Edir User Rights Window*/
	if($('a.editUserRightsDialogTrigger').is("a")) {
		$.fn.createDialog.defaults = {
			progress: true,
			center: true,
			opacity: 0.7,
			bg: '#000',
			alwaysLoad: true,
			index:1000
		}
		
		users = $('a.editUserRightsDialogTrigger');
		for(i=0;i<$(users).length;i++) {
			$(users[i]).createDialog({
			addr: users[i].id,
			bg: '#000'
		});
		}
	}
	
	/** Join as Expert Formular ein- und ausblenden */
	if ($('#joinAsExpert').is("div")) {
		if ($('#joinAsExpertCB').is(':checked')) {
			$('#joinAsExpert').show();
		} else {
			$('#joinAsExpert').hide();
		}

		$('#joinAsExpertCB').click(function() {
			$('#joinAsExpert').toggle();
		});
	}

	/** Other organisation ein- und ausblenden */
	if ($('#organisationNew').is("input")) {
		showHideOtherOrganisation($('#organisation'));
		$('#organisation').change(function() { showHideOtherOrganisation($('#organisation'));});
	}
	
	/** Other organisation ein- und ausblenden */
	if ($('#topicsContainer').is("div")) {
		showHideTopicsContainer($('#mustSelectTopicsCB'));
		if($.browser.msie){
			$('#mustSelectTopicsCB').bind("change click",function() {showHideTopicsContainer($('#mustSelectTopicsCB'))});
		} else {
			$('#mustSelectTopicsCB').change(function() { showHideTopicsContainer($('#mustSelectTopicsCB'));});
		}
	}
	
	/**Datepicker**/
	if($('.inputDateFrom').is("input")){
		$(".inputDateFrom, .inputDateTo").datepicker({ 
   			showOn: "both", 
    		buttonImage: "/images/calendar.gif", 
    		buttonImageOnly: true 
		});
	}
	
	/** Textbox watermark **/
	waterMarkValues=[];
	$("input.watermark").each(
            function(i){
            	waterMarkValues[i]=$(this).attr("title");
            	if($.trim($(this).val())=="") {
            		// Password Felder speziell behandeln
            		if ($(this).attr("type") == "password") {
                		$(this).hide();
                		$(this).after($('<input id="waterTextTmp'+i+'" type="text" />').attr("class",$(this).attr("class")).attr("title",$(this).attr("title")));
                		$("#waterTextTmp"+i).val(waterMarkValues[i]);
                		$("#waterTextTmp"+i).focus(function() {
                			if($(this).val()==waterMarkValues[i])
                            {
                                $(this).hide();
                                $(this).siblings("input[type=password]").show().focus();
                            }
                		});
                	} else {
                		$(this).val(waterMarkValues[i]);
                	}
            	}
                $(this).focus(function()
                    {
                        if($(this).val()==waterMarkValues[i])
                        {
                            $(this).val("");
                            $(this).removeClass("watermark");
                        }
                    }
                ).blur(function()
                    {
                        if($.trim($(this).val())=="")
                            {
	                        	if ($(this).attr("type") == "password") {
	                            	$(this).hide();
	                            	$(this).siblings("#waterTextTmp"+i).show();
	                            } else {
	                            	$(this).val(waterMarkValues[i]);
	                                $(this).addClass("watermark");
	                            }
                            }
                     }
                 );
            }
      );
      
      /**Start Link Carousel**/
                $('#linkcarouselpublicationDate').jcarousel({
            		vertical: true,
                    scroll: 1
    });

	
});

function showHideOtherOrganisation(organisation) {
	if($(organisation).val() == "other") {
		$('#otherorganisationlabel').show();
		$('#organisationNew').show();		
	} else {
		$('#otherorganisationlabel').hide();
		$('#organisationNew').hide();				
	}	
}

function showHideTopicsContainer(mustSelectTopicsCB) {
	if($(mustSelectTopicsCB).is(':checked')) {
		$('#topicsContainer').show();
	} else {
		$('#topicsContainer').hide();
	}	
}





