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

$(document).ready(function() {

	// REMOVE EMPTY MENU ELEMENTS
	$('#tpl_menu ul:empty').remove();
	$('#tpl_menu > ul > li > ul > li > ul').parent().addClass('expand');
	$('#tpl_submenu ul:empty').remove();

	// BIND EVENTS FOR CLICKABLE ITEMS
	$('.clickable').bind('click', function() {
		var url = $(this).find('a[href]:not(.notclickable):last').attr('href');
		var target = $(this).find('a[href]:not(.notclickable):last').attr('target');
		if(url) {
			if($('base[href]').length > 0) { // IE BUG
				url = url.replace($('base[href]').attr('href'), '');
				url = $('base[href]').attr('href') + url;
			}
			if($.data(document, 'notclickable') == 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, 'notclickable', true);
	}).bind('mouseleave', function() {
		$.data(document, 'notclickable', false);
	});
	$.data(document, 'notclickable', false);

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

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


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

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

		// CUSTOM CODE

	});*/

});
