/* 
* Skeleton V1.0.2
* Copyright 2011, Dave Gamache
* www.getskeleton.com
* Free to use under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
* 5/20/2011
*/	
	

$(document).ready(function() {

	/* Tabs Activiation
	================================================== */
	var tabs = $('ul.tabs');
	
	tabs.each(function(i) {
		//Get all tabs
		var tab = $(this).find('> li > a');
		tab.click(function(e) {
			
			//Get Location of tab's content
			var contentLocation = $(this).attr('href') + "Tab";
			
			//Let go if not a hashed one
			if(contentLocation.charAt(0)=="#") {
			
				e.preventDefault();
			
				//Make Tab Active
				tab.removeClass('active');
				$(this).addClass('active');
				
				//Show Tab Content & add active class
				$(contentLocation).show().addClass('active').siblings().hide().removeClass('active');
				
			} 
		});
	});
	
	$('a[rel^="prettyPhoto"]').prettyPhoto({ social_tools: false });
	
	function getInfo(element) {
		$.get(element.attr('href'), function(data) {
			element.attr('title', $(data).find('#kursinfo').text());		
		});	
	}
	
	$('td.info a').bt({
		ajaxPath: ["$(this).attr('href')", 'div#kursinfo'],
		ajaxCache: false,
		width: '350px',
		strokeWidth: 0,
		cornerRadius: 0,
		spikeGirth: 10,
		spikeLength: 10,
		fill: '#cfcfcf'
	});
	
	$('form#newsletter input[type=text]').val($('form#newsletter label').text()).css('color', '#999999').click(function() {
		if ($(this).val() == $('form#newsletter label').text()) {
			$(this).val('').css('color', '#000000');
		}
	});
	$('form#newsletter label').hide();	
	$('form#newsletter').submit(function(e) {
		e.preventDefault();
		$('form#newsletter input[type=submit]').addClass('loading');
		$.post($(this).attr('action'), $(this).serialize(),
			function(data) {
				var inhalt = $(data).find('#alertmsg ul li').text().replace(/Subscription request received./g, '');
				$('form#newsletter input[type=submit]').removeClass('loading');
				if (inhalt == 'Invalid Email Address') {					
					if ($('form#newsletter p#hinweis').length == 0) {
						$('form#newsletter input[type=text]').before('<p id="hinweis"></p>');
					}
					$('form#newsletter p#hinweis').text('Fehlerhafte E-Mail Adresse!').css({'padding': '5px', 'background': '#ffff66'});
				} else if (inhalt == 'Email address already exists. Duplicates are not allowed.') {					
					if ($('form#newsletter p#hinweis').length == 0) {
						$('form#newsletter input[type=text]').before('<p id="hinweis"></p>');
					}
					$('form#newsletter p#hinweis').text('E-Mail Adresse bereits vorhanden!').css({'padding': '5px', 'background': '#ffff66'});
				} else {
					$('div.newsletter').slideUp('fast').slideDown('fast').html($(data).find('.two-thirds').removeClass('two-thirds').removeClass('column'));	
				}
			}
		);
	});
	
});
