// ----------------------------------------------------------------------------
// 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, 'notclcikable') == false) {
				if(target == '_blank') {
					window.open(url);
				} else {
					window.location.href = url;
				}
			}
		}
	});
	
	// SET VARIABLE FOR NOT CLICKABLE ITEMS
	$('.clickable .notclickable').bind('mouseenter', function() {
		$.data(document, 'notclcikable', true);
	}).bind('mouseleave', function() {
		$.data(document, 'notclcikable', false);
	});
	$.data(document, 'notclcikable', 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');
	});

	// REMOVE EMPTY MENU DROP
	$('#tpl_menu > ul > li > ul:empty').remove();
	$('#tpl_menu > ul > li > ul').parent().find('> a').addClass('dropdown');


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

	$.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() {

		// ADD COLORBOX LOADED
		$('.enlarge').colorbox({
			initialWidth: 40,
			initialHeight: 40,
			speed: 400,
			overlayClose: true,
			opacity: 0.5
		});

	});
	});
	});
	});


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

	$(window).load(function() {

		// CUSTOM CODE

	});

});


// ----------------------------------------------------------------------------
// 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_content() {

	// WIDE CONTENT WHEN NO SUBMENU AVAILABLE
	if($('#tpl_submenu').length == 0) {
		$('#tpl_content').attr('id', 'tpl_content_wide');
	}

}
