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

$(document).ready(function() {

	// BIND EVENTS FOR CLICKABLE ITEMS
	$('.clickable').bind('click', function() {
		var url = $(this).find('a[href]:last').attr('href');
		var target = $(this).find('a[href]: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 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');
	});

	// HANDLE WINDOW RESIZE
	/*$(window).bind('resize', function() {

		// PAGE LOADED
		$('#tpl_wrapper').height(0);
		$('#tpl_wrapper').height($('#tpl_body').height());

	}).trigger('resize');
	var windowIntervalId = window.setInterval("$(window).trigger('resize')", 250);*/


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

	//$.getScript(jquery_coreurl+'/include/jquery/easing.latest.js', function() {

		// EASING LOADED

	//});


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

	$(window).load(function() {

		// PAGE LOADED
		//$(this).trigger('resize');

	});

});


// ----------------------------------------------------------------------------
// 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();
		$('#tpl_content').attr('id', 'tpl_content_wide');
	});

}*/
