$(document).ready(function() {
	//$('body').supersleight({shim: '/i/transp.gif'});
});

function showHide(elem) {
	if ($(elem).css('display') == 'none') {
		$(elem).slideDown();
	} else {
		$(elem).slideUp();
	}
}
var submenyCloseTimer = 0;
var closeTimeoutId = 0;
var prevId = 0;
function submeny(meny_id, close) {
	if (close) {
		submenyCloseTimer = setTimeout("$('#meny_lower" + meny_id + "').slideUp(50)", 500);
		closeTimeoutId = meny_id;
	} else {
		$('#meny_lower' + meny_id).slideDown(100, function () {
			if (closeTimeoutId == meny_id) clearTimeout(submenyCloseTimer);
			if (meny_id != prevId) $('#meny_lower' + prevId).slideUp(50);
			prevId = meny_id;
		});
	}
}

function drawSwf(url, w, h, wmode) {
	document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+w+'" height="'+h+'">');
	document.writeln('<param name="movie" value="'+url+'" />');
	document.writeln('<param name="quality" value="high" />');
	document.writeln('<param name="name" value="movie" />');
	document.writeln('<param name="swLiveConnect" value="true" />');
	if (wmode == 1) {
		document.writeln('<param name="wmode" value="transparent" />');
		document.writeln('<embed src="'+url+'" wmode="transparent" quality="high" scale="noscale" width="'+w+'" height="'+h+'" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	}
	else {
		document.writeln('<embed src="'+url+'" quality="high" scale="noscale" width="'+w+'" height="'+h+'" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	}
	document.writeln('</object>');
}

function showMask(hide) {
	if (hide == 1) {
		$('body').css('overflow', '');
		$('#mask').fadeOut(250);
	} else {
		$('body').css('overflow', 'hidden');
		$('#mask').css('height', $(document).height() + 'px');
		$('#mask').fadeIn(250);
	}
}
function putElemMiddle(elem) {
	var w = $(elem).width();
	var h = $(elem).height();
	var posX = $('body').width()/2-(w/2);
	posY = $(window).height()/2-(h/2);
	$(elem).css('position', 'fixed');
	$(elem).css('top', posY + 'px');
	$(elem).css('left', posX + 'px');
}
function showHelp(keycode) {
	if (keycode) {
		$.get('/o/help.php?code=' + keycode + '&ln=' + ln, function (data) {
			$('#ajaxContent').html(data);
			putElemMiddle('#ajaxBox');
			$('#ajaxBox').fadeIn(200);
			if ($('#helpBox').height()+50 > $(window).height()) {
				$('#helpBox').css('height', ($(window).height()-50) + 'px');
				putElemMiddle('#ajaxBox');
			}
			showMask();
		});
	} else {
		return false;
	}
}
function feedback(close) {
	if (close == 2) {
		$.post("/", { fbrate: $('#fbrate').val(), fbtopic: $('#fbtopic').val(), fbtext: $('#fbtext').val(), url: document.location.href } );
		feedback(1);
		alert(ln_thankYou);

		$('#fbrate').val('0');
		$('.fbrate').attr('class', 'fbrate active');
		$('#fbtopic').val('');
		$('#fbtextArea').hide(0);
		$('#fbtext').val('');
		$('.fbtopic').attr('class', 'fbtopic active');

		return false;
	} else if (close == 1) {
		showMask(1);
		$('#feedbackBox').fadeOut(200);
	} else {
		putElemMiddle('#feedbackBox');
		$('#feedbackBox').fadeIn(200);
		showMask();
	}
}

function showInFrame(url) {
	window.open(url, '_blank');
	return false;
}
function loader(end) {
	if (end == 1) {
		$('#mainLoader').fadeOut(200);
	} else {
		$('#mainLoader').fadeIn(200);
	}
}

function saveTodo(page_id, what, val, redirect) {
	if (user_id > 0) {
		$.getJSON(toolUrl + '/todo&page_id=' + page_id + '&what=' + what + '&val=' + val, function (data) {
			if (redirect) {
				window.location=redirect;
			}
		});
	} else {
		alert(_login_first);
		return false;
	}
}
