$(document).ready(function() {
	$(".fbox").fancybox();
});

function toggleEditor(id) {
	if (!tinyMCE.getInstanceById(id))
		tinyMCE.execCommand('mceAddControl', false, id);
	else
		tinyMCE.execCommand('mceRemoveControl', false, id);
}


function tinyMCEinitNews () {
	tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	editor_selector : "itemDescClass",
	plugins : "table",
    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,blockquote,|,styleselect,formatselect,fontselect,fontsizeselect",
	theme_advanced_buttons2 : "hr,removeformat,tablecontrols,|,undo,redo,|,sub,sup,|,link,unlink,anchor,image,cleanup,code,|,forecolor,backcolor",
	theme_advanced_buttons3 : "",
    content_css : "/edit.css",
    theme_advanced_toolbar_location : "top",
    cleanup_on_startup : true,
    entity_encoding : "raw",
    convert_urls : false,
    theme_advanced_toolbar_align : "left"});
}

function fullTextSwitch (id,sw) {
	$('#blogFullDiv').css('display',sw == '1' ? 'none' : '');
	$('#fullTextX').load('/live/x/blogFullText/'+id+'/'+sw);
}

function ajaxFileUpload(id) {
		$("#loading")
		.ajaxStart(function(){ 	$(this).show(); })
		.ajaxComplete(function(){	$(this).hide();	});

		$.ajaxFileUpload ( {
			url:'/live/x/upload/'+id,
			secureuri:false,
			fileElementId: 'fileToUpload',
			dataType: 'plain',
			success: function (data, status) {
				$('#uploadStatus').html(data.msg);
				$('#mediaList').load('/live/x/mediaflist/'+id);
			},
			error: function (data, status, e) {
				$('#uploadStatus').html(data.msg + ' e:' + e);
			}
		});

		return false;
}

function rowDown (r) {
  var i=r.parentNode.parentNode.rowIndex;
  var table = r.parentNode.parentNode.parentNode.parentNode;
  
  if (i < table.rows.length - 1) {
 	table.insertRow(i);
  	table.rows[i].innerHTML = table.rows[i+2].innerHTML;
  	table.deleteRow(i+2); 
  }
}

function rowUp (r) {
  var i=r.parentNode.parentNode.rowIndex;
  var table = r.parentNode.parentNode.parentNode.parentNode;
  if (i > 0) {
 	table.insertRow(i-1);
  	table.rows[i-1].innerHTML = table.rows[i+1].innerHTML;
  	table.deleteRow(i+1); 
  }
} 
		



