// coma part
jQuery(document).ready(function(){jQuery.gehrlicher.init();});

// Kontrollvariable für die Header-Slideshow
var slide = true;

// Kontrollvariable für die Header-Slideshow
var teaserslide = true;

// Hauptklasse
jQuery.gehrlicher = new Object;
jQuery.gehrlicher = {
	// Initialisation
	init: function() {
		this.header();
		this.teaser();
        this.headlines();
		this.beautyful();
	},
	
	beautyful: function() {
		
	
	},
	
	// Initialisiert die Header-Slideshow
	header: function() {
		var amount = 0;
		var pic_navi = '';
		jQuery('#header_flash img').each(function(i) {
			jQuery(this).hide();
			if(i == 0) jQuery(this).show().addClass('active');
			amount++;
		});
		if(amount > 1){
			pic_navi = '<ul>';
			for(c = 0; c < amount; c++) {
				if(c == 0) {
					pic_navi += '<li class="active"><a href="javascript:;" rel="'+c+'"></a></li>'
				}
				else
				{
					pic_navi += '<li><a href="javascript:;" rel="'+c+'"></a></li>'
				}
			}
			pic_navi += '</ul>';
			jQuery('#pic_navi').html(pic_navi);
			this.header_stop_by_click();
			setTimeout(function(){jQuery.gehrlicher.header_slide();}, 6000);
		}
		else
		{
			jQuery('#pic_navi').html(pic_navi);
		}
		
		
		
	},
	// Führt die Slideshow durch
	header_slide: function() {
		if(slide) {
			if(jQuery('#header_flash img:last-child').hasClass('active')){
				var last = jQuery('#header_flash img:last-child');
				var last_nav = jQuery('#pic_navi ul li:last-child');
				
				last
				.removeClass('active')
				.css('z-index', '0');
				
				jQuery('#header_flash img:first-child')
				.addClass('active')
				.css('z-index', '20')
				.fadeIn(function(){
					last.hide();
				});
				
				jQuery('#pic_navi ul li:first-child').addClass('active');
				
				
				
				last_nav
				.removeClass('active');
			}
			else
			{
				jQuery('#header_flash img.active')
				.removeClass('active')
				.css('z-index', '0')
				.next()
				.addClass('active')
				.css('z-index', '20')
				.fadeIn( function() {
					jQuery(this).prev().hide();
				});
				
				jQuery('#pic_navi ul li.active')
				.removeClass('active')
				.next()
				.addClass('active');
			}
			// führt die Wiederholung durch
			setTimeout(function(){jQuery.gehrlicher.header_slide();}, 6000);
		}
	},
	// Stopt die Slideshow, wenn auf ein Navigationspunkt geklickt wird.
	header_stop_by_click: function() {
	
		jQuery('#pic_navi ul li').click( function() {
			slide = false;
			element = jQuery(this);
			var index = jQuery('#pic_navi ul li').index(element);

			jQuery('#pic_navi ul li').removeClass('active');
			
			jQuery(this).addClass('active');
			
			jQuery('#header_flash img')
			.removeClass('active')
			.stop(true, true)
			.hide()
			.css('z-index','0');
			
			jQuery('#header_flash img:eq('+index+')')
			.addClass('active')
			.stop(true, true)
			.show()
			.css('z-index','20');
			
			//startet Slide nach 10000 ms
			
			
		});
	},
	
	// Teaser Slideshow
	teaser: function () {
		jQuery('#page-5 .csc-textpic-imagerow-last')
		.parent()
		.css('overflow', 'hidden')
		.append('<a class="teaser-prev" href="#"></a><a class="teaser-next" href="#"></a>');
		
		jQuery('#page-5 .csc-textpic-imagewrap').stop().hover( function () {
			jQuery(this)
			.find('.teaser-next')
			.stop(true, true)
			.animate({right: '9px'});
			
			jQuery(this)
			.find('.teaser-prev')
			.stop(true, true)
			.animate({left: '0px'});
		}, function () {
			jQuery(this)
			.find('.teaser-next')
			.stop(true, true)
			.animate({right: '-9px'});
			
			jQuery(this)
			.find('.teaser-prev')
			.stop(true, true)
			.animate({left: '-18px'});
		});
		jQuery('#page-5 .csc-textpic-imagerow .csc-textpic-caption').addClass('basic-caption');
		
		jQuery('.basic-caption').parent().parent().parent().parent().parent().find('.csc-header').hide();
		jQuery('.csc-textpic-imagerow').each( function (i) {
			jQuery(this).css('left', '242px');
			if(i == 0) jQuery(this).addClass('active').css('left', '0px');
			
		});
		this.teaser_next();
		this.teaser_prev();
		setTimeout(function(){jQuery.gehrlicher.teaser_slide();}, 6000);
	},
	
	teaser_slide: function () {
		if(teaserslide) {
			if(jQuery('.csc-textpic-imagewrap .csc-textpic-imagerow:last').hasClass('active')){
				var last = jQuery('.csc-textpic-imagewrap .csc-textpic-imagerow:last');
				
				last
				.removeClass('active')
				.stop(true, true)
				.animate({left: '-242px'});
				
				jQuery('.csc-textpic-imagewrap .csc-textpic-imagerow:first')
				.css('left', '242px')
				.stop(true, true)
				.addClass('active')
				.animate({left: '0px'});
	
			}
			else
			{
				jQuery('.csc-textpic-imagewrap .csc-textpic-imagerow.active')
				.removeClass('active')
				.stop(true, true)
				.animate({left: '-242px'})
				.next()
				.css('left', '242px')
				.addClass('active')
				.stop(true, true)
				.animate({left: '0'});	
			}
			// führt die Wiederholung durch
			setTimeout(function(){jQuery.gehrlicher.teaser_slide();}, 6000);
		}
		
	},
	
	teaser_next: function(){
		jQuery('.teaser-next').click( function () {
			teaserslide = false;
			if(jQuery('.csc-textpic-imagewrap .csc-textpic-imagerow:last').hasClass('active')){
				var last = jQuery('.csc-textpic-imagewrap .csc-textpic-imagerow:last');
				
				last
				.removeClass('active')
				.stop(true, true)
				.animate({left: '-242px'});
				
				jQuery('.csc-textpic-imagewrap .csc-textpic-imagerow:first')
				.css('left', '242px')
				.addClass('active')
				.stop(true, true)
				.animate({left: '0px'});

			}
			else
			{
				jQuery('.csc-textpic-imagewrap .csc-textpic-imagerow.active')
				.removeClass('active')
				.animate({left: '-242px'})
				.next()
				.css('left', '242px')
				.addClass('active')
				.stop(true, true)
				.animate({left: '0'});	
			}
			return false;
		});
		
	},
	
	teaser_prev: function(){
		jQuery('.teaser-prev').click( function () {
			teaserslide = false;
			if(jQuery('.csc-textpic-imagewrap .csc-textpic-imagerow:first').hasClass('active')){
				var first = jQuery('.csc-textpic-imagewrap .csc-textpic-imagerow:first');
				
				first
				.removeClass('active')
				.animate({left: '242px'});
				
				jQuery('.csc-textpic-imagewrap .csc-textpic-imagerow:last')
				.css('left', '-242px')
				.addClass('active')
				.animate({left: '0px'});

			}
			else
			{
				jQuery('.csc-textpic-imagewrap .csc-textpic-imagerow.active')
				.removeClass('active')
				.animate({left: '242px'})
				.prev()
				.css('left', '-242px')
				.addClass('active')
				.animate({left: '0'});	
			}
			return false;
		});
		
	},

    headlines: function() {
        if (jQuery('body').attr('id') != 'page-5')
        {
            jQuery('#main_content h1').each(function() {
               var text = jQuery(this).text();
               var image = '<img src="http://' + window.location.hostname + '/fileadmin/template/script/ttf_headlines.php?t=' + encodeURI(text.replace(/&/, '%26')) + '" alt="' + text + '" />';
               jQuery(this).html(image);
            });
        }
    }
}

function validationclass () {
	jQuery('.tx-powermail-pi1 .validation-failed').parent().find('label').addClass('error');
}


// end coma part
jQuery.noConflict(); 
var $j =jQuery;
jQuery(document).ready(function(){ 
//jQuery(function($){ 
	if (jQuery.browser.msie && parseInt(jQuery.browser.version)< 7) {jQuery(document).pngFix();}
	alert
        jQuery("ul.sf-menu").supersubs({ 
            minWidth:    12,   // minimum width of sub-menus in em units 
            maxWidth:    40,   // maximum width of sub-menus in em units 
            extraWidth:  3     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish({
        	 speed:       1,	
        	 pathClass:  'level1_act'
        });  // call supersubs first, then superfish, so that subs are 
                         // not display:none when measuring. Call before initialising 
                         // containing tabs for same reason. 
                         
                         
       jQuery("ul.lang-menu").supersubs_wide({ 
            minWidth:   12,   // minimum width of sub-menus in em units 
            maxWidth:    50,   // maximum width of sub-menus in em units 
            extraWidth:  3     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish({
        	 speed:       1	
        });  // call supersubs first, then superfish, so that subs are 
                         // not display:none when measuring. Call before initialising 
                         // containing tabs for same reason. 
    }); 
 
jQuery(document).ready(function(){ 
	var $search = jQuery('#searchform').addClass('overlabel');
	var $searchInput = $search.find('#searchbox_input');
	var $searchLabel = $search.find('label');
	var $searchLang = jQuery('input[name=tx_indexedsearch[lang]]').val();
	switch($searchLang){
		case '0':
			$searchLabel.html('SEARCH');
			break;
		case '1':
			$searchLabel.html('SUCHE');
			break;
		case '4':
			$searchLabel.html('SEARCH');
			break;
		case '5':
			$searchLabel.html('BUSCAR');
			break;
		case '6':
			$searchLabel.html('SEARCH');
			break;
		case '7':
			$searchLabel.html('SEARCH');
			break;
		case '8':
			$searchLabel.html('SEARCH');
			break;
	}
	$searchLabel.css('display','block');
	if($searchInput.val()){
		$searchLabel.hide();
	}
	
	$searchInput
	.focus(function(){
		$searchLabel.hide();
	})
	.blur(function(){
		if (this.value==''){
			$searchLabel.show();
		}
	});
	
	$searchLabel.click(function(){
		$searchInput.trigger('focus');
	});

});
