// Cufon Replace, has to be placed of "document.ready"
Cufon.replace('h1', { hover: false });
Cufon.replace('h3', { hover: true });
Cufon.replace('#menu a', { hover: true});
Cufon.replace('.cufonTransform', { hover: true});
Cufon.replace('ul.footerMenu a', { hover: true})
Cufon.replace('.tx-mmforum-subth2', { hover: true});

var windowQueueNewsSlider

/**
 * 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' });
			}
		}
	}

};



b_showNextNewsSlider = function(goToElement) {
//nextall().length == 0
	if (!goToElement.hasClass('active')) {
		$('.news-latest-item.active').removeClass('active').find('.teaserItem').fadeOut('slow')
		goToElement.addClass('active').find('.teaserItem').stop(true,true).fadeIn('slow')
	}


	var nextElement = goToElement.next()
	var counter = goToElement.nextAll().length
	if (goToElement.nextAll().length == 0) {
		nextElement = $('.news-latest-item').first()
	}

	windowQueueNewsSlider = window.setTimeout(function() {b_showNextNewsSlider(nextElement)}, 6000)

}


b_initNewsSlider = function() {
	$('.news-latest-item').first().addClass('active').find('.teaserItem').show();
	
	window.setTimeout(function() {b_showNextNewsSlider($('.news-latest-item.active').next())}, 6000)
	
	
	$('.listItem').click(function(evt) {
		window.clearTimeout(windowQueueNewsSlider)
		b_showNextNewsSlider($(this).parents('.news-latest-item'))
	});
	

/*
	$('.newsSlider').hover( function() {
		window.clearTimeout(windowQueueNewsSlider)
console.log('hover')
	}, function(){
		b_showNextNewsSlider($('.news-latest-item.active'))
// 		windowQueueNewsSlider = window.setTimeout(function() {b_showNextNewsSlider($('.news-latest-item.active').next())}, 2000)
	})
*/
	
	
}





$(document).ready(function(){
		// fontreplacing with JS
	Cufon.now();

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

		// make the login submit work
	$('.formSubmit').click(function(evt) {
		evt.preventDefault();
		$(this).parents('form').first().submit();
	});
	
	b_initNewsSlider();
	
	if ($('.replyButton').length > 0) {
		var replyUrl = $('.footerReplyButton a').attr('href')
		$('.replyButton').each(function() {
			$(this).attr('href', replyUrl)
		});
	}
	
	if ($('.topicButton').length > 0) {
		var topicUrl = $('.tx-mmforum-rootline a').last().attr('href')
		$('.topicButton').each(function() {
			$(this).attr('href', topicUrl)
		});
	}
	
	
	
});
