var netlive = {};

$(document).ready(function(){
	$('body').addClass('js');

	netlive.searchBar();
	netlive.ui();
});

/***********************************************/

netlive.searchBar = function() {

	/* Ein- und Ausblenden der Suchleiste
	********************************************/

	var searchActivatedBy = '';

	$('#subNaviB a').bind('click', function(e){
		e.preventDefault();

		var button       = $(this).parent('li').attr('id');
		var searchWrap   = $('#searchWrap');
		var searchStatus = searchWrap.css('display');

		if(searchActivatedBy == button) {
			searchWrap.slideToggle(200);
			searchActivatedBy = button;
			if(searchStatus == 'none') {
				setInputFocus(button, 250);
			}
		} else {
			if(searchStatus == 'none') {
				searchWrap.slideDown(200);
				searchActivatedBy = button;
				setInputFocus(button, 250);
			} else {
				searchWrap.find('#search').effect('shake', { times: 3 }, 50);
				setInputFocus(button, 450);
			}
		}

	});

	/* Ausblendeschalter für die Suche
	   (wird nur mit JS eingeblendet)
	********************************************/

	$('#search').prepend('<div id="searchClose"><a href="#"><img src="/demandit/files/M_BB941CC4DCEF687AD98/dms/Image/cross.png" style="border:0;" /></a></div>');
	$('#searchClose a').click(function(e){
		e.preventDefault();
		$('#searchWrap').slideUp(200);
		searchActivatedBy = '';
	});

	/* Focus auf die input-Felder legen
	********************************************/

	setInputFocus = function(button, timeOut){
		$.timer(timeOut, function(timer) {
			if(button == 'toggleSearch') {
				$('input#search_focus').focus();
			} else if(button == 'toggleLogin') {
				$('input#loginUser').focus();
			}
			timer.stop();
		});
	}
}

netlive.ui = function() {

	/* ToogleBox
	********************************************/

	$('div.toggleBox div.cbHead').bind('click', function(e){
		var contentBox = $(this).parent('div');
		var box        = contentBox.children('.toggleBoxContent');
		var boxStatus  = box.css('display');

		if(boxStatus == 'block') {
			box.slideUp(200, 'linear');
			contentBox.addClass('toggleBoxClosed');

		} else {
			box.slideDown(200, 'linear');
			contentBox.removeClass('toggleBoxClosed');
		}
	});

	/* Tabs
	********************************************/

	$('.tabs').accessibleTabs({
		tabhead: 'h2',
		fx: 'fadeIn',
		fxspeed: 200
	});

}