$(function(){

    $('.slide span').click(function(){

        $(this).parent('.slide').children('div').slideToggle();
        $(this).toggleClass('active');


    });
	
	/*var width_gal = $('#gallery').width();
	$('#gallery').css({width: width_gal});*/

    $('#gallery').cycle({
        
        fx:     'fade',
        speed:  'slow',
        timeout: 6000,
        pager:  '#nav',
		width: '383',


    // callback fn that creates a thumbnail to use as pager anchor
    pagerAnchorBuilder: function(idx, slide) {
        return '<li><a href="#"><img src="' + slide.src + '" width="50" height="50" /></a></li>';
    }
    });

    $('#gallery img').css({
        left: 'auto',
        right: 0
    })
	
	 // Formular
  
  	$('p#error').hide();  
	$(".absenden").click(function() {
		$('p#error').hide();
 
		var name = $("input#name").val();	
		if (name == "") {  
			$("p#error").show();  
			$("input#name").focus();  
			return false;  
		}
		
		var email = $("input#email").val();  
		if (email == "") {  
			$("p#error").show();  
			$("input#email").focus();  
			return false;  
		}
		
		var text = $("textarea#text").val();  
		if (text == "") {  
			$("p#error").show();  
			$("textarea#text").focus();  
			return false;  
		}
		
		var text = $("input#betreff").val();  
		if (text == "") {  
			$("p#error").show();  
			$("input#betreff").focus();  
			return false;  
		}
				
		var dataString = 'name='+ name + '&email=' + email + '&text=' + text + '&interest=' + interest;  
		$.ajax({
		
			type: "POST",  
			url: "http://www.dinnova.de/kunde/garbe/bin/process.php",  
			data: dataString,  
			success: function(data) {
				if(data == "Mail"){
					$("p#email_error").show();  
					$("input#email").focus();  
					return false;
				}
				else{
			
					$('.kontakt_formular').html("<div id='message'></div>");  
					$('#message').html("<h2>Formular abgeschickt.</h2>")  
					.append("<p>Wir werden uns in Kürze bei Ihnen melden.</p>")  
				
				}
				
			}
			
		});  
		return false; 
		

	});  

});

// this is a fix for the jQuery slide effects
function slideToggle(el, bShow){
  var $el = $(el), height = $el.data("originalHeight"), visible = $el.is(":visible");
  
  // if the bShow isn't present, get the current visibility and reverse it
  if( arguments.length == 1 ) bShow = !visible;
  
  // if the current visiblilty is the same as the requested state, cancel
  if( bShow == visible ) return false;
  
  // get the original height
  if( !height ){
    // get original height
    height = $el.show().height();
    // update the height
    $el.data("originalHeight", height);
    // if the element was hidden, hide it again
    if( !visible ) $el.hide().css({height: 0});
  }

  // expand the knowledge (instead of slideDown/Up, use custom animation which applies fix)
  if( bShow ){
    $el.show().animate({height: height}, {duration: 250});
  } else {
    $el.animate({height: 0}, {duration: 250, complete:function (){
        $el.hide();
      }
    });
  }
  
	
}


