/**
 * Logo-Homelink-Indicator
 */
$(function()
{
	$info = $('<p><img src="static/styles/images/to-home.png" /></p>')
				.css({
					'position': 'absolute',
					'left': '-5000px',
					'top': '-5000px'
				})
				.hide();
	$('a.logo')
		.not('.indicator-inactive')
		.append($info)
		.find('img.logo')
			.mousemove(function(e)
			{
				$info
					.css({
						'left': e.pageX-10,
						'top': e.pageY+5
					});
			})
			.hover(function(e)
			{
				$info
					.fadeIn('fast')
					.css({
						'left': e.pageX-10,
						'top': e.pageY+5
					});
			},
			function()
			{
				$info
					.fadeOut('fast', function()
					{
						$(this).css({
							'left': '-5000px',
							'top': '-5000px'
						})
					});
			});
});

$(function()
{
	var $topArea = $('.netshaker-layout-toparea')
						.prependTo('body')
						.css('position','relative');

	var $layout = $('>div.netshake-layout', $topArea);

	$('a#CloseToparea', $topArea).click(function()
	{
		$layout.css('min-height', '0');
		$('.netshake-content.active', $topArea)
			.slideUp('fast')
			.removeClass('active');
		$('ul.menu li span').removeClass('active');
		$(this).hide();
	});

	
	$('.netshaker-layout-toparea ul.menu')
		.click(function(e)
		{
			$('ul.menu li span').removeClass('active');
			
			e.preventDefault();
			var $li = $(e.target);
			
			if ( !$li.hasClass('menu-entry') ) {
				$li = $li.parents('.menu-entry');
			}
			var target = $li.attr('class').replace('menu-entry ', '');
			var $target = $('div.netshake-content.'+target);
			$('a#CloseToparea').show();
			
			if ( $target.hasClass('active') ) {
				$layout.css('min-height', '0');
				$target
					.slideUp('fast')
					.removeClass('active');
				$('a#CloseToparea').hide();
			} else if ( 0 < $('div.active', $topArea).size() ) {
				$layout
					.css('min-height', $layout.height());
				$('div.active', $topArea)
					.fadeOut('slow', function()
					{
						$(this).removeClass('active');
						$target
							.fadeIn('slow')
							.addClass('active');
					});
				$('span',$li).addClass('active');
			} else {
				$target
					.slideDown('fast')
					.addClass('active');
				$('span',$li).addClass('active');
			}
		});

	/**
	 * Stop-Scorlling
	 */
	(function()
	{

		var $infotext = $('#Infotext');
		$infotext
			.css({
				'left': '0',
				'right': '0',
				'height': '100px',
				'bottom': '-100px',
				'overflow': 'hidden'
			});
		$('.row', $infotext)
			.css({
				'position': 'relative',
				'margin-top': '101px',
				'width': 'auto',
				'top': '0',
				'left': '0',
				'overflow': 'auto',
				'height': '100%',
				'margin-right': '-50px'
			});


/*
		$(window).scroll(function(e)
		{
			scroll();
		});

		$(window).resize(function(e)
		{
			scroll();
		});

		function scroll()
		{
			var offset = $(window).scrollTop();
			var windowsHeight = $(window).height();
			var bottom = offset + windowsHeight;
			var topPosition = ($infotext.offset()).top;

			if ( bottom < topPosition ) {
				return;
			}
			$(window).scrollTop((topPosition-windowsHeight));					
		}
*/
	})();
});

$(document).ready(function() {
	$('.ui-usersense').focus(function() {

		if ( 'password' == $(this).attr('type') ) {
			if ( 'password' == $(this).val() ) {
				$(this).val("");
			}
			return;
		}

		if(!$(this).data("value")) {
			$(this).data("value", $(this).val());
		}

		if($(this).val() === $(this).data("value")) {
			$(this).val("");
		}
	});

	$('.ui-usersense').blur(function() {
		if ( 'password' == $(this).attr('type') ) {
			if ( 0 < $(this).val().length ) {
				return;
			}

			$(this).val('password'); return; 
		}

		if(!$(this).val() || 1 > $(this).val().length) {
			$(this).val($(this).data("value"));
		}
	});

	$('form').submit(function() {
		$(this).find('.ui-usersense').each(function(i) {
			if ( 'password' == $(this).attr('type') ) {
				return;
			}

			if($(this).data("value")) {
				$(this).data("value", $(this).val());
			}
			if($(this).value == $(this).data("value")) {
				$(this).val("");
			}
		})
	});
});
