
	/****
	 *
	 *   PHP-Fusion Content Management System (c)2004/7 CSS file Fuzeblog - 
	 *
	 *   Released under the terms and conditions of the
	 *   GNU General Public License (http://gnu.org).
	 *
	 *   Fuzed Themes - http://www.phpfusion-themes.com
	 *
	 */
	
	var FuzeBlog = {
		displayClock: function() {
			var days = 'Воскресенье,Понедельник,Вторник,Среда,Четверг,Пятница,Суббота';
			var months = 'января,февраля,марта,апреля,мая,июня,июля,августа,сентября,октября,ноября,декабря';
			var time = new Date();
			var year = time.getYear(), month = time.getMonth(), date = time.getDate(), day = time.getDay(), hours = time.getHours(), minutes = time.getMinutes(), seconds = time.getSeconds();
			var string = days.split(',')[day] + ", " + date + " " + months.split(',')[month] + " 20" + (String(year).substring(2).length == 1 ? '0' + String(year).substring(2) : String(year).substring(2)) + " г., " + hours + ":" + (minutes < 10 ? '0' + minutes : minutes) + ":" + (seconds < 10 ? '0' + seconds : seconds);
			FuzeBlog.clock.innerHTML = string;
			setTimeout(FuzeBlog.displayClock, 1000);
		},
		
		construct: function() {
			FuzeBlog.parseImages(FuzeBlog.cookie.scheme);
		
			var container = FuzeBlog.find('fuzeblog_content');
			if(container)
			{
				for(var node, i = 0; node = container.childNodes[i]; i++)
				{
					if(node.nodeName.toLowerCase() != 'td' || !node.className.match(/(main-bg|side-border-)/)) continue;

					var name = node.className.replace(/(-bg|side-border-)/i, '');
					
					var image = document.createElement('img');
					image.setAttribute('height', '1');
					image.setAttribute('src', FuzeBlog.settings.themedir + 'images/blank.gif');
					image.setAttribute('width', node.width || '100%');
					node.appendChild(image);
					
					FuzeBlog.colums[name] = node;
					
					if(FuzeBlog.cookie['hide_' + name] && FuzeBlog.cookie['hide_' + name] == 'yes') node.style.display = 'none';
				}
			}
			
			if(FuzeBlog.colums.main) FuzeBlog.colums.main.insertBefore(FuzeBlog.createTool(), FuzeBlog.colums.main.firstChild);
			if(FuzeBlog.displayClock) FuzeBlog.displayClock();
			
			window.setTimeout(function() {
				FuzeBlog.find('fuzeblog_load').style.display = 'none';
				FuzeBlog.find('fuzeblog_body').style.display = 'block';
					
				if(document.location.href.indexOf('#') != -1) document.location.href = document.location.href.substring(document.location.href.lastIndexOf('#'));
			}, 200);
		},
		
		colums: {},
		
		createTool: function() {
			var tool = document.createElement('div');
			tool.id = 'tool';
			
			this.clock = document.createElement('div');
			this.clock.id = 'tool_clock';
			tool.appendChild(this.clock);
			
			var menu = document.createElement('ul');
			menu.id = 'tool_menu';
			
			var button = document.createElement('li');
			button.appendChild(document.createTextNode('Вид'));
			button.className = 'button';
			button.onmouseover = function() { this.className += ' hover'; };
			button.onmouseout = function() { this.className = this.className.replace(' hover', ''); };
			
			var submenu = document.createElement('ul');
			button.appendChild(submenu);
			menu.appendChild(button);
			tool.appendChild(menu);
			
			var sides = new Array('left', 'right');
			var added = false;
			
			for(var item, link, image, title, side, i = 0; side = sides[i]; i++)
			{
				if(this.colums[side])
				{
					item = document.createElement('li');

					image = document.createElement('img');
					image.setAttribute('height', 16);
					image.setAttribute('src', this.settings.themedir + 'images/sh' + side + '.png');
					image.setAttribute('width', 16);
					
					link = document.createElement('a');
					link.id = 'tool_hide_' + side;
					link.appendChild(image);
					
					if(this.colums[side].style.display == 'none') title = String('Show %side column').replace('%side', side);
					else title = String('Hide %side column').replace('%side', side);

					link.appendChild(document.createTextNode(title));
					item.appendChild(link);
					submenu.appendChild(item);
					
					link.onmouseover = function() { this.className = 'hover'; };
					link.onmouseout = function() { this.className = ''; };
					
					this.createEvent(link, 'click', this.handleMenu);
					added = true;
				}
			}
			
			if(added) item.className = 'seperator';

			if(this.schemes)
			{
				for(var scheme in this.schemes)
				{
					var item = document.createElement('li');
					
					var link = document.createElement('a');
					link.id = 'tool_scheme_' + scheme;
					link.title = scheme;
					
					var preview = document.createElement('div');
					preview.className = 'tool_preview';
					preview.style.backgroundColor = this.schemes[scheme];
					
					link.appendChild(preview);
					link.appendChild(document.createTextNode(scheme));
					item.appendChild(link);
					submenu.appendChild(item);
					
					link.onmouseover = function() { this.className = 'hover'; };
					link.onmouseout = function() { this.className = ''; };
					
					this.createEvent(link, 'click', this.handleMenu);
				}
			}
			
			var br = document.createElement('br');
			tool.appendChild(br);
			
			return tool;
		},
	
		handleMenu: function(e) {
			if(document.all) e = event;
			var element = document.all ? e.srcElement : this;
	
			if(element.id)
			{
				var id = element.id.replace('tool_', '');
				var type = id.split('_')[0], option = id.split('_')[1];	
				
				if(type == 'hide')
				{
					if(!FuzeBlog.colums[option]) return;
	
					var target = FuzeBlog.colums[option];
					if(target.style.display == 'none')
					{
						target.style.display = '';
						element.replaceChild(
							document.createTextNode(String('Hide %side column').replace('%side', option)),
							element.lastChild
						);
						FuzeBlog.cookie[id] = null;
					}
					else
					{
						target.style.display = 'none';
						element.replaceChild(
							document.createTextNode(String('Show %side column').replace('%side', option)),
							element.lastChild
						);
						FuzeBlog.cookie[id] = 'yes';
					}
					
					// Browser sniffing is wrong, Kids.
					if(navigator.userAgent.indexOf('Opera') != -1) FuzeBlog.destruct();
				}
				else if(type == 'scheme')
				{
					if(FuzeBlog.cookie.scheme == option) return;
			
					FuzeBlog.link.href = FuzeBlog.link.href.replace('scheme=' + FuzeBlog.cookie.scheme, 'scheme=' + option);
					FuzeBlog.parseImages(option);
			
					FuzeBlog.cookie.scheme = option;

					// Browser sniffing is wrong, Kids.
					if(navigator.userAgent.indexOf('Opera') != -1) FuzeBlog.destruct();
				}
			}	
		},
	
		destruct: function() {
			var comma = '', string = '';
			
			for(var key in FuzeBlog.cookie)
			{
				var value = FuzeBlog.cookie[key];
				if(value !== null)
				{
					string += comma + key + ':' + value;
					comma = ',';
				}
			}
			
			if(string != '')
			{
				var date = new Date();
				date.setTime(date.getTime() + 2592000000);
			
				document.cookie = 'FuzeBlog=' + string + '; expires=' + date.toGMTString() + '; path=/';
			}
		},
	
		initialize: function(settings, cookie, schemes) {
			this.settings = settings;
			this.cookie = cookie;
			this.schemes = schemes;
			
			this.link = document.createElement('link');
			this.link.setAttribute('href', this.settings.themedir + 'fuzeblog.php?type=stylesheet&scheme=' + this.cookie.scheme);
			this.link.setAttribute('rel', 'stylesheet');
			this.link.setAttribute('type', 'text/css');
			document.getElementsByTagName('head')[0].appendChild(this.link);		
			
			this.createEvent(window, 'load', this.construct);
			this.createEvent(window, 'beforeunload', this.destruct);
		},
		
		logo: false,
		
		parseImages: function(scheme) {
			var images = document.getElementsByTagName('img');
			for(var image, i = 0; image = images[i]; i++)
			{
				if(image.src.match(/\/(bullet.gif|bulletb.gif|logo.png|panel_on.gif|panel_off.gif|pollbar.gif)/))
				{
					if(!this.logo && image.src.match(/\/logo.png/) && navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf('MSIE 7') == -1 && navigator.userAgent.indexOf('Opera') == -1)
					{
						this.logo = image;
						continue;
					}
					
					var name = image.src.substr(image.src.lastIndexOf('/'));
					image.src = this.settings.themedir + 'images/' + scheme + name;
				}
			}
			
			if(this.logo)
			{
				this.logo.src = this.settings.themedir + 'images/' + scheme + '/logo.png';
				this.logo.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + this.logo.src + '", sizingMethod="crop")';
				this.logo.src = this.settings.themedir + 'images/blank.gif';	
			}
		},
		
		find: function(id) {
			var doc = document;
			
			if(doc.getElementById && doc.getElementById(id)) return doc.getElementById(id);
			else if(doc.all && doc.all(id)) return doc.all(id);
			else if(doc.layers && doc.layers[id]) return doc.layers[id];
			
			return false;
		},
		
		createEvent: function(element, event, action) {
			if(element.attachEvent) element.attachEvent('on' + event, action);
			else if(element.addEventListener) element.addEventListener(event, action, false);
		}
	};
	