// JavaScript Document

function setContentHeight () {
		var x = document.getElementById("sidemenu");
		var y = document.getElementById("content-right");
		var z = document.getElementById("menu-right");
		
		if (x.offsetHeight < z.offsetHeight) {
			x.style.height = z.offsetHeight+'px';
		}
		if ((x.offsetHeight) > y.offsetHeight) {
			y.style.height = x.offsetHeight+'px';
		}
		
		//alert(x.offsetHeight+" "+y.offsetHeight+" "+z.offsetHeight);
		//alert(Browser.Engine.name);
}

window.onload = setContentHeight;

if( typeof com === "undefined" ) var com = {};
if( typeof com.aol === "undefined" ) com.aol = {};
com.aol.externallinks = new Class({
 
	Implements: [Options, Events],
	options : {
		currentServer : '', // override use of document.location.host
		extLnkClass : '',
		autoRun : true,
		onComplete : $empty // Event
	},
	initialize : function (options)
	{
		this.setOptions(options);
		if(this.options.autoRun) { this.run(); }
	},
	run : function() {
		var b = $$('body')[0], lnks = b.getElements('a'), s = this.setServer();
		lnks.each( function(item) {
			this.setLink( item, s );
		}, this );
 
		this.fireEvent( 'complete', { "statusText" : "ok", options : this.options } );
		return true;
	},
	//Helpers
	setServer : function() {
		var s = ( this.options.currentServer !== '' ) ? this.options.currentServer : document.location.host;
		return {
			getServer : function() { return s; }
		}
	},
	setLink : function( el, server ) {
		var h = el.get('href');
		if( h.indexOf('http') >= 0 && h.indexOf( server.getServer() ) < 0 ) {
			el.set('target', '_blank');
			if( this.options.extLnkClass !== '' ) el.set('class', this.options.extLnkClass )
		}					
		return el;
	}
});


tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	plugins : "safari,paste",
	width : "400",
	height : "200",
	// Theme options
	theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,undo,redo,|,bullist,numlist,|,pasteword",
	theme_advanced_buttons2 : "",
	theme_advanced_buttons3 : "",
	theme_advanced_toolbar_location : "top",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : true,
	theme_advanced_resize_horizontal : false,
	/*mode : "textareas",
	theme : "simple",
	width : "400",
	height : "200",*/
	file_browser_callback: "CustomFileBrowser",
	editor_deselector : /(mceNoEditor|postEditor)/
	
});

window.addEvent('domready', function() { // wait for the content
	if ($chk($('delete-link'))) {
		function display_confirm(_confirmed) {
			if (_confirmed) {
				window.location = $('delete-link').getProperty('href');
			}
		}
		$('delete-link').addEvent('click', function(link) {
			link.stop();
			var mdialog = new MavDialog.Confirm({
				'force': true,
				'title': 'Confirm Deletion',
				'message': 'Are you sure want to permanently delete that item?',
				'callback': display_confirm
			});			
		});
	}

	$$('.delete-link').addEvent('click', function(link) {
		link.stop();
		var confirm = new Facebox({
			width: 200,
			title: 'Confirm deletion',
			message: 'Are you sure you want to delete that?',
			submitValue: 'Yes',
			cancelValue: 'No',
			submitFunction: function() {
				confirm.fastclose(),
				window.location = this.getProperty('href');
			}.bind(this),
			cancelFunction: function() {
				confirm.fastclose();
			}
		});
		confirm.show();

	});
	
	var lnks = new com.aol.externallinks( {
	    extLnkClass : 'externalLink'
	});
	Cufon.replace('.content h1');
});