// JavaScript Document
function doNothing(){}

$(document).ready(function(){

	$('.show_tips').hover(
			function() {
				$(this).children('.tips').fadeIn('slow');
			},
			function() {
				$(this).children('.tips').fadeOut('slow');
	});


	$('.show_menu').css({ marginLeft:'-90px' });
/*
	$('.show_menu').animate({
			marginLeft:'-90px',
			}, 1000);
*/	
	$('.menu_switch').hover(
			function() {
				$(this).children('.show_menu').animate({marginLeft:'0px'}, 500);
			},
			function() {
				$(this).children('.show_menu').animate({marginLeft:'-90px'}, 1000);
			
	});
	
	//Then initialize prettyPhoto. http://www.no-margin-for-errors.com/projects/prettyPhoto/
	 $("a[rel^='prettyPhoto']").prettyPhoto();
	 
	//portfolio play with thumbnails
	if ($('#port_back').size() > 0) {
		$('#port_back').children().css({'opacity':'0.8'});
		
  	$('#port_back').children().hover(function(){
  		$(this).css({
  			'opacity': '1.0'
  		});
  	}, function(){
  		$(this).css({
  			'opacity': '0.8'
  		});
  	});
  }
//contact FORM with validation
  var options = { 
	beforeSubmit: validate,
    target:     '#divFeedback', 
    url:        'contact/sendMail', //url to sendMail controller
    success:    makeAnswer
	}; 
//change value for input hidden if js on
$('input.hidden').attr('value', 'isjs');

// pass options to ajaxForm 
	$('#checkForm').ajaxForm(options);

	function makeAnswer(){
		$('form#checkForm').slideUp();
		$('divFeedback').show('slow');
	}
//while this return false => form have wrong input. If ok then do ajax
 function validate(formData, jqForm, options){
 	if ($("form#checkForm").valid() == false) {
 		return false;
 	}
 	else { //form is ok, do things but only once!
			$('p.submitButton input').hide();
			$('p.submitButton input').parent().append("<img src='images/shwartz/loading.gif' alt='.' />");	
		}
	} 
 	  
  // validate register form on keyup and submit
  //http://docs.jquery.com/Plugins/Validation
  //$("#form_register form").validate({
  $("form#checkForm").validate({
    rules: {
      TradeName: "required",
      Telephone: "required",
      Address1: "required",
      TownCity: "required",
      Country: "required",
      ZipCode: "required",
      Title: "required",
      FirstName: "required",
      Textarea: "required",
      LastName: "required",
      Email: {
        email: true,
				required: true
      },
      JobTitle: "required",
      password: {
        required: true,
        minlength: 5
      },
      psw: {
        required: true,
        minlength: 5
      },
      confirmPassword: {
        required: true,
        minlength: 5,
        equalTo: "#password"
      },
      Captcha: {
      		required:true,
      		equalTo: "#captcha"
      		},
      username: "required",
      usr: "required"
    },
    messages: {
      TradeName: "Please enter your Company name",
      Telephone: "Please enter your telephone",
      Address1: "Please enter your address",
      TownCity: "Please enter your town city",
      Country: "Please enter your country",
      ZipCode: "Please enter your postal code",
      Title: "Please enter your title",
      FirstName: "Please enter your first name",
      Textarea: "Please enter enquiry",
      LastName: "Please enter your last name",
      Email: {
        required: "Please enter your email",
        email: "Please enter a valid email address"
      },
      JobTitle: "Please enter your job title",
      password: {
        required: "Please enter your password",
        minlength: "Your password must be <br />at least 5 characters long"
      },
      confirmPassword: {
        required: "Please provide a password",
        minlength: "Your password must be <br />at least 5 characters long",
        equalTo: "Please enter <br />the same password as above"
      },
      Captcha: {
      	required: "Add numbers from image",
      	equalTo: "Numbers must be same"
     	},
      username: "Please enter your username"
    }
  });

//hide email address from spider

	$('span.mailme').each(function(index){
		$(this).attr("id", "mailNr" + index);
			var spt = $('span#mailNr' + index);
			var at = / at /;
			var dot = / dot /g;
			var addr = $(spt).text().replace(at,"@").replace(dot,".");
			$(spt).after('<a href="mailto:'+addr+'" title="Send an email">'+ addr +'</a>')
			.hover(function(){window.status="Send a letter!";}, function(){window.status="";});
			$(spt).remove();
		});
  
 /* if ($('a.zoom').size() > 0) { 
$("a.zoom").fancybox({
				'zoomSpeedIn'			:	500,
				'zoomSpeedOut'		:	500,
				'overlayOpacity'	:	0.8,
				'overlayColor'		:	'#000'
			});

}
*/
  
//end of script	 
});