/**
 * Initialize $.CORE in case it's not present
 */
if(typeof $.CORE == "undefined") {
	$.CORE= Object;
};

/**
 * Dummy object
 */
$.CORE.dummyobject = {
	construct : function() {
	},
	
	dummyFunction : function() {
	}
};

/**
 * Forms
 */
$.CORE.forms = {
	construct : function() {
		this.execFormCheckerPlugin();
		this.fillSelectBox();
	},
	
	execFormCheckerPlugin : function() {
		var $formRef = $('form.formGenerated');
		if($formRef.length) {
        	$formRef.formChecker();
		}
	},
	
	fillSelectBox : function(){
		
		$.getJSON('/nl/c/shop', function(data){
			//alert(data);
			$.each(data , function(index, value){
				var $option = $('<option>').text(value).attr('value',value);
				$('form .artikels select').append($option);
			});
		});
	}
};

$.CORE.slideshow = {
	construct : function(){
		$('#photoslider IMG').css({opacity: 0.0});
   		$('#photoslider IMG:last').animate({opacity: 1}, 'slow');
   		setInterval("slideSwitch()", 5000);
	}
};

function slideSwitch() {
    var $active = $('#photoslider IMG.active');
    if($active.length == 0){
		$active = $('#photoslider IMG:last');
	}
    var $next =  $active.next().length ? $active.next() : $('#photoslider IMG:first');
	$active.animate({opacity: 0}, 600, function(){$active.addClass('last-active');});
    $next.css({'opacity': '0.0'})
        .addClass('active')
        .animate({opacity: 1}, 'slow', function() {
            $active.removeClass('active last-active');
        });
}

/**
 * Executes when the DOM has been fully loaded
 */
$(document).ready(function() {
	$.CORE.forms.construct();
	$.CORE.slideshow.construct();
	
	$('.external').attr('target','_blank');
	
	$('a.lightbox').lightBox();
	
	$('.scrollable').jScrollPane();

	
});
