$(document).ready(function () {
    
    $('#shadowLayer').css('opacity', 0.9);
    
    // open upload form
    
        $('#enter_upload').click(function (event) { 
        
            event.preventDefault();
            
            $('#shadowLayer').css('display', 'block');
            $('#shadowLayer').css('width', getWindowWidth());
            $('#shadowLayer').css('height', getWindowHeight());
        
            $('#shadowLayer').animate({opacity: 0.9}, 'def', function () {
            
                $('#uploadForm').fadeIn();
                $('#uploadForm').css('left', ((getWindowWidth()/2)-448)+'px');
            });
            
        });    
    
    // close upload form
        
        $('#uploadForm #closebutton').click(function (event) { 
        
            event.preventDefault();
        
            $('#uploadForm').fadeOut('def', function () {
            
                $('#shadowLayer').fadeOut();
            });
        }); 
		
	// impressum
        $('a#impressum').click(function (event) { 
        
            event.preventDefault();
            
            $('#shadowLayer').css('display', 'block');
            $('#shadowLayer').css('width', getWindowWidth());
            $('#shadowLayer').css('height', getWindowHeight());
        
            $('#shadowLayer').animate({opacity: 0.9}, 'def', function () {
            
                $('#impressumBox').fadeIn();
                $('#impressumBox').css('left', ((getWindowWidth()/2)-227)+'px');
            });
            
        });
		
	// close impressum
        
        $('#impressumBox #closebutton2').click(function (event) { 
        
            event.preventDefault();
        
            $('#impressumBox').fadeOut('def', function () {
            
                $('#shadowLayer').fadeOut();
            });
        }); 

	// gewinnspiel
        $('a#gewinnspielbutton').click(function (event) { 
        
            event.preventDefault();
            
            $('#shadowLayer').css('display', 'block');
            $('#shadowLayer').css('width', getWindowWidth());
            $('#shadowLayer').css('height', getWindowHeight());
        
            $('#shadowLayer').animate({opacity: 0.9}, 'def', function () {
            
                $('#gewinnspielForm').fadeIn();
				$('#gewinnspielForm').css('left', ((getWindowWidth()/2)-448)+'px');
            });
            
        });
		
	// close gewinnspiel
        
        $('#gewinnspielForm #closebutton3').click(function (event) { 
        
            event.preventDefault();
        
            $('#gewinnspielForm').fadeOut('def', function () {
            
                $('#shadowLayer').fadeOut();
            });
        }); 		
        
		
    // open rollover
    
        $('#gallery .thumbnail').mouseenter(function (event) { 
        
            event.preventDefault();
            event.stopPropagation();
            
            $('.thumbnail').css('z-index','0');
            $(this).css('z-index','998');
            
            $(this).children('.rollover').show();
            
        });    
    
    // close rollover
        
        $('#gallery .thumbnail').mouseleave(function (event) { 
        
            event.preventDefault();
            event.stopPropagation();

            
            $(this).children('.rollover').hide();
            
            $('.thumbnail').css('z-index','1');
            $(this).css('z-index','1');
            
        });
        
        $('#gallery .rolloverClose a').click(function (event) { 

            event.preventDefault();
            event.stopPropagation();

            $(this).parent().parent().parent().hide();
            $(this).parent().parent().parent().css('z-index','1');
            $(this).css('z-index','998');
        }); 

});

// Positioning

    window.onresize = function(){

        $('#uploadForm').css('left', ((getWindowWidth()/2)-448)+'px');
		$('#impressumBox').css('left', ((getWindowWidth()/2)-227)+'px');
        $('#shadowLayer').css('width', getWindowWidth());
        $('#shadowLayer').css('height', getWindowHeight());
        
    };

    function getWindowHeight(win) { if (win == undefined) win = window; if (win.innerHeight) { return win.innerHeight; } else { if (win.document.documentElement && win.document.documentElement.clientHeight) { return win.document.documentElement.clientHeight; } return win.document.body.offsetHeight; } }
    function getWindowWidth(win)  { if (win == undefined) win = window; if (win.innerWidth)  { return win.innerWidth; }  else { if (win.document.documentElement && win.document.documentElement.clientWidth)  { return win.document.documentElement.clientWidth; }  return win.document.body.offsetWidth; } }
	
	
	
// E-mail-functions
function showerror(containerID,error,simple)
{
 	 var container = document.getElementById(containerID);
	 
	 if (simple == '') { 
	 
	 	container.innerHTML = '<span class="highlight"><strong>Bitte f&uuml;lle die markierten Felder aus:<br />' + error + '</strong></span>';
	 }
	 else {
		 
	 	container.innerHTML = '<span class="highlight"><strong>Bitte f&uuml;lle die markierten Felder aus oder &uuml;berpr&uuml;fe Deine Eingaben.<br /></strong></span>';
	 }
	
	container.style.display = 'block';	
	return true;
}


// Highlights a required field
function highlightElement(el) {
	el.style.borderColor = "#CC0000";
	el.style.backgroundColor = "#FEF1F2";
}

// Rücksetzen des Feldes, wenn zwischenzeitlich der eingegebene Wert korrigiert wurde
function dehighlightElement(el) {
	el.style.borderColor = "#CCCCCC";
	el.style.backgroundColor = "#FFFFFF";
}

// Validates the given input field
function validate(el, msg) {
	if (el.value == "") {
		highlightElement(el);
		return msg + "\n";
	} else {
		dehighlightElement(el);
		return "";
	}
}


// Validates the given email address
function checkEmail(s) {
	var a = false;
	var res = false;
	if(typeof(RegExp) == 'function') {
  		var b = new RegExp('abc');
  		if(b.test('abc') == true){a = true;}
  	}
	if(a == true) {
		reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
			'(\\@)([a-zA-Z0-9\\-\\.]+)'+
			'(\\.)([a-zA-Z]{2,4})$');
		res = (reg.test(s));
	} else {
		res = (s.search('@') >= 1 &&
			s.lastIndexOf('.') > s.search('@') &&
			s.lastIndexOf('.') >= s.length-5)
	}
	return(res);
}	