$(document).ready(function() { 
	
	// ajax form
	if ($('.ajax_form').length) { 
		$('.ajax_form').ajaxForm({
			url:       'ajax.php',
			type: 	   'post',
		    dataType:  'json',
		    beforeSubmit:  function() {
			    $('#feedback').remove();
		        $('body').append('<div id="ajax-loading" style="position: fixed; left: 50%; color: #000; z-index: 1000; padding: 10px; font-weight: bold; width: 140px; margin-left: -70px; top: 40%; background-color: #FFF;"><img src="http://www.cicloteque.ro/wp-content/themes/cicloteque/images/ajax-loader.gif" alt="loading" /> Loading...</div>');
		    },
		    success: function(data, status, target_form) {
			    $('#ajax-loading').remove();
				if(data.error) {
					$('.ajax_form').before(data.message);
					return false;
				} else {
					if(data.message != '') {
						$('.ajax_form').before(data.message);
						if(data.redir != '') {
							$('#feedback').animate({opacity: 1.0}, 4000).fadeOut('slow', redir(data.redir));
						} else {
							$('#feedback').animate({opacity: 1.0}, 4000).fadeOut('slow', function() { $('#feedback').remove() });
						}
					} else {
						reloc();
					}
				}
			}
		});
	}
	
	// slider
	$('#slider').nivoSlider({
		effect:'fade',
		animSpeed:300,
		pauseTime:4000,
		directionNav:false,
		directionNavHide:true,
		captionOpacity:0.9
	});
	
});

function reloc(){
	window.setTimeout(function() {location.reload(true)}, 1);
}

function redir(uri){
	window.setTimeout(function() {window.location = uri});
}