var startContact = function() {
     
	   $('#contactform input[type=text],#contactform textarea').css({width:'300px'}).eq(0).focus();
	   $('#contactform').submit(function(e){
		  var a = $(this).find('select[name=callback]');
		  var b = $(this).find('input[name=phone]');
		  if ( a.val() != 'no' && b.val() == '' ) {
			 alert('Sie würden gerne zurückgerufen werden. Bitte hinterlassen Sie eine Telefonnummer.');
			 e.preventDefault();
			 b.focus();
		  }
	   });
};
window['startContact'] = startContact;
var startContactHelp = function() {
    
    $('#contactform input[type=text],#contactform textarea').css({
	   width:'300px'
    }).eq(0).focus();
    $('#contactform').submit(function(e){
	   var a = $(this).find('select[name=type]');
	   if ( a.val() == 0 ) {
		  alert('Bitte wählen Sie einen Grund für Ihre Anfrage aus.');
		  e.preventDefault();
	   }
    });
};
window['startContactHelp'] = startContactHelp;
var startPreview = function() {
    var scrI = $('#scrollinner');
    var scrC = 0;
    scrI.children().css({
	   border:0,
	   margin:0,
	   padding:0,
	   position:'absolute'
    }).hide().eq(0).show();
    var scrF = function() {
	   var ch = scrI.children();
	   ch.css({
		  'z-index':1
	   });
	   ch.eq(scrC).css({
		  'z-index':5
	   });
	   scrC++;
	   if ( scrC >= scrI.children().length ) scrC = 0;
	   ch.eq(scrC).hide().css({
		  'z-index':10
	   }).fadeIn(1000);
    };
    window.setInterval(scrF, 4000);
};
window['startPreview'] = startPreview;
var checkIfTourImagesLoaded = function() {
    $('#tour-pic-small,#tour-pic-big').load(function(){
	   $(this).data('imageready',true);
    }).each(function(){
	   if(this.complete)
		  $(this).trigger("load");
    });
    checkifTourImagesReady();
};
var checkifTourImagesReady = function () {
    var a = $('#tour-pic-small');
    var aa = a.data('imageready') == true || a.complete;
    var b = $('#tour-pic-big');
    var bb = b.data('imageready') == true || b.complete;

    if ( aa && bb )
	   startTour();
    else {
	   window.setTimeout(checkifTourImagesReady, 250);
    }
}
var startTour = function () {
    var psC = $('#tour-pic-small-container');
    var psBC = $('#tour-pic-big-container');
    var pic = $('#tour-pic-big');
    var psCpic = psC.find('img:first');

    var psCWidth = psCpic.width();
    var psCHeight = psCpic.height();

    var roW = Math.ceil(psCpic.width()* psBC.width() / pic.width());
    var roH = Math.ceil(psCpic.height()*psBC.height() / pic.height());
    var ro = $('<div>&nbsp;</div>').appendTo(psC).css({
	   background:'transparent',
	   border:'2px solid #00aa00',
	   position:'absolute',
	   top:'0px',
	   left:'0px',
	   width:roW+'px',
	   height:roH+'px'
    });

    var ratioW = pic.width() / psCpic.width();
    var ratioH = pic.height() / psCpic.height();

    psC.mousemove(function(e){
	   var m = $(this);
	   var l = Math.ceil(e.pageX - m.offset().left);
	   var t = Math.ceil(e.pageY - m.offset().top);

	   l = l - (roW / 2);
	   t = t - (roH / 2);
	   if ( l < 0 ) l = 0;
	   if ( t < 0 ) t = 0;
	   if ( l + roW  > psCWidth )  l = psCWidth - roW;
	   if ( t + roH > psCHeight ) t = psCHeight - roH;
	   ro.css({
		  top:t+'px',
		  left:l+'px'
	   });

	   t = -1 * Math.ceil(t * ratioH);
	   l = -1 * Math.ceil(l * ratioW);
	   pic.css({
		  top:t+'px',
		  left:l+'px'
	   });
    });
};

$.fn.formTransform = function() {
    $('input[type=text], input[type=password], textarea',this).each(function() {
	   if ( !$(this).hasClass('inputText') )
		  $(this)
		  .addClass('inputText')
		  .hover(function(){
			 $(this).addClass('inputText-hover');
		  },function(){
			 $(this).removeClass('inputText-hover');
		  })
		  .focus(function(){
			 $(this).addClass('inputText-focus');
		  })
		  .blur(function(){
			 $(this).removeClass('inputText-focus');
		  });
    });
    $('input[type=submit],input[type=reset],input[type=button],button',this).each(function() {
	   if ( !$(this).hasClass('inputButton'))
		  $(this)
		  .addClass('inputButton')
		  .hover(function(){
			 $(this).addClass('inputButton-hover');
		  },function(){
			 $(this).removeClass('inputButton-hover');
		  });
    });
    $('select',this).addClass('inputSelect');
};


