$(document).ready(function() {
  
		///////////////////////////////////////////////////////////////////////////// home page cycle efx
	  $('#panel_img').hide().fadeIn(2200);
	  $('#panel_img').cycle({
		    fx: 'fade',
		    timeout: 2500,
		    speed: 2500
	  });

		///////////////////////////////////////////////////////////////////////////// main navigation
	  $('#navigation ul li.photo_gallery').hover(function() {
	  $(this).children('ul').stop().animate({ width: "552px" }, 700);
	  $(this).children('ul').children('li').hide().stop().show();
	  },
	  function () {
	  $(this).children('ul').stop().animate({ width: "0px" }, 700);
	  });
    
	  $('#navigation ul li.contact').hover(function() {
	  $(this).children('ul').stop().animate({ width: "534px" }, 700);
	  $(this).children('ul').children('li').hide().stop().show();
	  },
	  function () {
	  $(this).children('ul').stop().animate({ width: "0px" }, 700);
	  });

 		///////////////////////////////////////////////////////////////////////////// file upload input
	  $("input[type=file]").filestyle({ 
		    image: "./images/choose_file.jpg",
		    imageheight : 25,
		    imagewidth : 100,
		    width : 308
	   });

 		///////////////////////////////////////////////////////////////////////////// faq
	  $('.faq p:first').show().css({
		'padding': '0',
		'margin-bottom': '30px'
		});
		
		$('.faq div p:last-child').css({
			"margin-bottom":"0"
		});

		
		isIE = ($.browser.msie) ? true : false;
		
		$('.faq h2').click(function() {
		if ( isIE == false ) $(this).css({ 'background-position': '-20px left' });
			$(this).next().slideDown('normal', function(){
				$('.faq div').removeClass('open');
				$(this).addClass('open');
					$('.faq div:visible').not('.open').slideUp();
				});
		  });
  
		///////////////////////////////////////////////////////////////////////////// clear form function    
  	$.fn.clearForm = function() {
  	return this.each(function() {
  	var type = this.type, tag = this.tagName.toLowerCase();
  	if (tag == 'form')
  	return $(':input',this).clearForm();
  	if (type == 'text' || type == 'password' || tag == 'textarea')
  	this.value = '';
  	else if (type == 'checkbox' || type == 'radio')
  	this.checked = false;
  	// else if (tag == 'select')
  	// this.selectedIndex = -1;
  	});
  	};
  	
  	// $('#contact_form').clearForm()
  	$(':input').clearForm()

		///////////////////////////////////////////////////////////////////////////// request form
		$('#mail_brochure').click(function(){
		if ( $('#mail_brochure').is(':checked') ) {
		$('#mail_address').slideDown('normal').removeClass('off');
		} else {
		$('#mail_address').slideUp('normal').addClass('off');
		}
		}); 
		
		/////////////////////////////////////////////////////////////////////////// validate form (bassistance.de)
		$.metadata.setType("attr", "validate"); // for radio, checkbox and select ( inline validation with attribute )
	
		
		$("#request_form").validate({
    errorPlacement: function(error, element) {
    if (element.attr("type") == "checkbox")
        error.appendTo('div.req_in p:first-child')
		else if (element.attr("name") == "project")
			  error.appendTo('div.req_description p:first-child')
    else
       error.insertBefore(element);
    },
    rules: {
			firstname: 		{ required: true },
			lastname: 		{ required: true },
			email: 				{ required: true, email: true },		
			address: 			{ required: true },
			city: 				{ required: true },
			state: 				{ required: true },
			zip: 					{ required: true },
			project: 			{ required: true },
			interest: 		{ required: true, minlength: 1 }
    },
		ignore: "#mail_address.off input", // ignore this when necessary ( checkbox adds and removes the class .off )
    messages: {
			firstname : "required",
			lastname  : "required",
			address   : "required",
			city      : "required",
			state     : "required",
			zip       : "required",
			project   : "required",
			interest  : "required",
			email			: { required: "required",  email: "Please enter a valid email address" }
			}
    });
    // success: function(label) { label.text("ok!").addClass("success"); }  


		///////////////////////////////////////////////////////////////////////////// case studies
		$('#cases > div').hide(); // hide all divs
		$('#cases div.current').fadeIn('slow'); // hide all divs
		
		 /*
		 $('#sidepanel li a').each(function() {
		 		$(this).bind("click", function(event) {
		 			event.preventDefault();
		 			$('#sidepanel li a').css({ 'background':'none' });
		 			$(this).css({ 'background':'#E0AA0F' });
	   		});
		 });
		 */

		///////////////////////////////////////////////////////////////////////////// layout adjustment
		$('#sub-content ul').children().eq(1).css({'margin-right' : '18px', 'margin-left': '18px'});
		$('#request_form div.float-right p:eq(1)').css({'margin-top' : '18px'});
		
		///////////////////////////////////////////////////////////////////////////// uploading file anim. gif
		$('p.loading').hide();
		$('input[name=upload]').click(function() {
			$('p.loading').show();
		});
		
	//////////////////////////////////////////////////////////////////
	//Replace for target="_blank" to open in a new window
    $("a[rel='external']").click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
		
		
}); // end doc ready




