/**
 * Initialize $.CORE in case it's not present
 */
if(typeof $.CORE == "undefined") {
	$.CORE= Object;
};

/**
 * Product slider
 */
$.CORE.slider = {
	construct : function() {
		this.productList();
	},
	
	productList : function() {
		if($('.prodListContainer').length) {
			$('.prodListContainer').each(function(){
				var width = 0;
				$('.items a', this).each(function(){
					width = width + $(this).width() + 14;
				});
				$('.items', this).width(width);
			});
			$('.scroll-pane').jScrollPane({
				horizontalDragMinWidth: 78,
				horizontalDragMaxWidth: 78,
				hijackInternalLinks: true
			}).bind(
				'jsp-scroll-x',
				function(event, scrollPositionX, isAtLeft, isAtRight)
				{
					var centerItem  = Math.floor(scrollPositionX / 113) + 1;
					var id = $('.items a:eq('+centerItem+')', this).attr('id');
					id = id.split('_');
					$(this).parent().find('.prodListCats a').removeClass('active');
					$('a[href=#'+id[0]+'_'+id[1]+'_1]').addClass('active');
				}
			);

		
			$('.btnNext').bind('click', function() {
				var api = $(this).parent().find('.scroll-pane').data('jsp');
				api.scrollBy(113, 0);
				return false;
			});

			$('.btnPrev').bind('click', function() {
				var api = $(this).parent().find('.scroll-pane').data('jsp');
				api.scrollBy(-113, 0);
				return false;
			});

		}
	}
};

/**
 * 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.slider.construct();
	
	$('a.lightbox').lightBox({
		overlayBgColor: "#000",
		overlayOpacity: 0.6,
		imageLoading: "/public/images/lightbox/loading.gif",
		imageBtnClose: "/public/images/lightbox/close.gif",
		imageBtnPrev: "/public/images/lightbox/prev.gif",
		imageBtnNext: "/public/images/lightbox/next.gif",
		imageBlank: "/public/images/lightbox/blank.gif", 
		containerResizeSpeed: 350,
		txtImage: "",
		txtOf: "of"
	});
});
