/**********************************************
/	Funktionen zum Scrollen
**********************************************/

var ScrollBox;
var ScrollCont;
var clipHeight;
var referencePos = 1;


function scrollInit(){
	if ( document.getElementById('ScrollContainer') ){
		ScrollBox = document.getElementById('ScrollText');
		ScrollCont = document.getElementById('ScrollContainer');
		clipHeight = ScrollCont.offsetHeight;
		scrollHeight = ScrollBox.offsetHeight;
		$('#ScrollText').animate( {top: "0px"} );
	}
}


function scrollDown(){
	var pos_y = parseInt( ScrollBox.style.top , 10 );
	if ( (2 * clipHeight - pos_y ) < scrollHeight ){
		move_y = pos_y - clipHeight;
	}
	else{
		move_y = clipHeight - scrollHeight;
	}
	$('#ScrollText').animate( {top: move_y+"px"} );
}

function scrollUp(){
	var pos_y = parseInt( ScrollBox.style.top , 10 );
	if ( (pos_y + clipHeight) < 0 ){
		move_y = pos_y + clipHeight;
	}
	else{
		move_y = 0;
	}
	$('#ScrollText').animate( {top: move_y+"px"} );
//	new Effect.Move(document.getElementById('ScrollText'), {x: 0, y: move_y , mode: 'absolute'});
}

function reference(pos){
	document.getElementById('reference_' + referencePos).className = "";
	referencePos = parseInt( pos , 10 );
	document.getElementById('reference_' + referencePos).className = "selected";
	if ( (referencePos - 6) > 0 ) {

		if ( (referenceMax - referencePos) < 5 ) move_y = ( 11 - referenceMax ) * 16;
		else move_y = ( 6 - pos ) * 16;
		$('#ScrollList').animate( {top: move_y+"px"}, "slow" );
	}
	else{
		$('#ScrollList').animate( {top: "0px"}, "slow" );
	}

	move_y = ( 1 - pos ) * clipHeight;
	$('#ScrollText').animate( {top: move_y+"px"}, "slow" );
	return false;
}

function referenceUp(){
	if ( referencePos > 1 ) {
		reference( referencePos - 1 );
	}
	return false;
}

function referenceDown(){
	if ( referencePos < referenceMax ){
		reference( referencePos + 1 );
	}
	return false;
}

function ContactForm(){

	var arrayPageSize = getPageSize();

	$('#ContactFormOverlay').css({ height: '100%', opacity: 0, display: "block" });

	$('#ContactFormOverlay').animate( { opacity: 0.7 }, 700 , function() { $('#ContactFormBox').css({ height: "10px", display:"block" }); $('#ContactFormBox').animate({ height: "400px" },700)});

	$('#ContactFormOverlay').click( function(){ hideContactForm() });

	var myAjax = new Ajax();
	myAjax.url = "/ajax.php5";
	myAjax.params = "mode=kontaktformular";
	myAjax.method = 'get';

	myAjax.onSuccess=function(txt) {
		if ( HasError( txt ) ) {
			ErrorHandler( GetError(txt) );
		}
		else{
			$( '#ContactFormBox' ).html(txt);
			$( '#nachricht' ).focus();
		}
	}

	myAjax.onError=function(msg) {
	  alert(msg);
	}

	myAjax.doRequest();

	return false;

}


function hideContactForm(){
	$( 'ContactFormBox' ).innerHTML = "";
	
	$('#ContactFormBox').animate({ height: "10px" },700, function(){ $('#ContactFormBox').css({ display:"none" }); $('#ContactFormOverlay').animate( { opacity: 0 }, 700, function(){ $('#ContactFormOverlay').css({ display:"none" }) } ) });
	
	
}

function sendMail( f ){
	/**
	* Reguläre Ausdrücke zum Testen von Formulareingaben
	*/
	var exprFon = /^[0-9\(\)\-\/\s]+$/;
	var exprEmail = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([a-z]{2,3}))$/;
	var exprNotEmpty = /.+/;


	if ( ! ( exprNotEmpty.exec(document.getElementById("name").value ) ) ){
		alert("Bitte geben Sie Ihren Namen ein.");
		$("name").focus();
		return false;
	}

	if ( ! ( exprEmail.exec(document.getElementById("email").value ) ) ){
		alert("Bitte geben Sie eine gültige E-Mailadresse ein.");
		$("email").focus();
		return false;
	}

	paramArray = new Array();
	paramArray = paramArray.concat( getFormValues( f , 'input' ) );
	paramArray = paramArray.concat( getFormValues( f ,  'textarea' ) );

	var myAjax = new Ajax();
	myAjax.url = "/ajax.php5";
	myAjax.params = paramArray.join("&")
	myAjax.method = 'post';

	myAjax.onSuccess = function(txt) {
		if ( HasError( txt ) ) {
			ErrorHandler( GetError(txt) );
		}
		else{
			$( '#ContactFormBox' ).html(txt);
		}
	}

	myAjax.onError = function(msg) {
		alert(msg);
	}

	myAjax.doRequest();

	return false;

}


/**
*
*/
function getPosition( element ){
  var tagname="" , x=0 , y=0;
  while ( ( typeof(element) == "object" ) && ( typeof( element.tagName ) != "undefined" ) ){
    y += element.offsetTop;
    x += element.offsetLeft;
    tagname = element.tagName.toUpperCase();
    if ( ( tagname == "BODY" ) || ( tagname == "HTML" ) )  element=0;
    if ( typeof( element ) == "object" ){
      if ( typeof( element.offsetParent ) == "object" ) element = element.offsetParent;
      if ( element == null ) element=0;
    }
  }
  position=new Object();
  position.x=x;
  position.y=y;
  return position;
}

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	pageHeight = yScroll;

	pageWidth = xScroll;

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

$(document).ready(function(){
  $("#pageflip").hover(function() { //On hover...
	  $("#pageflip img , .msg_block").stop()
		  .animate({ //Animate and expand the image and the msg_block (Width + height)
			  width: '307px',
			  height: '319px'
		  }, 500);
	  } , function() {
	  $("#pageflip img").stop() 
		  .animate({
			  width: '150px',
			  height: '156px'
		  }, 220);
	  $(".msg_block").stop() 
		  .animate({
			  width: '150px',
			  height: '150px'
		  }, 200); //Note this one retracts a bit faster (to prevent glitching in IE)
  });
  window.setTimeout( 
    function(){
	$("#pageflip img").animate({ width: '307px', height: '319px' }, 1000); 
	$(".msg_block").animate({ width: '307px', height: '319px' }, 1040, function(){ 
	  window.setTimeout(
	    function(){
	      $("#pageflip img").animate({ width: '150px',height: '156px'}, 530);
	      $(".msg_block").animate({ width: '150px', height: '150px'}, 500);
	    }
	  , 1000);
	} ); 
    } 
    , 1784
  )
});



