$(document).ready(function(){

	$('ul').find('li:last').css({'margin-bottom':'0px','padding-bottom':'0px'});
	
	// confirm delete
	$('.confirm_delete').click(function(){
		return confirm('Are you sure you want to delete this?');
	});

	// apply tooltips
	tooltips('.qtip[title]');

	/**
	 * Show & Hide Form inputs based on selected
	 */
	$('.show_hide').change(function(){
		// hide all options
		$.each($(this).children(),function(k,v){
			var val = v.value;
			if(val != '') {
				$('#show_hide_'+val).hide();
			}
		});

		// fade in the selected option input
		var selected = $(this).val();
		$('#show_hide_'+selected).fadeIn();
	});
	
	// datepicker
	if( $('.datepicker').length ) {
		$(".datepicker").datepicker({
			dateFormat: 'dd/mm/yy',
			showOn: 'button',
			buttonImage: '/img/icons/calendar.png',
			buttonImageOnly: true,
			changeMonth: true,
			changeYear: true,
			firstDay: 1
		});
	}   
});


/**
 * Assign Tooltips
 */
function tooltips(div) {
	if(jQuery().qtip) {
	$(div).qtip({
		style: { 
			name:'dark',
			tip:'bottomLeft'
		},
		position: {
			target:'mouse',
			corner: {
				target: 'topMiddle',
				tooltip: 'bottomLeft'
			}
		}
	});
	}
}
