/* Javascript Document Ready */
$(document).ready(function(){

	$('.child').hide().css('visibility','visible');
	
	$('.parent').hover(function(){
		$(this).stop();
		$(this).parent('div').find('.child').delay(500).show();	
	},function(){
		$(this).stop();
		$(this).parent('div').find('.child').delay(500).hide();
	});

	$('.child').hover(function(){
		$(this).stop();
		$(this).parent('div').find('.parent').addClass('hover');
		$(this).show();
	},function(){
		$(this).stop();
		$(this).parent('div').find('.parent').removeClass('hover');
		$(this).hide();
	});

	if(document.getElementById("scroll"))
	{
		// initialize scrollable and return the programming API
		scroller = $("#scroll").scrollable({
			items: '#navigator',
			circular: true,
			keyboard: false
		// use the navigator plugin
		});
		
		stopped = true; 
		api = scroller.navigator().data("scrollable");
		api.begin();
		
		$('#tabs').hide();
		$('#scroll').hide().delay(1500).fadeIn(500);
		$('#tabs').delay(4000).fadeIn(500);
		$('#tabs').delay(4000).queue(function(){
			if (stopped)
			{
				api.seekTo(1);
				scroller.autoscroll({interval: 10000}); 
			}
		});
		$('#tabs a').click(function(){
			scroller.stop();	
			stopped = false;
		})
	}
	
	$('.adminbuttons').hide();
	/* ON Hover Show Adminbuttons */
	$('.adminbuttons').parent('div').hover(function(){$(this).children('.adminbuttons').show()},
								function(){$(this).children('.adminbuttons').hide()});
	
	/* Activate Inactive Elements */
	$('.inactive').each(function(){
		if ($(this).attr('value'))
		{
			$(this).removeClass('inactive');  
	  		$(this).addClass('active');  
		}
		else
			$(this).attr('value',$(this).attr('default'));
	});

	$('.inactive').focus(function(){  
	  $(this).removeClass('inactive');  
	  $(this).addClass('active');
	  
	  val = $(this).attr('value');
	  def = $(this).attr('default');
	  if (def && (val.replace('\r\n','') == def.replace('\r\n','')))
		 $(this).attr('value','');   
	});
  
	$('.active').live('focusout',function(){
	  if ( ($(this).val()==$(this).attr('default')) || ($(this).val()=='') ) 
	  {
		$(this).removeClass('active');
		$(this).addClass('inactive');
		$(this).attr('value',$(this).attr('default'));  
	  }
	});
	
	/* Formulare validieren Client */
	$('form[validate="true"]').each(function(){$(this).validate();});
	
	$('form').submit(function(){
		$(this).find('input[type="text"]').each(function(){
			if ($(this).attr('value') == $(this).attr('default'))
				$(this).attr('value','');		
		});
		$(this).find('textarea').each(function(){
			val = $(this).attr('value');
			def = $(this).attr('default');
			if (def && (val.replace('\r\n','') == def.replace('\r\n','')))
				$(this).attr('value','');
		});	
		
	});
	
});
