



$(document).ready(function() {

    
    // 3 Column
    $('.threeColumn').columnize({width:330}).css({'float':'left'});
    toolTip();
     
    teaserSlider();

    accordion();
    
//    twitter();
    
    boxAlign('#c3111');
    boxAlign('#c5661');
        
    addContactForm();
    
 });
 
 
  function toolTip(){
      
   $("#neustagroup > span").click(function(){
      target(jQuery(this).attr('href'));
   });   
      
   $("#neustagroup > .internal-link").tooltip({

   // tweak the position
   offset: [10, 0],

   // use the "slide" effect
   effect: 'slide'

    // add dynamic plugin with optional configuration for bottom edge
    });
    

    $("#neustagroup > .external-link-new-window").tooltip({

   // tweak the position
   offset: [10, 0],

   // use the "slide" effect
   effect: 'slide'

    // add dynamic plugin with optional configuration for bottom edge
    });
     
     
 }
 
 function target(target) {
  window.location.href = target;
}
 
 function addContactForm(){
     
     $('#contact-top').before("<div id='contactHeader'></div>");
     $('#contactHeader').append($('#contactContainer'));
    

    
    if($('.tx-powermail-pi1_thx').length > 0){
	$('#contact-top').animate({top: '554'}, 0, function(){$('#contact-top').html('schliessen')});
  	$('body').animate({backgroundPosition: '0px 545px'}, 0);
	$('#contactContainer').animate({marginTop: '0'}, 0);
	$('#contactContainer > .csc-frame-indent6633').hide();
    }
    
     
     $('#contact-top').toggle(
     
     /* fadeOut */
     function(){
	$('#contact-top').animate({top: '554'}, 1000, function(){$('#contact-top').html('schliessen')});
  	$('body').animate({backgroundPosition: '0px 545px'}, 1000);
	$('#contactContainer').animate({marginTop: '0'}, 1000);
     },
     /* fadeIn */
     function(){
	$('#contact-top').animate({top: '0'}, 1000, function(){$('#contact-top').html('anfrage')});
  	$('body').animate({backgroundPosition: '0px 0px'}, 1000);
	$('#contactContainer').animate({marginTop: '-549'}, 1000);
     });
     
     
    $('#contactContainer input, #contactContainer textarea')
    .focus( function() {
    if ( $(this).val() == this.defaultValue ) {$(this).val('');}
    })
    .blur( function() {
    if ( $(this).val()=='' ) {$(this).val(this.defaultValue);}
    });

     
 }

 
 function boxAlign(container){
     height = searchHight(container);
     	$(container + ' > .threeColumnteaser').each(function(index, value) { 
	    $(this).height(height);
	});

     
}

function searchHight(container){
    var height = 0;
    $(container + ' > .threeColumnteaser').each(function(index, value) { 
	if (height < $(this).height()){
	    height = $(this).height();
	}    
    });    
    
    return height;
}
 
 /*
 function twitter(){
     
     jQuery(function($){
      $("#twitter").tweet({
        avatar_size: 40,
        count: 2,
        username: "teamneusta",
        template: "<b>@teamneusta</b> <br />{text}"
      });
    }).bind("loaded", function(){
      $(this).find("a.tweet_action").click(function(ev) {
        window.open(this.href, "Antworten",
                    'menubar=0,resizable=0,width=550,height=420,top=200,left=400');
        ev.preventDefault();
      });
    });
 }
 */
 
 function teaserSlider(){
         jQuery('#header-slider').show('fast');
    //stage cycle    
    jQuery('.stage').each(function() {
	var pager = jQuery('.nav', this);
	var imageStage = jQuery('.imageStage', this).cycle({
 
	    timeout:12000,
	    speed:1000,
	    pager:pager
	});
	pager.css({
	    top:imageStage.height() - 32,
	    right:pager.width() - pager.find('a:first').width() * pager.find('a').length + 10,
	    zIndex:parseInt(pager.find('a').length) + 2
	});
    });
    // Center nav below Slider
    jQuery('.nav').css('width', jQuery('.nav a').length*38);

 }
 
 function accordion(){
     
     anzElements = $('#accordion .csc-default').length;
     
	$('#accordion > .csc-default').each(function(index, value) { 
	    if(index == 2){
		$(this).css('marginRight',0);
	    }   
	}); 
       
     $('#accordion .csc-default .csc-default').each(function(index, value) { 

	 $(this).data('fullHeight', $(this).height());
	 $(this).data('minHeight', '15');
	 me = $(this); 
	 $(this).addClass('closed');
	 $(this).click(
	 function(){
	    if ($(this).height() == $(this).data('minHeight')){
		    $('#accordion').find('.open').animate({height : me.data('minHeight')}, 500,  function(){
			$(this).removeClass('open').addClass('closed');
		    });		
		$(this).animate({height : $(this).data('fullHeight')}, 500, function(){
	    	    $(this).removeClass('closed').addClass('open');
		});
	    }else{
		$(this).animate({height : $(this).data('minHeight')}, 500,  function(){
		    $(this).removeClass('open').addClass('closed');
		});
	    }
	 }
	 );
	 

     });
   
     
 }
 

