$(document).ready(function() {

//page transitions


	


$("a.fancyboxstay").fancybox({centerOnScroll:true});
$("a.fancybox").fancybox();
$("a.iframe").fancybox({
	type:'ajax',
});
$("a.iframetrue").fancybox({
	type:'iframe',
	height:420,
	width:540
});
	// Main menu accordion
	$( "#menu-accordion" ).accordion({ 
		collapsible: true,
		autoHeight: false, 
	    active: false,
		navigation:true
	});

	// Data table
	$('.table-list').each(function() {
		var skippedColSort = [];
		var i = 0;
		$(this).find('th').each(function() {
			if($(this).hasClass('skip-sort'))
			{
				skippedColSort.push(i);
			}
			i++;
		});
		$(this).dataTable({
			"sPaginationType": "full_numbers", 
			"aoColumnDefs" : [ { 
			"bSortable" : false, 
			"aTargets" : skippedColSort 
			}]
		});
	});
	
	// Form elements skin
	$("select, input:checkbox, input:radio, input:file").uniform();
	
	// Select all checkbox for a set of checkboxes
	$(".select-all").click(function() {
		var checkedStatus = this.checked;
		var checkboxName = this.value;
		$('input[name="' + checkboxName + '[]"]').each(function() {
			this.checked = checkedStatus;
			if(checkedStatus)
			{
				$(this).parent().addClass('checked');
			}
			else
			{
				$(this).parent().removeClass('checked');
			}
		});
	});
	
	$('select.select-submit').change(function() {
		if($(this).val() !== '')
		{
			$(this).closest("form")[0].submit();
		}
	});
	
	$('div#notification-close').click(function() {
		$('div#notification-wrapper').animate(
			{"opacity": 0}, 
			500,
			function() {
				$('div#notification-wrapper').css('display', 'none');
			}
		);
	});
	
	tinyMCE.init({
			// General options
			mode : "textareas",
			theme : "advanced",
			editor_selector : "tiny-mce",
			relative_urls : true,
			remove_script_host : false,
			convert_urls : false,
			accessibility_warnings : false,
			plugins : "advimage,advlink,autolink,lists,media,table,jbimages,media",
			// Theme options
			theme_advanced_buttons1 : "code,media,fontselect,fontsizeselect,forecolor,backcolor,|,bold,italic,underline,strikethrough",
			theme_advanced_buttons2 : "justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,outdent,indent,blockquote,|,sub,sup",
			theme_advanced_buttons3 : "link,unlink,|,jbimages,charmap,|,tablecontrols,|,hr,removeformat|code",
			theme_advanced_buttons4 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : false,
			width: '100%',
			height: '400px'
	});
	
	$( "input.date" ).each(function(index) {
		var name = $(this).attr('name');
		var id = $(this).attr('id');
		var val = $(this).val();
		if(id == null || id == '')
		{
			id = name;
			$(this).attr('id', id);
		}
		
		$(this).parent().append('<input class="datepicker" type="text" id="' + name + '_datepicker" readonly="readonly" />');
		$('#' + name + '_datepicker').datepicker({
			buttonImage : BASE_URL + 'templates/framework/images/jquery-ui/ui-calendar.png',
			buttonImageOnly : true,
		    showOn : 'both',
			dateFormat : 'yy-mm-dd',
			//dateFormat : 'DD, d M yy',
			altFormat : 'yy-mm-dd',
			altField : '#' + id,
			autoSize : true,
			buttonText : '',
			defaultDate : val
		});
		
		$('#' + name + '_datepicker').datepicker('setDate', val);
		$('#' + name + '_datepicker').datepicker('option', 'dateFormat', 'DD, d M yy');
	});
});

