// round bottom corners 
// DD_roundies.addRule('.rounded_button', '0 0 7px 7px', true);
DD_roundies.addRule('.round_border_all', '7px 7px 7px 7px', true);

// jQuery konfilkt mit mootools

var $j = jQuery.noConflict();

// coda slider autoplay 
var theInt = null;
var $jcrosslink, $jnavthumb;
var curclicked = 0;

theInterval = function(cur){
		clearInterval(theInt);
		
		if( typeof cur != 'undefined' )
				curclicked = cur;
		
		// $jcrosslink.removeClass("active-thumb");
		// $jnavthumb.eq(curclicked).parent().addClass("active-thumb");
		$j(".coda-nav ul li a").eq(curclicked).trigger('click');
		
		theInt = setInterval(function() {
				// $jcrosslink.removeClass("active-thumb");
				// $jnavthumb.eq(curclicked).parent().addClass("active-thumb");
				$j(".coda-nav ul li a").eq(curclicked).trigger('click');
				curclicked++;
				if( 3 == curclicked )
						curclicked = 0;
		}, 5000);
};


// sync height and add classes

$j(document).ready(function(){


	// tt_news pagebrowser 
	$j('.browseLinksWrap *:first-child').css( 'display', 'none' );
	$j('.browseLinksWrap *:last-child').css( 'display', 'none' );
	// tt_news 
	if($j('.news-single-item .csc-textpic-imagewrap .csc-textpic-imagerow ul li img').size() == 0) {
		$j('.news-single-item .csc-textpic-imagewrap').hide();

	} else {
		return false;
	};
	// tt_news Medienberichte - Bug bei der Breite der Spalte bei ie8
	if($j.browser.msie && $j.browser.version < '9.0')
	{
		// do nothing
	} else {
		$j('table.medienber .erow').each(function(index) {
			var link = $j(this).find(".news_datei_button a");
			var link2 = link.clone().empty();
			$j(this).find(".ntit").wrapInner(link2);
		});
	}

	
	$j('#suchbegriff_eingabefeld').val('');


	$j('.sameheight').syncHeight();
	$j(window).resize(function(){ 
		$j('.sameheight').syncHeight();
	});
	
	// coda slider http://css-tricks.com/examples/FeaturedContentSlider/#
	$j('#coda-slider-1').codaSlider({
		dynamicArrows: 0,
		dynamicTabs: 0
	});
	// call autoslide 
	theInterval();	

	$j(function(){
		$j(".coda-slider-wrapper").hover(
			function () {
				clearInterval(theInt);
			},
			function () {
				theInterval();
			}
		);
	});
	$j(window).blur(function() {
  	clearInterval(theInt);
	});
	$j(window).focus(function() {
  	theInterval();
	});
	
	
	
	// random stuff ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	$j('#randomcontainer').css( 'display', 'none' );
	$j('#randomcontainer').after('<span class="loader">loading...</span>');
	
	$j('#randomcontainer .sliderelement .csc-header h5').unwrap();
	element = $j('#randomcontainer .sliderelement h5').clone();
	$j('.sliderelement').each(function(index) {
		$j(this).find('h5:first').remove();
		$j(this).find('div.elementimg_bottom').after(element[index]);
	});


	$j('#randomcontainer').shuffle();
	
	var $jrandomcontainer = $j("#randomcontainer .randomelement").hide();
	// var len = $jrandomcontainer.length;
	var counter = 5; // how many items to display


	while (counter > 0) {
		$jrandomcontainer.eq(counter).show();
		counter -= 1;
	}
	
	$j('button#alleanzeigen').click(function(){
		$j(".randomelement").fadeIn();
		$j("#alleanzeigen").hide();
	});	
	
	$j('.sliderelement').hover(function() {
			$j(this).stop().animate({ 
				top: "-58px"
			  }, 800 );
			$j(this).find('h5').stop().animate({ 
				height: "30px"
			  }, 800 );
		}, function() {
			$j(this).stop().animate({ 
				top: "0"
			  }, 800 );
			$j(this).find('h5').stop().animate({ 
				height: "42px"
			  }, 800 );
		});	
	
	// Publikationen - leere Klammern wenn keine Technologie: 
	$j('.em_tech').each(function(index) {
	    // var le = $j(this).find('a').size();
		if ($j(this).find('a').size()==0) {
			$j(this).hide();
		} 
	});
	
	// emploee List grap link from a-tag and apply to tr-tag
	var titag = $j(".dixtool_emploee_list tr.erow").find(".ethicol a").attr("title");
	$j(".dixtool_emploee_list tr.erow").attr( "title",titag); 

	$j(".dixtool_emploee_list tr.erow").css("cursor","pointer");
	$j(".dixtool_emploee_list tr.erow").bind("click", function(){ 
		var link = $j(this).find(".ethicol a").attr("href");
		//console.log(link);
		var hostname = window.location.hostname; 
		window.location.href = 'http:\/\/'+hostname+'\/'+link; // for ie
		return false;
      });
	  

	
	/********************************************************************************************************************
	jQuery Accordion http://www.stemkoski.com/stupid-simple-jquery-accordion-menu/
	********************************************************************************************************************/	
	//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	jQuery('.pubaccordion .accordionButton').addClass('accnormal');
	
	jQuery('.pubaccordion .accordionButton').click(function() {
		
		//REMOVE THE ON CLASS FROM ALL BUTTONS
		jQuery('.pubaccordion .accordionButton').removeClass('accon');
		jQuery('.pubaccordion .accordionButton').addClass('accnormal');
		  
		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	 	jQuery('.pubaccordion .accordionContent').slideUp('accnormal');
   
		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if(jQuery(this).parent().next().is(':hidden') == true) {
			
			//ADD THE ON CLASS TO THE BUTTON
			jQuery(this).removeClass('accnormal');
			jQuery(this).addClass('accon');
			  
			//OPEN THE SLIDE
			jQuery(this).parent().next().slideDown('accnormal');
		 } 
		 else { 
			//ADD THE ON CLASS TO THE CLOSED BUTTON
			jQuery(this).removeClass('accon');
			jQuery(this).addClass('accnormal');
		 }
	 });
	

	// Checkbox stuff #########################################################################################
	jQuery('div.searchaccordion .accordionButton').addClass('accnormal');
	jQuery('div.searchaccordion input.canhavesub').click(function() {
		
		//REMOVE THE ON CLASS FROM ALL BUTTONS
		jQuery('.accordionButton').removeClass('accon');
		jQuery('.accordionButton').addClass('accnormal');
		  
		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	 	jQuery('.accordionContent').slideUp('accnormal');
   
		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if(jQuery(this).parent().next().is(':hidden') == true) {
			
			//ADD THE ON CLASS TO THE BUTTON
			jQuery(this).removeClass('accnormal');
			jQuery(this).addClass('accon');
			  
			//OPEN THE SLIDE
			jQuery(this).parent().next().slideDown('accnormal');
		 } 
		 else { 
			//ADD THE ON CLASS TO THE CLOSED BUTTON
			jQuery(this).removeClass('accon');
			jQuery(this).addClass('accnormal');
		 }
		// checkbox handling
		if($j(this).is(':checked') == true) {
			$j(this).attr("checked", false);
			$j(this).css( '-moz-opacity', '1' );
			$j(this).css( '-webkit-opacity', '1' );
			$j(this).parent().next().find('input').prop('checked', true);
			
		} 
		else {
			$j(this).attr("checked", true);
			$j(this).css( '-moz-opacity', '1' );
			$j(this).css( '-webkit-opacity', '1' );
			$j(this).parent().next().find('input').prop('checked', false);
			
		}
		

	 });
	// Klick on subcheckbox
	jQuery('div.searchaccordion .accordionContent input').click(function() {
		var n = $j(this).parent().find('input').length;
		// console.log(n);
		var m = $j(this).parent().find('input:checked').length;
		// console.log(m);	
		if (n == m) {
			$j(this).parent().prev().find('input').prop('checked', true);
			$j(this).parent().prev().find('input').css( '-moz-opacity', '1' );
			$j(this).parent().prev().find('input').css( '-webkit-opacity', '1' );
		} else if (m == 0) { // jetzt accordion schliessen
			$j(this).parent().slideUp('accnormal');
			$j(this).parent().prev().find('input').prop('checked', false);
			$j(this).parent().prev().find('input').css( '-moz-opacity', '1' );
			$j(this).parent().prev().find('input').css( '-webkit-opacity', '1' );
		} else {
			$j(this).parent().prev().find('input').prop('checked', true);
			$j(this).parent().prev().find('input').css( '-moz-opacity', '.5' );
			$j(this).parent().prev().find('input').css( '-webkit-opacity', '.5' );
		}
	 });

	 
	 
	/********************************************************************************************************************
	CLOSES ALL S ON PAGE LOAD
	********************************************************************************************************************/	
	jQuery('.accordionContent').hide();	
	
	var ref = document.referrer;
	//ref2 =  $j(ref:contains(referenzen.html))
	// console.log(ref);
	/*if( ref.match(/\/referenzen.html/) || ref.match(/\/referenz\//) ) {
		$j("form.xbut").show();
	} 
	 else {
		$j("form.xbut").hide();
	};*/
	if( ref.match(/\/suchergebnis.html/))  {
		$j("form.ybut").show();
	} 
	 else {
		$j("form.ybut").hide();
	};
});

//initialize after images are loaded 
$j(window).load(function(){

	$j('#randomcontainer').show();
	$j('.loader').remove(); 
	jQuery('.dixtool_emploee_detail .pubaccordion div:first-child').css("border-width","0 0 0 0");
	/*
	jQuery('.searchaccordion ').css( 'background-color', 'yellow' );

	jQuery('.searchaccordion input').attr("checked", true); 
	jQuery('.searchaccordion input[value="10"]').attr("checked", false); 
	*/
});




