﻿var RightMenu = function () {
	var __right;
	var __list;
	var __h;
	
	var __hidden = false;

	var CLASSNAME = 'textLinks';
	var MENUTITLE = 'Još ...';
	var WIDTH = '170px';
	
	var _init = function () {
		__right = document.getElementById('right');
		var allLists = __right.getElementsByTagName('ol');
		for (var i in allLists) {
			if (!allLists[i].className || allLists[i].className != CLASSNAME) continue;
			__list = allLists[i];
		}
		createMarkup();
		hideList();
	}
	
	var createMarkup = function () {
		__h = document.createElement('h4');
		__h.innerHTML = MENUTITLE;
		__h.onclick = toggleList;
		doCss();
		__list.parentNode.insertBefore(__h, __list);
	}
	
	var doCss = function () {
		with (__h.style) {
			cursor = 'pointer';
			backgroundColor = '#222';
			fontWeight = 'normal'
			textTransform = 'lowercase';
			color = '#aaa';
			margin = '0';
			width = (parseInt(WIDTH, 10) - 16) + 'px';
			border = '1px solid ' + backgroundColor;
			padding = '8px';
		}
		__h.onmouseover = makeBold;
		__h.onmouseout = makeNormal;
		with (__list.style) {
			position = 'absolute';
			backgroundColor = '#FaFaFa';
			width = WIDTH;
			border = '1px solid #EEE';
		}
		var lis = __list.getElementsByTagName('li');
		if (lis.length) for (var i=0, j=lis.length; i<j; i++) {
			if (lis[i] && lis[i].nodeName.toLowerCase() != 'li') continue;
			with (lis[i].style) {
				paddingLeft = '8px';
				borderBottom = '1px solid #EEE';
			}
		}
	}
	
	var hideList = function () {
		__list.style.display = 'none';
		__hidden = true;
	}
	
	var showList = function () {
		__list.style.display = '';
		__hidden = false;
	}
	
	var toggleList = function () {
		if (__hidden) showList();
		else hideList();
	}
	
	var makeBold = function () {
		__h.style.fontWeight = 'bold';
	}
	
	var makeNormal = function () {
		__h.style.fontWeight = 'normal';
	}
	
	
	
	_init();
}

window.onload = function () {
	new RightMenu();
}