/**
 * Initialize $.CORE in case it's not present
 */
if(typeof $.CORE == "undefined") {
	$.CORE= Object;
};


/** 
 * Backgroundimage resize
 */
$.CORE.backgroundimage = {
	construct : function () {
		this.setupBackground();
	},
	
	setupBackground : function () {
		backgroundSize = $("#wrapper").height() + $("#footer").height();
		$("#background_image").css('height',backgroundSize);
	}
};

/** 
 * Rightcolumn set topmargin
 */
$.CORE.rightColumnTopMargin = {
	construct : function () {
		this.setTopMargin();
	},
	
	setTopMargin : function () {
		topMarginHeight = $("#description .intro-text").outerHeight();
		$("#sidebar").css('margin-top',topMarginHeight);
	}
};

/**
 * Navigation
 */
$.CORE.navigation = {
	construct : function() {
		this.execMainNavigation();
	},
	
	execMainNavigation : function() {
		$("#main-navigation.sf-menu").superfish({
			delay : 300,
			speed : 0,
			autoArrows : false,
			dropShadows : false
		});
	}
};

/**
 * Quotes
 */
$.CORE.quotes = {
	construct : function() {
		this.execQuotes('#quotes');
	},
	
	execQuotes : function(quotes) {
		if($(quotes).length) {
			$(quotes) 
			.before('<div id="quotes-nav">')
			.cycle({
				cleartypeNoBg : true,
				speed : 500,
				timeout : 8000,
				pager : "#quotes-nav"
			});
		}
	}
};

/**
 * 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.navigation.construct();
	$.CORE.quotes.construct();
	$.CORE.forms.construct();
});

$(window).load(function(){  
	$.CORE.rightColumnTopMargin.construct();
	$.CORE.backgroundimage.construct();
}); 
