/**
 * jquery.config.js
 */

//$.noConflict();

jQuery(document).ready(function($) {

/* sidebar begin */
	
	$('.column_two .single_content_element').addClass('column_two-panel');
	
	$('.column_two .csc-default').each(function() {
		
		//Erste Überschrift suchen
		headLine = $(':header:first', this);
		//console.log('Header found: ', headLine);
		
		//Fehler Behandlung wenn keine Überschrift vorhanden ist
		if(headLine.length == 0) {
			$(this).addClass('column_two-error').removeClass('column_two-panel');
			//console.log('No header found: ', this);
		}
		else {
			
			//kleiner trick um <div class="csc-header"><h1>... abzufangen			
			if(headLine.parent().find('*').length == 1 && !headLine.parent().is('.column_two')) {
				headLine.parent().addClass('column_two-handler');
			}
			else {
				headLine.addClass('column_two-handler');
			}
			
			//Inhalte umschließen für die Ansprache
			$('.column_two-handler', this).siblings().wrapAll('<div class="column_two-content"></div>');
			
			//prüfen ob ein Fehler aufgetreten ist
			if($('.column_two-content .column_two-handler', this).length > 0) {
				//console.log('Handler may not be wrapped by more then one element: ', this);
				$(this).addClass('column_two-error').removeClass('column_two-panel');
			}
		}
	});
	
	
	// hide all
	$('.column_two .column_two-content').hide();
	
	// some css and html
	
	$('.column_two-content').css({
		'padding-top' : '10px',
		'padding-bottom' : '5px'
	});
	
	$('.column_two:last').append('<div style="background:#cac9c9; height:15px; margin:0 -10px;"></div>');
	
	// manipulate search (second-element)
	/*$('.column_two:nth-child(6) .column_two-content').slideDown('normal', function() {
	    // Animation complete.
		//$('h3', '.column_two:nth-child(6)').addClass('header-active');
	});*/
	$('.column_two .column_two-content').hide();
	// manipulate last element
	$('.column_two:last .csc-default div').removeClass('column_two-handler');
	$('.column_two:last .csc-default div').removeClass('column_two-content');
	$('.column_two:last .csc-default .csc-header h3').addClass('header-allways-open');
	$('.column_two:last .csc-default div').show();
	// manipulate first element
	var firstElement = $('.column_two:first .csc-default .csc-header h3');
	if(firstElement.is('.header-allways-open')) {
		firstElement.next().css('display', 'block !important');
		$('.column_two:first .csc-default div').removeClass('column_two-handler');
		$('.column_two:first .csc-default div').removeClass('column_two-content');
		$('.column_two:first .csc-default .csc-header h3').addClass('header-allways-open');
		$('.column_two:first .csc-default div').show();
	}
	
	// events
	$('.column_two .column_two-handler').click(
		
		function() {
			
			var headerElement = $(this);
			var checkElement = $(this).next();
			
			if((checkElement.is('.column_two-content')) && (checkElement.is(':visible'))) {
				$('.column_two-content:visible').slideUp('normal', function() {
				    // Animation complete.
					$('h3.header-active').removeClass('header-active');
				});
				return false;
			}
			if((checkElement.is('.column_two-content')) && (!checkElement.is(':visible'))) {
				
				$('.column_two-content:visible').slideUp('normal', function() {
				    // Animation complete.
					$('h3.header-active').removeClass('header-active');
				});
				
				checkElement.slideDown('normal', function() {
				    // Animation complete.
					$('h3', headerElement).addClass('header-active');
				});
				
				return false;
			}
		}
	);

/* sidebar end */

}); 

