$(document).ready(function() {
	
	var imagelist = new Array();
	imagelist[0] = "../images/wm_logo_hover.png";
	imagelist[1] = "../images/redrbutton2.png";

	// vorzuladene Bilder werden nun in den neuen Array 'Bilder' geschrieben

	var image = new Array()

	function imageload()	
	{
  		for (i = 0; i < imagelist.length; i++) {
    		image[i] = new Image();
    		image[i].src = imagelist[i];
  		}
	}

	imageload();
	  	      	      	  		
    $(function() {
		$('.galery a').lightBox({ 
			txtImage: 'Bild',
			txtOf:	  'von'
		});
	});
			
      		
	function setupbox(e)
	{		
		//Cancel the link behavior  
	    e.preventDefault();  
	    var id = $(this).attr('href');    
	   	$('#mask').css({ 'width':'100%','height':'100%' });
	   //transition effect       
	   //$('#mask').fadeIn(1000);      
	   $('#mask').fadeTo("fast",0.8);    
	   
	   showBox(id);
	}
	
	function showBox(id)
	{
	   //Get the window height and width  
	   var winH = $(window).height();  
	   var winW = $(window).width();  
	           
	   //Set the popup window to center  
	   $(id).css('top',  winH/2-$(id).height()/2);  
	   $(id).css('left', winW/2-$(id).width()/2);  
	   
	   //transition effect  
	   $(id).fadeIn(2000);   
	   $(id).show();
	}
	
    //select all the a tag with name equal to modal  
    $('a[name=modal]').live('click',setupbox);  
     
    //if close button is clicked  
    $('.window .close').click(function (e) {  
       //Cancel the link behavior  
       e.preventDefault();  
       $('#mask, .window').hide();  
    });       
     
    //if mask is clicked  
    $('#mask').click(function () {  
       $(this).hide();  
       $('.window').hide();  
    });
    
    $('#submitlogin').click(function(){
   		var validator = $('#user_login_form').validate();	 	
  		
  		if(validator.form())
		{
			$.get('index.php',$('#user_login_form').serialize(),function(response){
			
				if(response.error)
				{
					$('#user_login_form .alert').removeClass('hide');
				}
				else
				{  
					$('.window').hide(); 
					showBox('#send_message');
					$('#contactlink').attr('href', '#send_message');
					$('#topmenu .first a').attr('href', 'login');
					$('#topmenu .first a').text('Infocenter');
					$('#topmenu .second a').attr('href', 'logout');
					$('#topmenu .second a').text('Logout');
				}			
			});				
		}						
    });
	
	$('#submitmsg').click(function(){
   		var validator = $('#sent_msg_form').validate();	 	
  		
  		if(validator.form())
		{
			$.get('index.php',$('#sent_msg_form').serialize(),function(response){
			
				if(response.error)
				{
					$('#sent_msg_form .alert').removeClass('hide');
				}
				else
				{  
					$('.window').hide(); 
					showBox('#message_sent');
				}			
			});				
		}						
    });
       
 }); 
