// ----------------------------------------------------------------------------
// 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($.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/tweet.latest.js', function() {

		// ADD LATEST TWEET
		$('.tpl_twitter_latest').html('').tweet({
			username: 'netgemak',
            count: 2,
			lang_about: '{text}'
		});

	});

	$.getScript(jquery_coreurl+'/include/jquery/easing.latest.js', function() {
	$.getScript(jquery_coreurl+'/include/jquery/ui.latest.js', function() {
		
		// INCLUDE UI ACCORDION
		$('.tpl_accordion').accordion({
			autoHeight: false,
			animated: 'easeOutExpo'
		});
	
	});
	});

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

		// ADD CAROUSEL
		$('#tpl_highlight_small_slider').jcarousel({
			animation: 1000,
			scroll: 5,
			easing: 'easeInOutExpo',
			auto: 5,
			wrap: 'both',
			initCallback: function(carousel) {
				carousel.buttonNext.bind('mouseenter mouseleave', function() {
					$(this).toggleClass('hover');
				});
				carousel.buttonPrev.bind('mouseenter mouseleave', function() {
					$(this).toggleClass('hover');
				});
				carousel.clip.hover(function() {
					carousel.stopAuto(0);
				}, function() {
					carousel.startAuto(5);
				});
			},
			buttonNextHTML: '<div id="tpl_highlight_small_slider_next" class="hoverable"></div>',
			buttonPrevHTML: '<div id="tpl_highlight_small_slider_prev" class="hoverable"></div>'
		});

	});
	});


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

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

		// CUSTOM CODE

	//});

});
