function formValidate($thisForm){
		var $fields = $thisForm.find('input[type=text], input[type=password], textarea').not('.ffv-opt');
		
		var validate = true;
		$fields.each(function(){
			var email_filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
			var v = 1;
			if ($(this).attr('name') == 'email' || $(this).attr('name') == 'e-mail') {
				if (!email_filter.test($(this).val())) {
					validate = false;
					v = -1;
				}
			}
			if (!$(this).val() || $(this).val() == '' || $(this).val() == $(this).get(0).defaultValue) {
				validate = false;
				v = -1;
			}
			if (v == -1) {
				$(this)
					.addClass('ff-notvalid')
					.bind("focus", function(){
						$(this).removeClass('ff-notvalid');
					});
			}
		})
		
		if (validate) {return true;}
		return false;
}

$(document).ready(function(){
	$('#submit').click(function(e){
		e.preventDefault();
		$form = $(this).parents('form');
		$form.find('.error').remove();
		var email_filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		var formIsValid = true;
		
		
		$form.find('.input input').each(function(){
			$(this).parents('.input').find('.error').remove();
			
			if($(this).hasClass('required') && ($(this).val() == '')){
				$(this).parents('.input').append('<div class="error">This field is required</div>');
				formIsValid = false;
			}
			if($(this).is('#email') && (!email_filter.test($(this).val()))){
				$(this).parents('.input').append('<div class="error">You should type a valid email</div>');
				formIsValid = false;
			}
		});
		
		
		if(!formIsValid){
			return false;
		}
		
		
		$.post ('thanks-subscription.htm', $form.serialize(), function(data,status){
				var txt='Something goes wrong';
				if(status=='success'){
					txt = '<span class="feed-res">Thank you for subscription!</span>';
					
				}
				
				$form.html(txt);
				
			}, 'html');
	
	});
	/* Google Analytics goals */
	$('a[href^=to/]').attr('target', '_blank');/*.click(function(){
		var href = $(this).attr('href');
		if (typeof(_gaq)!='undefined' && href.indexOf('//casino/')==-1) {
			trackPageview('click/'+href.replace(/http:\/\/[^\/]+\/[^\/]+/i, ''));
		}
		return true;
	});*/
	
	$('.ff-validate').submit(function(){
		return formValidate($(this));
	});
});

$(window).load(function(){
		$('.img_onpage').each(function(){
			var thisAlign = $(this).attr('align');
			var thisText = $(this).attr('title');
			var thisWidth = $(this).width();
			
			$(this)
					.wrap('<div class="imgwrap imgwrap_'+thisAlign+'"></div>')
					.attr('align', '');
											   
			if ($(this).attr('title')) {
					$(this).after('<div class="img_title" style="width:'+thisWidth+'px">'+thisText+'</div>');
			}
		});
		$('.imgwrap:first-child').css('margin-top', '10px');
	});
