$(function() {
	hairmail.init();
});

var hairmail = {
	init : function() {
		if(!($.browser.msie && parseInt($.browser.version) < 7)) {
			this._addShadow();
		}

		var that = this;
		this._initLoginFields();
		$('#mainmenu .pro').click(function() {
			if(!that.PRO_MODE) {
				that._showLoginNotice();
				return false;
			}
		});

		this._displayLoginErrors();
	},
	
	_displayLoginErrors : function() {
		var that = this;
		$errors = $('#login .error');
		if($errors.length > 0) {
		 	$('#login form').hide();
			$errors.show();
			$errors.click(function() { that._restoreLoginForm(); });
			setTimeout(function() {
				that._restoreLoginForm();
			}, 5000);
		}
	},
	
	_restoreLoginForm : function() {
		$('#login .error').hide();
		$('#login form').show();
	},
	
	_addShadow : function() {
		$('#content').addClass('shadow-four');
		$('.shadow-four').wrap('<div class="shadow-three" />');
		$('.shadow-three').wrap('<div class="shadow-two" />');
		$('.shadow-two').wrap('<div class="shadow-one" />');
		$('.shadow-one').prepend('<div class="corner-b" />');
		$('.shadow-one').prepend('<div class="corner-a" />');
	},
	
	_initLoginFields : function() {
		if(this.lang != 'fi' && this.lang != 'se') return;
		
		$('#username').tpLabeledTextfield({
			removeLabelTag : false,
			label : this.translate['Käyttäjätunnus'],
			labelCss : {
				'font-style' : 'italic',
				'color' : '#666666'
			},
			valueCss : {
				'color' : '#000000',
				'font-style' : 'normal'
			}
		});
		
		$('#password').tpLabeledTextfield({
			removeLabelTag : false,
			password : true,
			label : 'salasanasana',
			labelCss : {
				'font-style' : 'italic',
				'color' : '#666666'
			},
			valueCss : {
				'color' : '#000000',
				'font-style' : 'normal'
			}
		});
	},
	
	_showLoginNotice : function() {
		$('object').css({'display':'none'});
		!$.browser.msie ? $('#login_notice').fadeIn() : $('#login_notice').show();
			
		$('#login_notice').click(function() {
			$('object').css({'display':'block'});
			!$.browser.msie ? $('#login_notice').fadeOut() : $('#login_notice').hide();
			$('#login_notice').unbind('click');
		});		
	}	
		
		
		
	
	
}


