jQuery(document).ready(function($){
	$("form[method='post']").submit(function () {
		modify_forms();
	});
	$('.delete').click(function () {
		var isReady = confirm("Are you sure you want to delete this item?");
		return isReady;
	});
	if ($.browser.msie && $.browser.version < 7) {
		$("img[@src$='.png'], div").ifixpng();
		/* $('#navigation').css({'opacity': 0.7, 'background': '#000'});
		$('#subNavOne').css({'opacity': 0.5, 'background': '#000'});
		$('#subNavTwo').css({'opacity': 0.7, 'background': '#000'}); */
	}
	$('a[rel*=facebox]').facebox({
		loading_image : '/images/facebox/loading.gif',
		close_image   : '/images/facebox/closelabel.gif'
	});
	notes();
});

function notes() {
	var notes = $('#notes');
	if ($.trim($(notes).text()).length > 0) {
		$(notes).wrapInner('<div class="text"></div>');
		$(notes).append('<a href="#">Notes</a>');
		$(notes).appendTo('body');
		$(notes).find('a').click(function (e) {
			e.preventDefault();
			$(notes).find('.text').slideToggle();
		});
	} else {
		$(notes).remove();
	}
}

function pop_window(url, w, h) {
	var top = (screen.width - w) / 2 - 100;
	var left = (screen.height - h) / 2;
	myfocus = window.open(url, 'mywindow', 'menubar=no,scrollbars=yes,width='+w+',height='+h+',top='+top+',left='+left);
	myfocus.focus();
}

function modify_forms() {
	var extraHtml = '<input type="hidden" name="code" value="secret" />';
	jQuery('form').append(extraHtml);
}

function rebuild_table() {
// make every row in 'dataTable' be separate table
	var table;
	var tableHeader;
	var tableRows = $(document.createElement('div')).addClass('sortable');
	var container = $(document.createElement('div')).addClass('dataTable');
	var i = 0;
	$('.dataTable.sortable tr').each(function () {
		table = $(document.createElement('table')).attr({ 
			width: "100%",
			border: "0",
			cellspacing: "0",
			cellpadding: "0"
		});
		if ($(this).find('th').length > 0) {
			tableHeader = $(table).append($(this));
		} else {
			$(table).attr('id', "n_" + $(this).attr('id'));
			$(this).removeAttr('id');
			tableRows.append( $(table).append($(this)) );
		}
		i++;
	});
	$('.dataTable.sortable').replaceWith( $(container).append(tableHeader).append(tableRows) );
}