$(function() {

	/*---------- EMAIL ----------*/
	
	$('a.email').each(function() {
		
		var id = '#' + $(this).attr('id');
		var end = '.de';
		if ($(id + '.org').length > 0) {
			end = '.org';
		}
		var email = $(id + ' span:first').text() + '@' + $(id + ' span:last').text() + end;
		var test = $('#second span:first').text();
		$(id).attr({ "href" : ('mailto:' + email) });
		$(id + ' span:first').remove();
		$(id + ' span:last').replaceWith(email);
		
	});
	
	$('.extern').attr({ "target" : "_blank" });

	/*---------- OVERLAY ----------*/
	
	var open = $('<div id="open"><a class="down" href="#BedieungshinweisOn">Bedienungshinweise</a></div>');
	var close = $('<div id="close"><a class="up" href="#BedieungshinweisOff">Bedienungshinweise</a></div>');
	var hinweis = $('<div id="hinweis" />');
		
	$('#hinweisBG').append(hinweis);
	$('#overlayBox').append(open, close);
	$(close).hide();
	
	var overlaytextbox = '<div id="overlaytextbox">';
			overlaytextbox += '<h3>Bedienungshinweise</h3>';
			overlaytextbox += '<div class="line02" />';
			overlaytextbox += '<p>Klicken Sie auf die Farbfelder um die T-shirts mit Farbe zu f&uuml;llen.<br />Klicken Sie auf die Motive um den T-shirts Motive zuzuweisen.</p>';
			overlaytextbox += '<p>Sie k&ouml;nnen die T-schirts vergr&ouml;&szlig;ern in dem Sie auf <span class="red">&raquo;vergr&ouml;&szlig;ern&laquo;</span> klicken.<br />Die Motive k&ouml;nnen Sie ansehen indem Sie auf die Pfeile neben <span class="red">&raquo;vergr&ouml;&szlig;ern&laquo;</span> klicken.</p>';
	
	$(hinweis).append(overlaytextbox);
	
	$(open).click(function() {
	
		$('#hinweis').slideDown(500);
		$(this).hide();
		$(close).show();
		
	});
	
	$(close).click(function() {
	
		$('#hinweis').slideUp(500);
		$(this).hide();
		$(open).show();
		
	});

	/*---------- OVERLAY ----------*/

	/*---------- SEITZEICHEN ----------*/
	
	$('a.seitzeichen').attr({ "target" : "_top" });

	/*---------- SEITZEICHEN ----------*/
			
	/* ---------- Shirtfunction ---------- */

	$('.inline').hide();
	$('.fish').hide();
	
	var goBig = $('<div class="areasize" id="goBig"><a href="#big" class="big">vergr&ouml;&szlig;ern</a></div>');
	var goSmall = $('<div class="areasize" id="goSmall"><a href="#small" class="small">verkleinern</a></div>');
	var prev = $('<div id="prev"><a class="prev">|</a></div>');
	var next = $('<div id="next"><a class="next">|</a></div>');
	
	$('#slidenavi').append(prev, goBig, goSmall, next);
	$(goSmall).hide(); $(prev).hide();
	
	$('#black').click(function() {
	
		$('#women .inline').replaceWith('<img class="inline" src="img/womenblack.png" alt="" />');
		$('#men .inline').replaceWith('<img class="inline" src="img/menblack.png" alt="" />');
	
	});
	
	$('#red').click(function() {
	
		$('#women .inline').replaceWith('<img class="inline" src="img/womenred.png" alt="" />');
		$('#men .inline').replaceWith('<img class="inline" src="img/menred.png" alt="" />');
	
	});
	
	$('#logoFisch').click(function() {
	
		$('#women .fish').replaceWith('<img class="fish" src="img/fishwomen.png" alt="" />');
		$('#men .fish').replaceWith('<img class="fish" src="img/fishmen.png" alt="" />');
	
	});
	
	$('#logoAuftrieb').click(function() {
	
		$('#women .fish').replaceWith('<img class="fish" src="img/auftriebwomen.png" alt="" />');
		$('#men .fish').replaceWith('<img class="fish" src="img/auftriebmen.png" alt="" />');
	
	});
	
	$(goBig).click(function() {
	
		$('#visual').animate({ "height" : "490px" });
		$('ul#visualslide li').animate({ "font-size" : "20px", "height" : "400px" });
		$(this).hide(); $(goSmall).show();
		
	});
	
	$(goSmall).click(function() {
	
		$('ul#visualslide li').animate({ "font-size" : "10px", "height" : "200px" });
		$('#visual').animate({ "height" : "290px" });
		$(this).hide(); $(goBig).show();
	
	});
	
	$(prev).click(function() {
	
	});
	
	var currpoint = 0;
	
	$(next).click(function() {
	
		$(prev).show();
		
		currpoint = currpoint - 990;
		$('ul#visualslide li').animate({ "left" : currpoint });
		
		if (currpoint < -990) {
			$(this).hide();
		}
	
	});
	
	$(prev).click(function() {
	
		$(next).show();
		
		currpoint = currpoint + 990;
		$('ul#visualslide li').animate({ "left" : currpoint });
		
		if (currpoint > -990) {
			$(this).hide();
		}
	
	});
			
	/* ---------- Shirtfunction ---------- */
			
	/* ---------- Kontaktformular ---------- */
	
	var repeat = $('<div id="repeat"><div class="line02" /><p /></div>');
	$('#formular').append(repeat);
	$(repeat).css({ "color" : "#d10c1f" }).hide();
	
	$('#form').ajaxForm(function(data) {
	
		if (data==1) {
		
			var success = $('<p>Ihre Email wurde erfolgreich abgeschickt, Wir setzen uns schnellstm&ouml;glichst mit Ihnen in Verbindung!</p>');
			$('#repeat p').replaceWith(success);
			$(repeat).slideDown();
			$('#form').resetForm();
		
		}
		
		else if (data==2) {
		
			var server = $('<p>Bitte versuchen Sie es sp&auml;ter noch einmal oder schicken Sie uns eine Email</p>');
			$('#repeat p').replaceWith(server);
			$(repeat).slideDown();
		
		}
		
		else if (data==3) {
		
			$('label:not(.not)').css({ "color" : "#d10c1f" });
			var control = $('<p>Bitte &uuml;berpr&uuml;fen Sie die rot markierten Felder.</p>');
			$('#repeat p').replaceWith(control);
			$(repeat).slideDown();
			
		}
		
		$('#submit').click(function() {
		
			$(repeat).slideUp();
		
		});
		
		$('#reset').click(function() {
		
			$('label:not(.not)').css({ "color" : "#000" });
			$(repeat).slideUp(function() {
				$('#repeat p').replaceWith('<p />');
			});
			
		});
	
	});
	
	/* ---------- Kontaktformular ---------- */
	
});
