$(document).ready(function () {
    initInputDefaultValues();
    if ($.cookie('ekLogin') == 1) {
		ekLoggedIn();
	} else {
		ekNotLoggedIn();
	}
    // global search autocomplete
    $('#global-search-text').autocomplete('index.php', {autoFill:false,minChars:1,matchContains:true,extraParams:{ac:globalSite}});
    
    // set content headlines to same height
    $.each($('#content .col.center .headline.even'), function(i) {
        var compareElem = $(this).prev('.headline');
        if (compareElem && compareElem.css('float') != 'none') {
            if ($(this).height() > $(compareElem).height()) {
                $('.content', compareElem).height($('.content', this).height());
                $('.wrap', compareElem).height($('.wrap', this).height());
            } else {
                $('.content', this).height($('.content', compareElem).height());
                $('.wrap', this).height($('.wrap', compareElem).height());
            }
        }
    }); 
	$('#ekLoginForm form').submit(function() {
		$.cookie('ekLogin', 1, { path: '/' });
		ekLoggedIn();
		return true;
	});
	function ekLoggedIn() {
		$('#ekLoginForm').hide();
		$('#ekNavi').show("fast");
	}
	function ekNotLoggedIn() {
		$('#ekLoginForm').show("fast");	
		$('#ekNavi').hide();
	}
	$('#ekLogout').click(function() {
		$.cookie('ekLogin', null);
		ekNotLoggedIn();
		return true;
	});
});

function initInputDefaultValues(forceReset) {
    // if set globalDefaultValus init default values for text inputs
    if (globalDefaultValues) $('input').each(function(i) {
        if (globalDefaultValues[this.id]) {
            if (!this.value || (this.value == globalDefaultValues[this.id]) || forceReset) $(this).val(globalDefaultValues[this.id]).addClass('no-value');
            $(this).focus(function () { if (this.value == globalDefaultValues[this.id]) $(this).val('').removeClass('no-value'); });
            $(this).blur(function () { if (this.value == '') $(this).val(globalDefaultValues[this.id]).addClass('no-value'); });
        }
    });
}
