/*
 * jQuery funktioner för taxi.halmstad.net
 * @requires jQuery v1.2.2 or later
 *
 */

	 jQuery(document).ready(function(){ //jquery update dom - snabbare än on load
	 	

	var temp;
	$("#subpagesDummy").hide();								
/********************** End Document Ready ***********************************/
			
	});		


// edit in place etc för admin

$.fn.tinymce = function(options){
   return this.each(function(){
	  
      tinyMCE.execCommand("mceAddControl", true, this.id);
   });
}


function initMCE(){
   tinyMCE.init({
   	mode : "none",
    plugins : 'autoresize, paste', 
      theme : "advanced",
      theme_advanced_toolbar_location : "external",
      theme_advanced_toolbar_align : "left",
      theme_advanced_statusbar_location : "bottom",
      theme_advanced_buttons1 : "code,bold,italic,underline,strikethrough,separator,bullist,numlist,undo,redo,link,unlink",
      theme_advanced_buttons2 : "",
      theme_advanced_buttons3 : "",
      theme_advanced_resizing : false,
      content_css : "kimtarp.css",
      //plugins : "autoresize",
   	  force_br_newlines : true,
      forced_root_block : ''
   });
}

initMCE();
var tinymceConfigs = 
					[{
						  execcommand_callback : "resizeTable",
					      mode : "none",
					      plugins : 'autoresize', // - tells TinyMCE to skip the loading of the plugin
					      theme : "advanced",
					      theme_advanced_toolbar_location : "external",
					      theme_advanced_toolbar_align : "left",
					      theme_advanced_statusbar_location : "none",
					      theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,undo,redo,link,unlink",
					      theme_advanced_buttons2 : "",
					      theme_advanced_buttons3 : "",
					      theme_advanced_resizing : false,
					      content_css : "css/editHeading.css",
					      //plugins : "autoresize",
					   	  force_br_newlines : true,
					      forced_root_block : ""
					},{ 
					      mode : "none",
					      plugins : 'autoresize, paste',
					      theme : "advanced",
					      paste_auto_cleanup_on_paste : true,
					      theme_advanced_toolbar_location : "external",
					      theme_advanced_toolbar_align : "left",
					      theme_advanced_statusbar_location : "none",
					      theme_advanced_buttons1 : "formatselect,separator,bold,italic,underline,strikethrough,separator,bullist,numlist,separator,justifyleft,justifycenter,justifyright,justifyfull",
					      theme_advanced_buttons2 : "code,forecolor,backcolor,image,separator,link,unlink,separator,pastetext,pasteword,selectall",
					      theme_advanced_buttons3 : "",
					      theme_advanced_resizing : false,
					      content_css : "edit.css"
					      //plugins : "autoresize",
					   	  //force_br_newlines : true,
					      //forced_root_block : ""
					}];
function resizeTable()
{
	$('table.mceLayout').css('height', '10px');
}

$.editable.addInputType('mce2', {
   element : function(settings, original) {
   		
      var textarea = $('<textarea id="'+$(original).attr("id")+'_mce"/>');
      if (settings.rows) {
         textarea.attr('rows', settings.rows);
      } else {
         textarea.height(settings.height);
      }
      if (settings.cols) {
         textarea.attr('cols', settings.cols);
      } else {
         textarea.width("461px");
      }
      $(this).append(textarea);
         return(textarea);
      }
      ,
   plugin : function(settings, original) {
		
   	  temp = settings.selector;
   	  $("#subpages").hide();
   	  $("#subpagesDummy").show();
   	  $('#'+temp).attr("style", "margin-left: -11px;");
   	  tinyMCE.settings = tinymceConfigs[1];
      tinyMCE.execCommand("mceAddControl", true, $(original).attr("id")+'_mce');
      },
   submit : function(settings, original) {
   	  $('#'+temp).attr("style", "margin-left: 0px;");
      tinyMCE.triggerSave();
      tinyMCE.execCommand("mceRemoveControl", true, $(original).attr("id")+'_mce');
      $("#subpagesDummy").hide();
      $("#subpages").show();
      },
   reset : function(settings, original) {
   	$('#'+temp).attr("style", "margin-left: 0px;");
      tinyMCE.execCommand("mceRemoveControl", true, $(original).attr("id")+'_mce');
      original.reset();
   }
});





(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);

