$(document).ready(function(){
	
	$("a[rel^='gal']").prettyPhoto({
		theme: 'elbepark', 
		default_width: 680
	});
	
/*	
	$('.cycle-files').cycle({ 
		fx:     'fade', 
		speed:   1000, 
		timeout: 3000
	});
*/	
	
	
	$('.sl').each(function()
	{
    var f = 60;
    var h = $(this).height();
//    alert(h);
    var n = Math.ceil(h / f);
    h = n * f;
    
    $(this).css('height', h);
    
    $(this).find('p.lk').css('height', h);
	});
	
/*
var weg = 0;
$(".ex").hover(
function()
{
weg = weg+1;
$(this).expose({color: '#12549c'}).load();
}
);



$(".ex").mouseout(
function()
{
weg = weg - 1;
if(weg == 0)
{
$.mask.close();
}
}
);
*/
	// Expose

  $(".ex").hover(
    function()
    {
      $(this).expose({color: '#12549c', opacity: 0.5, loadSpeed: "fast"}).load();
    }, 
    function()
    {
      $.mask.close();
    }
  );

	
	

	$(".slide").scrollable(
	{
    next: "li .next",
    prev: "li .prev", 
    speed: "normal", 
    circular: true
	}).autoscroll({ autoplay: true, interval: 5000 });
	
	
	
  $('.img.ani').hover(function()
  {
    $(".text", this).stop().animate({bottom:'0px', display: 'block'},{queue:false, duration:300});
  },
  function()
  {
    var h = $(".text", this).height();
    $(".text", this).stop().animate({bottom: '-' + h + 'px', display: 'none'},{queue:false, duration:300});
  });
	
	
	
	$('.xform form').each(function() {
		var $form = $(this);
		
    $('input[type=text]').focus(function() {
      $(this).parent().addClass('formfocus');
    });
    
    $('input[type=text]').blur(function() {
      $(this).parent().removeClass('formfocus');
    });
		
    $('textarea').focus(function() {
      $(this).parent().addClass('formfocus');
    });
    
    $('textarea').blur(function() {
      $(this).parent().removeClass('formfocus');
    });
  });
	
/*  
  // DOMContentLoaded
  $(function() {
    
    // bind radiobuttons in the form
    var $filter = $('#filter-cats a');
  
    // get the first collection
    var $tenants = $('#tenants');
  
    // clone tenants to get a second collection
    var $data = $tenants.clone();
  
    // attempt to call Quicksand on every form change
    $filter.click(function(e)
    {

/      $.get( $(this).attr('href'), function(data)
      {
        $('#tenants').quicksand( $(data).find('#tenants li'),
        {
          duration: 800,
          easing: 'easeInOutQuad',
          attribute: function(v)
          {
            return $(v).find('li').attr('rel');
          }
        });
      });
      e.preventDefault();  
/      
      var $rel = $(this).attr('rel');

      if ($rel < 1)
      {
        var $filteredData = $data.find('li');
      }
      else
      {
        var $filteredData = $data.find('li[rel=' + $rel + ']');
      }
      
  
      // finally, call quicksand
      $tenants.quicksand($filteredData, {
        duration: 800,
        adjustHeight: 'dynamic',
        easing: 'easeInOutQuad',
        attribute: function(v)
        {
//          return $(v).find('li').attr('rel');
          return $(v).find('img').attr('src');
        }
      });

    });
  
  });
*/
	
	
});



// -------------------------------------------------------------------------------------------------------------------
function popMeUp(link, name, posx, posy, width, height, extra)
{
  
  $window = window.open(link, name, 'width=' + width + ', height=' + height + ', ' + extra);
  $window.moveTo(posx,posy);
  $window.focus();
}



// -------------------------------------------------------------------------------------------------------------------
function openRadio(link)
{
  var name = 'radiopopup';
  var width = 321;
  var height = 120;
  var extra = 'toolbar=no, location=no, directories=no, status=0, resizable=no, scrollbars=no, menubar=no';
  var posx = parseInt((screen.width - width - 50));
//  var posy = parseInt((screen.height - height)) - 24;
  var posy = 100;

  // newWindow (name,link,posx,posy,width,height,extra);
  popMeUp(link, name, posx, posy, width, height, extra);
}




// page init
$(document).ready(function(){
	initFormValidation();
});
// form validation
function initFormValidation() {
	var _errorClass = 'warning';
	var _regEmail = /^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/;
	var _regEmails = /^([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4})+([, ]+[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4})*$/;
	var _regPhone = /^[69]{2}[0-9]{8}$/;
	var _regNum = /^[0-9]+$/;
	var _regDay = /^(([0]{1}[1-9]{1})|([1-9]{1})|([1-2]{1}[0-9]{1})|([3]{1}[0-1]{1}))$/;
	var _regMon = /^(([0]{1}[1-9]{1})|([1-9]{1})|([1]{1}[0-2]{1}))$/;
	var _regYear = /^[19]{2}[0-9]{2}$/;
	
//	$('form.validate-form').each(function(){
	$('.xform form').each(function(){
		var _form = $(this);
		function checkFields() {
			
			var _flag = false;
			_form.find('.'+_errorClass).removeClass(_errorClass);

			// fields validation
			_form.find('input.required-email').each(function(){
				if(!_regEmail.test($(this).val())) addError($(this));
			});
			_form.find('input.required-day').each(function(){
				if(!_regDay.test($(this).val())) addError($(this));
			});
			_form.find('input.required-mon').each(function(){
				if(!_regMon.test($(this).val())) addError($(this));
			});
			_form.find('input.required-year').each(function(){
				if(!_regYear.test($(this).val())) addError($(this));
			});
			_form.find('textarea.required-many-emails').each(function(){
				if(!_regEmails.test($(this).val())) addError($(this));
			});
			_form.find('input.required-phone').each(function(){
				if(!_regPhone.test($(this).val())) addError($(this));
			});
			_form.find('input.required-num').each(function(){
				if(!_regNum.test($(this).val())) addError($(this));
			});
			_form.find('input.required, textarea.required').each(function(){
				if(!$(this).val().length || $(this).val() == $(this).attr('alt')) addError($(this));
			});
			_form.find('input.required-chek').each(function(){
				if (!$(this).is(':checked')) {
					$(this).parent('p').addClass('warning');
					_flag=true;
				}
			});
			_form.find('div.required-radio').each(function(){
				var _test = false;
				$(this).find('input[type=radio]').each(function(){
					if ($(this).is(':checked')) _test = true;
				});
				if (!_test) {
					$(this).find('div.row3 > span').eq(0).addClass('error-chk');
					_flag=true;
				}
			});

			// error class adding
			function addError(_obj) {
				var ter = _obj.attr('id');
				var errLab = _form.find('label[for='+ter+']');
				errLab.addClass(_errorClass);
				_flag=true;
			}
			return _flag;
		}
		
		/*
		CheckFormular() {
			if(checkFields()) {
				return false;
			}
			else {
				ProgressStart();
			}
		}
		*/
		$('#FileSubmit a').click(function() {
			_form.find('div.form-error').hide();
			if(checkFields()) {
				_form.find('div.form-error').show();
				return false;
			}
			else {
				ProgressStart();
			}
		});
		
/*		
		// catch form submit event
		_form.submit(function(){
			_form.find('span.error-box').hide();
			if(checkFields()) {
				_form.find('span.error-box').show();
				
				return false;
			}
			_form.find('input.submit').addClass('thanks');
		});
*/		
	});
}
