$(document).ready(function() {
	agent = jQuery.browser;
  $('.send').validate({
		newmask : /[0-9]{1}-[0-9]{1}/,	// 1-1
		err_class : "invalidInput"
	})
  $('.submit').click(function() {
    $('.send').submit();
    return false;
  })
  $('.send').submit(function() {
    var submitOptions = {
      dataType: 'json',
      type: 'post',
      clearForm: true,
      error: function() {
				alert('Es ist ein Fehler aufgetreten.');
				return false;
			},
			success: function(j) {
				var msg = j.msg;
        alert(j.msg);
				return false;
			}
	 }
	 $(this).ajaxSubmit(submitOptions);
	 return false;
	})	
		$('.popBoxLink').click(function() {
		if($('.popBoxContainer')) {
			$('.popBoxContainer').remove();
		}
		if(!$(this).hasClass('popBoxLinkActive')) {	
			cur = $(this);
			titleX = $(cur).html();
			contentX = $(cur).next('.popBoxLoadContent').html();
			classX = $(cur).attr('class');
			boxX = createPopBox(titleX, contentX, classX);
			if($(cur).hasClass('shadowFormLink')) {
				$(cur).parents('.boxH').after(boxX);
			} else {
				$(cur).after(boxX);
			}
			boxX = $('.popBoxContainer');
			posit = $(cur).position();
			widthit = $(cur).outerWidth();
			widthbox = $(boxX).outerWidth();
			$(boxX).css({top: posit.top-8, left: (posit.left-widthbox+widthit+25)});
			return false;
		}
	})
	clicked0 = false;
	clicked2 = false;
	$('.referenzen').click(function() {
		if(!clicked2) {
			if(clicked0) newWidth = 826;
			else newWidth = 553;
			$('#environment').addClass('wider').animate({width: newWidth+'px'}, 250);
			$('#contentRef').stop().animate({opacity: 'toggle', width: 'toggle'}, 250, 'linear', function() {
				$(this).children('.hiddenContent').animate({opacity: 'toggle'}, 250);
			});	
		} else {
			$(this).effect("highlight", {color: '#fff'}, 250);
			$('#contentRef').effect("highlight", {color: '#b6def3'}, 250);
		}
		clicked2 = true;
		return false;
	})
	$('.ueber_uns').click(function() {
		if(!clicked0) {
			if(clicked2) newWidth = 826;
			else newWidth = 553;
			$('#environment').addClass('wider').animate({width: newWidth+'px'}, 250);
			$('#contentAbout').stop().animate({opacity: 'toggle', width: 'toggle'}, 250, 'linear', function() {
				$(this).children('.hiddenContent').animate({opacity: 'toggle'}, 250);
			});	
		} else {
			$(this).effect("highlight", {color: '#fff'}, 250);
			$('#contentAbout').effect("highlight", {color: '#b6def3'}, 250);
		}
		clicked0 = true;
		return false;
	})
	allNexts = $('.clients').size();
	stop = false;
	$('.next').click(function() {
		if(stop) return false;
		stop = true;
		nextPage = $(this).attr('href');
		$(this).attr('href', Number(nextPage)+1);
		prevEl = nextPage-1;
		if(nextPage > 1) {
			$('.prev').fadeIn(150).attr('href', Number(nextPage)-1);
		}
		if(allNexts == nextPage) {
			$('.next').fadeOut(150);
		}
		$('ul.clients.l'+prevEl).animate({marginLeft: '-265px', opacity: 0}, 250, 'linear', function() {
			stop = false;
		});
		return false;
	})
	$('.prev').click(function() {
		if(stop) return false;
		stop = true;
		prevPage = $(this).attr('href');
		$(this).attr('href', Number(prevPage)-1);
		$('.next').attr('href', Number(prevPage)+1)
		prevEl = prevPage;
		if(prevPage == 1) {
			$('.prev').fadeOut(150).attr('href', Number(nextPage)-2);
		}
		if(allNexts < prevPage+1) {
			$('.next').fadeIn(150);
		}
		$('ul.clients.l'+prevEl).animate({marginLeft: '0', opacity: 1}, 250, 'linear', function() {
			stop = false;
		}).show();
		return false;
	})

})

function createPopBox(titleX, contentX, classX) {
	var htmlc = '<div class="popBoxContainer"><div class="popBoxBodyContainer"><div class="popBoxBody"><div class="popBoxContentContainer"><div class="popBoxContent"><div class="popBoxHolderContainer"><div class="popBoxHolder"><div class="popBox"><div>'+contentX+'</div><a class="popBoxClose" onclick="removePopBox(event, this);return false;"> </a></div></div></div></div></div></div></div><div class="popBoxHeadContainer"><div class="popBoxHead"><div class="popBoxHeadLinkContainer"><div class="popBoxHeadLink"><a href="#" class="popBoxLinkActive '+classX+'" onclick="removePopBox(event, this);return false;">'+titleX+'</a></div></div></div></div></div>';
	return htmlc;
}
function removePopBox(event, boxX) {
	if(agent.msie) {
		event.cancelBubble = true;
		$(boxX).parents('.popBoxContainer').remove();
	} else {
		event.stopPropagation();
		$(boxX).parents('.popBoxContainer').fadeOut('normal', function() { $(this).remove(); });
	}	
	
	return false;
}

