/* var stopAnimation = false; */

/**
 * does some various form-related logic
 */
var b13forms =  {

		// input logic
	initInputFieldsWithTitle: function() {
		$('input[type=text]').each(b13forms.fillInputWithTitle);
		$('input[type=text]').blur(b13forms.fillInputWithTitle);
		$('input[type=text]').blur(function() {
			$(this).parents('.formRow').removeClass('isActive');
			$(this).parents('.inputWrap').removeClass('isActive');
		});
		$('input[type=text]').bind('click focus', b13forms.removeTitleFromInput);
		$('input[type=text]').bind('click focus', function() {
			$(this).parents('.formRow').addClass('isActive');
			$(this).parents('.inputWrap').addClass('isActive');
		});
		$('form').bind('submit', function() {
			$('input[type=text]').each(b13forms.removeTitleFromInput);
		});
	},

		// fill input field with corresponding title-field
	fillInputWithTitle: function() {
		if ($(this).attr('title') && ($(this).val() === '' || $(this).val() === $(this).attr('title'))) {
			$(this).val($(this).attr('title'));
			$(this).addClass('inputDefaultValue');
			if ($(this).hasClass('inputTitleColor')) {
				$(this).css({color: '#aaa' });
			}
		}
	},

		//remove value from input if default-value
	removeTitleFromInput: function() {
		if ($(this).hasClass('inputDefaultValue') && $(this).val() === $(this).attr('title')) {
			$(this).val('');
			$(this).removeClass('inputDefaultValue');
			if ($(this).hasClass('inputTitleColor')) {
				$(this).css({color: '#666' });
			}
		}
	}

};




/*
//play animation
b_teaserAnimation = function (el) {
	if (stopAnimation == false) {
		var crtTeaser = $(el).children('.current').css({'zIndex': '5'});
		var pageBrowser = $(el).children('.teaserPager');
		
		if ($(crtTeaser).next().hasClass('singleTeaser')) {
			var nextTeaser = $(crtTeaser).next();
		} else {
			var nextTeaser = $(el).children().first().css({'zIndex': '10'});
		}
		
		var indexNr = $(nextTeaser).index();
		
		//pageBrowsers next page
			$(pageBrowser).children().eq(indexNr).addClass('current').siblings().removeClass('current');
		
		$(nextTeaser).addClass('current').fadeIn('slow', function() {
			$(crtTeaser).removeClass('current').hide();
		});
		
		//click event for pageBrowser
		$(pageBrowser).children().click(function() {
			if (!$(this).hasClass('current')) {
				var showTeaser = $(this).index();
				$(this).addClass('current').siblings().removeClass('current');
				$(el).children().eq(showTeaser).addClass('current').css({'zIndex': '10'}).siblings('.singleTeaser').removeClass('current').css({'zIndex': '5'});
				$(el).children().eq(showTeaser).fadeIn('slow', function() {
					$(el).children().eq(showTeaser).siblings('.singleTeaser').hide();
				});
			}
		})
	}
	
	window.setTimeout(function(){
		b_teaserAnimation(el);
	}, 8000);
}

//init animation
b_initTeaserAnimation = function(el) {
	var imgCount = $(el).children('.singleTeaser').length;
	var pageBrowser = $(el).children('.teaserPager');
	$(el).children('.singleTeaser').first().show().addClass("current").css({'zIndex': '5'}).siblings('.singleTeaser').hide().css({'zIndex': '10'});
	
	//create pageBrowser icons
	for (i=0; i<imgCount; i++) {
		$(pageBrowser).prepend("<span></span>");
	}
	$(pageBrowser).children().first().addClass("current");

	window.setTimeout(function(){
		b_teaserAnimation(el);
	}, 8000);
}
*/


initAccordion = function() {
	$('.accordionContent').each(function() {
		var height = $(this).data("originalHeight"); 
		var visible = $(this).is(":visible");
		// get the original height
		if( !height ){
			// get original height
			height = $(this).show().outerHeight();
			// update the height
			$(this).data("originalHeight", height);
			// if the element was hidden, hide it again
			if( !visible ) $(this).hide().css({height: 0});
		}
	});
}


$(document).ready(function() {

		// start some form-related logic
	b13forms.initInputFieldsWithTitle();

	/*
$('.mainTeaser').each(function() {
		if ($(this).children('.singleTeaser').length > 1) {
			b_initTeaserAnimation($(this));
		}
	});
	$('.mainTeaser').hover(function() {
		stopAnimation = true;
	}, function() {
		window.setTimeout(function() {
			stopAnimation = false;
		}, 1000);
	});
*/
	
	//init accordion
	/* initAccordion(); */

	// toggles the detail-view-content-visibilty of tt_news
/*
	$('.accordionLink').click( function(evt) {
		evt.preventDefault();
		content = $(this).next('.accordionContent');
		if (content.hasClass('open')) {
			$(this).removeClass('accordionOpen')
			content.stop(true, true).slideUp(750).removeClass('open');
		} else {
			$(this).parents('.accordionWrap').find('.open').animate({height: '0px'}, 750, "linear", function() { 
				$(this).hide(); 
			}).removeClass('open');
			$(this).parents('.accordionWrap').find('.accordionOpen').removeClass('accordionOpen')

			$(content).show().animate({height: $(content).data("originalHeight") }, 750, "linear").addClass('open');
			$(this).addClass('accordionOpen');
		}
	});
*/

$( ".accordionWrap" ).accordion({ header: '.accordionItem .accordionLink',  active: 0, clearStyle: true, autoHeight: false,
			navigation: true });

	// call amazingSlider plugin
	$('.mainTeaser').amazingSlider();


/*
$(function() {
		$('.accordionWrap').accordion({
			autoHeight: false,
			navigation: true
		});
	});
*/

})
