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

$(document).ready(function() {

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

	// BIND RESIZE
	$(window).bind('resize load', function() {
		$('#tpl_content, #tpl_content_wide').css('minHeight', '0px');
		var corheight =  305; // top height + padding / margin content
		var winheight = $('#tpl_body').height();
		$('#tpl_content, #tpl_content_wide').css('minHeight', (winheight - corheight) + 'px');
	});
	$(window).trigger('resize');
	setInterval("$(window).trigger('resize')", 100);


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

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

		// REMOVE BACKGROUND IMAGE WHEN NOT EMPTY
		$('#tpl_header:not(:empty)').css('backgroundImage', 'none');

		// ADD SIMPLE FADE IN OUT
		$('#tpl_header').cycle();

	});


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

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

		// CUSTOM CODE

	});*/

});


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

function jquery_include_dropmenu() {

	// MOVE MENU ITEMS
	$('#tpl_menu .mid1').each(function() {
		$(this).find('.mid2 .boxed').append($(this).not('.selected').find('> .menu2'));
		$(this).find('.mid2 .boxed:empty').parent().parent().remove();
		$(this).find('.mid3').hide().prev('.menu2selected').next('.mid3').show();
	});

	// BIND AND HANDLE MENU EVENTS
	$('.mid1').bind('mouseenter', function() {
		$(this).css('zIndex', 100000).find('.mid2').show();
		$(this).find('.shadow').height($(this).find('.boxed').height());
	});
	$('.mid1').bind('mouseleave', function() {
		$(this).css('zIndex', 10000).find('.mid2').hide();
	});

}

function jquery_include_content() {

	// REMOVE EMPTY BANNER COL
	$('#tpl_banners:empty').each(function() {
		$('#tpl_banners').remove();
		$('#tpl_content').attr('id', 'tpl_content_wide');
	});

}
