var timer;

$(function(){	
	$('input[name=delete], input[type=image]').click(function(event){if(!confirm('Are you sure you wish to delete this item?'))event.preventDefault();});
	
	$('input.placeholder').live('focus', function(event){if(this.value==this.title)this.value='';});
	$('input.placeholder').live('blur', function(event){if(this.value=='')this.value=this.title;});
	
	$('.panels .arrow-left').click(function(){ $('.panels').animate({ scrollLeft:  $('.panels').scrollLeft() - 241 }, 500); });
	$('.panels .arrow-right').click(function(){ $('.panels').animate({ scrollLeft:  $('.panels').scrollLeft() + 241 }, 500); });
	
	$('a[rel=external]').live('click', function(event){ event.preventDefault(); window.open(this.href); });
	$('a.popup').live('click', function(event){ event.preventDefault(); window.open(this.href, 'JustOne', 'width=400, height=200'); });
	
	$('#category').change(function(){ $.getJSON('/includes/ajax/course', { cat: $(this).val() }, function(data) {
		$('#course').empty().removeClass('ui-state-disabled');
		if (location.href.indexOf('id=') == -1) $('<option></option>').html('Select a Course...').appendTo('#course');
		$(data).each(function(i,e) { $('<option></option>').attr({ 'value': e.course_title.replace(/ /gi, '-').toLowerCase() }).html(e.course_title).appendTo('#course'); });
	}); });
	
	$('#course').change(function(){ location.href = '/training/' + this.value });

	if (jQuery.fn.validate) $('form').validate();
	
	if ($('.feature div').length > 1) timer = setTimeout(timeout, 5000);
});

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-26975147-1']);
_gaq.push(['_trackPageview']);
 
(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

function timeout() {
	var images = $('.feature div');
	var index = $('.feature div:visible').index('.feature div');
	
	$(images).fadeOut(1000);
	if (index < images.length - 1) $('.feature div:eq(' + ++index + ')').stop(true,true).fadeIn(1000);
	else $('.feature div:first').stop(true,true).fadeIn(1000);	
	
	timer = setTimeout(timeout, 5000);
}

function close() { $('.popup').fadeOut(function(){$(this).remove()}); }
