/**
 * Initialize $.CORE in case it's not present
 */
if(typeof $.CORE == "undefined") {
	$.CORE= Object;
};

/**
 * Facebook
 */
$.CORE.fb = {
	
	appId : null,
	appLocation : null,
	
	construct : function() {
		if(this.appId != null) {
			var params = {
				appId: this.appId,
				status: true,
				cookie: true,
				xfbml: true
			}
			$('body').append('<div id="fb-root"></div>');
			FB.init(params);
			this.monitor();
		}
	},
	
	monitor : function() {
		this.fbLikes();
		this.fbDislikes();
	},
	
	fbLikes : function() {
		FB.Event.subscribe('edge.create', function(response) {
			top.location.href = $.CORE.fb.appLocation;
		});
	},
	
	fbDislikes : function() {
		FB.Event.subscribe('edge.remove', function(response) {
			top.location.href = $.CORE.fb.appLocation;
		});
	}
};

/**
 * Forms
 */
$.CORE.forms = {
	construct : function() {
		this.execFormCheckerPlugin();
	},
	
	execFormCheckerPlugin : function() {
		var $formRef = $('form.formGenerated');
		if($formRef.length) {
        	$formRef.formChecker();
		}
	}
};

/**
 * Executes when the DOM has been fully loaded
 */
$(document).ready(function() {
	$.CORE.forms.construct();
	$.CORE.fb.construct();
});
