// ----------------------------------------------------------------------------
// 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');
	});


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

		$('.colorboxinline').each(function() {
			var href = $(this).attr('rel');
			//var html = $(href).html();
			$(this).colorbox({
				inline: true,
				href: href,
				initialWidth: 40,
				initialHeight: 40,
				speed: 250,
				overlayClose: true,
				opacity: 0.80,
				maxWidth: '90%',
				maxHeight: '90%',
				onOpen: function() {
					// HIDE SCROLLBARS
					$('body').css('overflow', 'hidden');
				},
				onClosed: function() {
					// SHOW SCROLLBARS
					$('body').css('overflow', 'auto');
				}
			});
		});

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


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

	$(window).load(function() {

		// PAGE LOADED

	});

});


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

function jquery_include_topmenu() {
	// ADD DIVIDERS
	$('#tpl_topmenu a:not(:first)').before(' &nbsp;&nbsp;|&nbsp;&nbsp; ');
}

function jquery_include_submenu() {
	// REMOVE EMPTY SUBMENU
	$('#tpl_submenu > ul:empty').each(function() {
		$('#tpl_submenu').remove();
		$('#tpl_content').attr('id', 'tpl_content_wide');
	});
}

function jquery_include_column() {
	// REMOVE EMPTY COLUMN
	$('#tpl_column:empty').each(function() {
		$('#tpl_column').remove();
		$('#tpl_content_wide').attr('id', 'tpl_content_widest');
		$('#tpl_content').attr('id', 'tpl_content_wide');
	});
}

function jquery_include_footer() {
	// ADD DIVIDERS
	$('#tpl_footer a').before(' &nbsp;&nbsp;|&nbsp;&nbsp; ');
}
