// ----------------------------------------------------------------------------
// DOM READY
// ----------------------------------------------------------------------------

$(document).ready(function() {

	// BIND EVENTS FOR CLICKABLE ITEMS
	$('.clickable').bind('click', function() {
		var url = $(this).find('a[href]:first').attr('href');
		var target = $(this).find('a[href]:first').attr('target');
		if(url) {
			if($.data(document, 'notclickable') == false) {
				if(target == '_blank') {
					window.open(url);
				} else {
					window.location.href = url;
				}
			}
		}
	});

	// REMOVE EMPTY ELEMENTS
	$('.tpl_header:empty').remove();

	// SET VARIABLE FOR NOT CLICKABLE ITEMS
	$('.clickable .notclickable').bind('mouseenter', function() {
		$.data(document, 'notclickable', true);
	}).bind('mouseleave', function() {
		$.data(document, 'notclickable', false);
	});
	$.data(document, 'notclickable', false);

	// BIND EVENTS FOR HOVERABLE ITEMS
	$('.hoverable').bind('mouseenter mouseleave', function() {
		$(this).toggleClass('hover');
	});

	// BIND EVENTS FOR FORMS
	$('.formline, .formarea, .formselect').bind('focus blur', function() {
		$(this).toggleClass('focus');
	});
	$('.formbut').bind('mouseenter mouseleave', function() {
		$(this).toggleClass('hover');
	});

	// BIND WINDOW RESIZE EVENT
	$(window).bind('resize load', function() {
		$('#tpl_body_wrapper').css('minHeight', ($(window).height() - $('#tpl_footer').height()) + 'px');
		$('#tpl_wrapper').css('minHeight', ($('#tpl_body_wrapper').height() - 225) + 'px');
	});
	$(window).trigger('resize');


	// ------------------------------------------------------------------------
	// LOAD EXTERNAL SCRIPTS / PLUGINS
	// ------------------------------------------------------------------------

	if($('.colorbox').length > 0) {
		$.getScript(jquery_coreurl+'/include/jquery/getcss.latest.js', function() {
		$.getCSS(jquery_siteurl+'/css/jquery.colorbox.css', function () {
		$.getScript(jquery_coreurl+'/include/jquery/easing.latest.js', function() {
		$.getScript(jquery_coreurl+'/include/jquery/colorbox.latest.js', function() {
		
			if($('img.colorbox').length > 0) {
				$('img.colorbox').each(function() {
					$(this).wrap('<a href="' + $(this).attr('src') + '" title="Klik hier voor een uitvergroting" class="colorbox"></a>').removeClass('colorbox');
				});
			}
	
			// ADD COLORBOX LOADED
			$('.colorbox').colorbox({
				initialWidth: 40,
				initialHeight: 40,
				speed: 400,
				overlayClose: true,
				opacity: 0.80
			});
	
		});
		});
		});
		});
	}


	// ------------------------------------------------------------------------
	// ONLOAD / LOAD COMPLETE
	// ------------------------------------------------------------------------

	//$(window).load(function() {

		// PAGE LOADED

	//});

});


// ----------------------------------------------------------------------------
// CUSTOM FUNCTIONS | CALLED BEFORE DOM READY FROM INSIDE TEMPLATE
// ----------------------------------------------------------------------------

function jquery_include_submenu() {

	// REMOVE EMPTY SUBMENU
	$('#tpl_submenu ul:empty').each(function() {
		$('#tpl_submenu').remove();
	});

}

function jquery_include_subsubmenu() {

	// REMOVE EMPTY SUBSUBMENU
	$('#tpl_subsubmenu ul:empty').each(function() {
		$('#tpl_subsubmenu').remove();
		$('#tpl_content_small').attr('id', 'tpl_content');
	});

}
