var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function nav_open()
{  nav_canceltimer();
   nav_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function nav_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function nav_timer()
{  closetimer = window.setTimeout(nav_close, timeout);}

function nav_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#nav > li').bind('mouseover', nav_open)
   $('#nav > li').bind('mouseout',  nav_timer)});

document.onclick = nav_close;

function showhide(id){
	if (document.getElementById){
		obj = document.getElementById(id);
		if (obj.style.display == "none"){
		obj.style.display = "";

		} else {
		obj.style.display = "none";

		}
	}
}

<!--
/*
function Smiles(which) {
	document.newtopic.sisu.value = document.newtopic.sisu.value + which;
	document.forms['newtopic'].sisu.focus();
}
*/
function Smiles(myValue) {

//IE support
if (document.selection) {
var temp;
document.newtopic.sisu.focus();
sel = document.selection.createRange();
temp = sel.text.lenght;
sel.text = myValue;
if (myValue.length == 0) {
sel.moveStart('character', myValue.length);
sel.moveEnd('character', myValue.length);
} else {
sel.moveStart('character', -myValue.length + temp);
}
sel.select();
}
//MOZILLA/NETSCAPE support
else if (document.newtopic.sisu.selectionStart || document.newtopic.sisu.selectionStart == '0') {
var startPos = document.newtopic.sisu.selectionStart;
var endPos = document.newtopic.sisu.selectionEnd;
document.newtopic.sisu.value = document.newtopic.sisu.value.substring(0, startPos) + myValue + document.newtopic.sisu.value.substring(endPos, document.newtopic.sisu.value.length);
document.newtopic.sisu.selectionStart = startPos + myValue.length;
document.newtopic.sisu.selectionEnd = startPos + myValue.length;
} else {
document.newtopic.sisu.value += myValue;
}

}


var clientInfo = navigator.userAgent.toLowerCase();
var isIE = ( clientInfo.indexOf("msie") != -1 );
var isWin = ( (clientInfo.indexOf("win")!=-1) || (clientInfo.indexOf("16bit") != -1) );

function createBBtag( openerTag , closerTag , areaId ) {
	if(isIE && isWin) {
		createBBtag_IE( openerTag , closerTag , areaId );
	}
	else {
		createBBtag_nav( openerTag , closerTag , areaId );
	}
	return;
}

function createBBtag_IE( openerTag , closerTag , areaId ) {
	var txtArea = document.newtopic.sisu;
	var aSelection = document.selection.createRange().text;
	var range = txtArea.createTextRange();

	if(aSelection) {
		document.selection.createRange().text = openerTag + aSelection + closerTag;
		txtArea.focus();
		range.move('textedit');
		range.select();
	}
	else {
		var oldStringLength = range.text.length + openerTag.length;
		txtArea.value += openerTag + closerTag;
		txtArea.focus();
		range.move('character',oldStringLength);
		range.collapse(false);
		range.select();
	}
	return;
}

function createBBtag_nav( openerTag , closerTag , areaId ) {
	var txtArea = document.newtopic.sisu;
	if (txtArea.selectionEnd && (txtArea.selectionEnd - txtArea.selectionStart > 0) ) {
		var preString = (txtArea.value).substring(0,txtArea.selectionStart);
		var newString = openerTag + (txtArea.value).substring(txtArea.selectionStart,txtArea.selectionEnd) + closerTag;
		var postString = (txtArea.value).substring(txtArea.selectionEnd);
		txtArea.value = preString + newString + postString;
		txtArea.focus();
	}
	else {
		var offset = txtArea.selectionStart;
		var preString = (txtArea.value).substring(0,offset);
		var newString = openerTag + closerTag;
		var postString = (txtArea.value).substring(offset);
		txtArea.value = preString + newString + postString;
		txtArea.selectionStart = offset + openerTag.length;
		txtArea.selectionEnd = offset + openerTag.length;
		txtArea.focus();
	}
	return;
}

//-->

$().ready(function() {
  $('#dialog').jqm();
});