$(document).ready(function() {

	/** ie specialties **/
	if($.browser.msie){
		$('#serviceNavigation').css('zoom', 1);
		$('.col2Content .formBg ul.view').css('zoom', 1);
		$('input[type=checkbox]').css('border', 0);
		$('input[type=checkbox]').css('padding', 0);
	}
		
	/** JobSearch Accordion **/
	if ($('.accordion').length > 0) {
		
		/* fix ie z-index issue for info container */
		$(".accordion li > div").each(function(i){
	  		$(this).css("z-index",10000-i);
		});
		
		var imgOpened = "/images/icon_dot_arrow_down.gif";
		var imgClosed = "/images/icon_dot_arrow_right.gif";

		if($(".accordion > li").length > 1) { //dont close just one item 
			$(".accordion .listContent").hide();
			$(".accordion li").removeClass('selected');
			$(".accordion li img.icon").attr("src", imgClosed);
		}
		
		$(".accordion h4").click(function(){
			var listItem = $(this).parent().parent();
			var imgToSwap = listItem.find("img.icon");
			var imgToSwapName = imgOpened;
			
			if(imgToSwap.attr("src") == imgOpened){
				imgToSwapName = imgClosed;
			}
			
			listItem.toggleClass("selected");
			imgToSwap.attr("src", imgToSwapName);			
			listItem.find(".listContent").toggle();
		});
	}
	
	/**  **/
	if ($('.col2Content .formBg fieldset select.selection').length > 0) {
		
		$(".col2Content .formBg fieldset select.selection").each(function(){
			$(this).parent().before("<label class=\"selection\">Ihre Auswahl: <select class=\"selection\" name=\"pool\" id=\"pool\" size=\"4\" multiple=\"multiple\"></select></label><span class=\"control\"><a href=\"#\" class=\"add\">Hinzuf&uuml;gen</a><a href=\"#\" class=\"remove\">Entfernen</a></span>");
			$(this).parent().parent().find("span.control").children("a").bind("click", selectHandle);
		});
		
	}
	
	
	/** Drop Down Navigation **/
	if ($('#mainnavigation ul.main').length > 0) {
		
		$("#mainnavigation ul.main").superfish({
			hoverClass: 'sfHover',
			animation: {
				opacity: 'show',
				height: 'show'
			}, // fade-in and slide-down animation 
			delay: 500,
			speed: 'normal',
			autoArrows: false, // disable generation of arrow mark-up 
			dropShadows: false // disable drop shadows    
		}).find('ul').bgIframe({
			opacity: false
		});
		
	}
	
	/** JobSearch Accordion **/
	if ($('#searchformView').length > 0) {
		
		var showSearchform = "Suche einblenden";
		var hideSearchform = "Suche ausblenden";
		
		$('#searchform').after('<div class="cf"><a href="#" id="searchform-toggle">'+hideSearchform+'</a></div>');
		
		if( $('#searchformView').val()=='true') {
			$('#searchform').hide();
			$('#searchform-toggle').text(showSearchform);
		}
		
		$("a#searchform-toggle").click(function(){
			
			$('#searchform').toggle();
			
			var hidden = $('#searchformView').val();
			
			if (hidden == 'false') {
				$('#searchformView').val('true');
        $('#hits_hidden').val('true');
				$(this).text(showSearchform);
			} else {
				$('#searchformView').val('false');
        $('#hits_hidden').val('false');
				$(this).text(hideSearchform);
			}
		});

	}
	
	/** Drop Down Sorting **/
	if ($('.paginationcontainer select').length > 0) {

		var evt = $.browser.msie ? 'click' : 'change'; //because of ie change event issues
		
		$('.paginationcontainer select').each(function(){
	
			var selectValue = $(this).val();
			$(this).bind(evt,function(){
				if($(this).val() != selectValue){
					$(this).append("<input type='hidden' name='doSearch' />").parents("form").submit();
				}
	        })
		});

	}
	
	/** Combo Select Fields **/
	if ($('select.comboselect').length > 0) {
		$('select.comboselect').comboselect({
			sort:"both",
			addbtn:"",
			rembtn:""
		});
	}
	

	/** auto focus on first element with special class **/
	if ($('.autoFocusOnLoad').length > 0) {
		$('.autoFocusOnLoad')[0].focus();
	}
	
	if($.browser.msie){
		$('form.applicants tr td:nth-child(5)').hover( 
			function() { $(this).css('position','relative'); },
			function() { $(this).css('position','static'); }
		);
	}

});

function activateAtoZ() {
	if ($('.charIndex-_').length == 0){
		$('.abisz input.ci-_').hide();
	}
	
	charPos_a = "a".charCodeAt(0);
	charPos_z = "z".charCodeAt(0);
	
	for (i=charPos_a; i<=charPos_z; i++ ){
		
		var c = String.fromCharCode(i);
		$('.charIndex-' + c).addClass('charIndex');
		if ($('.charIndex-' + c).length == 0){
			var classSel = '.abisz input.ci-' + c;
			$(classSel).attr('disabled', 'disabled');
		$(classSel).addClass('disabled');
			$(classSel).removeClass('ci-' + c);
		}
	}

	$('.abisz input.ci-all').addClass('current');
	$('.abisz').show();

}

function charIndexShow(ci){
	$('.abisz input').removeClass('current');
	$('.abisz input.ci-' + ci).addClass('current');		
	if ( ci == 'all' ){
		$('.charIndex').show();
		return;
	}    	
	$('.charIndex').hide();
	$('.charIndex-' + ci).show();
}

function selectHandle() {
      if($(this).attr("class") == "add") {
            $(this).parent().parent().parent().find("select:first").children("option").each(function(){
                  if($(this)[0].selected == true) {
                        var $option = $(this);
                        $option.appendTo($(this).parent().parent().parent().find("select:last"));
                  }               
            });
      }
      else if($(this).attr("class") == "remove") {
            $(this).parent().parent().parent().find("select:last").children("option").each(function(){
                  if($(this)[0].selected == true) {
                        var $option = $(this);
                        $option.appendTo($(this).parent().parent().parent().find("select:first"));
                  }               
            });
      }
      return false;
}
