var redirURL = '';
var Functions = {
	load: function(d){
		$('#'+loader_div).animate({height:'show'});
		$('#'+response_div).animate({height:'hide'},
			function(){
				$('#'+response_div).html('');
				$('#'+content_div).animate({height:'hide'},
					function(){
						$('#'+content_div).html('');
						$('#'+loader).fadeIn(
							function(){
								$.get(cf+'.php?action='+d,
								function(p){
									$('#'+loader).fadeOut(
										function(){
											$('#'+content_div).html(p);
											$('#'+content_div).animate({height:'show'});
											$('#'+loader_div).animate({height:'hide'});
										});
								},'script');
							});
					});
			});
	},
	form_send:function(){
		var values = $("#fcbform").serialize();
		$('#'+loader_div).animate({height:'show'});
		$('#'+response_div).animate({height:'hide'},
			function(){
				$('#'+response_div).html('');
				$('#'+content_div).animate({height:'hide'},
					function(){
						$('#'+content_div).html('');
						$('#'+loader).fadeIn(
							function(){
								$.getJSON(cf+'.php?'+values,
									function(d){
										$('#'+loader).fadeOut(
											function(){
												$('#'+response_div).html(d.msg);
												$('#'+response_div).animate({height:'show'});
												$('#'+loader_div).animate({height:'hide'});
												
												setTimeout("Functions.load('"+d.call+"');",1000);
											});
									});
							});
					});
			});
	},
	frame_send : function(){
		var values = $("#fcbform").serialize();
		$('#'+loader_div).animate({height:'show'});
		$('#'+content_div).animate({height:'hide'},
			function(){
				$('#'+loader).animate({height:'show'},
					function(){
						Functions.goto(cf+'.php?'+values,'iframe');	
					});
			});
	},
	framed_response : function(d){
		$('#'+response_div).hide();
		$('#'+loader).fadeOut(
			function(){
				$('#'+response_div).html(d.msg);
				$('#'+response_div).animate({height:'show'});
				$('#'+loader_div).animate({height:'hide'});
				if(d.call){
					setTimeout("Functions.load('"+d.call+"');",1000);	
				}
		});
	},
	goto:function(_url, _target) {
		window.open(_url, _target);
	},
	redirect:function() {
		this.goto(redirURL, '_self');
	},
	reload_it:function() {
		document.location.reload();
	},
	rateit:function(p){
		$('#vote').html('Sending...');
		$.getJSON('ajax.php?action='+p.action+'&id='+p.id+'&vote='+p.vote,
			function(d){
				$('#vote').html(d.msg);
				if(d.status == 0){
					$('#rating').html(d.rating);
					$('#votes').html(d.votes);
				}
			},'script');
	},
	validate:function(a){
		$.getJSON('register.php?action=validate&type='+a+'&value='+$('#'+a).val(),
			function(d){
				if(d.status == 1){
					$('#errored').html(d.msg);
					$('#'+d.field).removeClass('valid');
					$('#'+d.field).addClass('error');
					$('#profile [for='+d.field+']').removeClass('valid');
					$('#profile [for='+d.field+']').addClass('error');
					errors = 1;
				} else {
					errors = 0;
					$('#errored').html('');	
				}
			});
	},
	scrollTo:function(selector) {
        var targetOffset = $(selector).offset().top;
        $('html,body').animate({scrollTop: targetOffset}, 500);
    }
}