//--------------------------------------------
//Vx Theme (v1.00) for PHP-Fusion v6
//--------------------------------------------
//file: vx.js (javascript)
//author: Riadi (http://phpfusion-themes.com/)
//--------------------------------------------
//Released under the terms and conditions of
//the GNU General Public License (Version 2)
//--------------------------------------------

var DayNam = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var MnthNam = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

function Vx_Engine() {
	this.cookievalue = '';
	this.basedir = false;
};

Vx_Engine.prototype = {
	init : function(settings) {
		this.settings = settings;
		this.basedir = this.settings['basedir'];
		if (window.addEventListener) {
			window.addEventListener('load',Vx_Engine.prototype.onLoad,false);
		} else {
			window.attachEvent('onload',Vx_Engine.prototype.onLoad);
		}
	},
	onLoad : function() {
		var n = document.all ? document.all('contentbody').childNodes : document.getElementById('contentbody').childNodes;
		for (var i = 0;i < n.length;i++) {
			if (n[i].nodeName != 'TD' || (n[i].className.indexOf('side-border-') == -1 && n[i].className != 'main-bg'))
				continue;
			
			d = document.createElement('img');
			d.setAttribute('alt', 'spacer');
			d.setAttribute('height', '1');
			d.setAttribute('src', Vx.basedir +'images/blank.gif');
			d.setAttribute('width', (n[i].className == 'main-bg' ? '100%' : n[i].width));
			n[i].appendChild(d);
			
			if (n[i].className == 'side-border-left' && Vx.settings['hideleft'] == 'off') {
				var im = document.all ? document.all('panel_left_img') : document.getElementById('panel_left_img');
				n[i].style.display = 'none';
				im.src = im.src.replace('left_panel.gif','left_panel.gif');
			} 
			if (n[i].className == 'side-border-right' && Vx.settings['hideright'] == 'off') {
				var im = document.all ? document.all('panel_right_img') : document.getElementById('panel_right_img');
				n[i].style.display = 'none';
				im.src = im.src.replace('left_panel.gif','left_panel.gif');
			}
		}
	},
	showHideSide : function(side) {
		var n = document.all ? document.all('contentbody').childNodes : document.getElementById('contentbody').childNodes;
		var im = document.all ? document.all('panel_'+ side +'_img') : document.getElementById('panel_'+ side +'_img');
		for (var i = 0;i < n.length;i++) {
			if (n[i].nodeName != 'TD' || n[i].className != 'side-border-'+ side)
				continue;
			
			var s = n[i].style.display;
			n[i].style.display = (s == 'none' ? '' : 'none');
			if (im.src.indexOf('left_panel.gif') != -1) {
				im.src = im.src.replace('left_panel.gif','right_panel.gif');
			} else {
				im.src = im.src.replace('right_panel.gif','left_panel.gif');
			}
			this.cookieUpdate(side,(s == 'none' ? 'on' : 'off'));
			break;
		}
	},
	cookieUpdate : function(side,val) {
		var cv;
		if (side == 'left') {
			cv = 'hideleft:'+ val +'&hideright:';
			if (typeof(this.settings['hideright']) == 'undefined') { cv = cv + 'on'; }
			else { cv = cv + this.settings['hideright']; }
		} else {
			cv = 'hideright:'+ val +'&hideleft:';
			if (typeof(this.settings['hideleft']) == 'undefined') { cv = cv + 'on'; }
			else { cv = cv + this.settings['hideleft']; }			
		}
		var days = 30;
		var date = new Date();
		date.setTime(date.getTime()+(days *24*60*60*1000));
		var expires = '; expires='+ date.toGMTString();
		document.cookie = 'Vx_Theme='+ cv + expires +'; path=/';			
	},
	tick : function() {
		var hours,minutes,seconds,ap,intHours,intMinutes,intSeconds,today;
		today = new Date();
		intDay = today.getDay();
		intDate = today.getDate();
		intMonth = today.getMonth();
		intYear = today.getYear();
		intHours = today.getHours();
		intMinutes = today.getMinutes();
		intSeconds = today.getSeconds();
		timeString = DayNam[intDay]+', '+intDate;
		if (intDate == 1 || intDate == 21 || intDate == 31) {
			timeString= timeString + 'st ';
		} else if (intDate == 2 || intDate == 22) {
			timeString= timeString + 'nd ';
		} else if (intDate == 3 || intDate == 23) {
			timeString= timeString + 'rd ';
		} else {
			timeString = timeString + 'th ';
		} 
		if (intYear < 2000){
			intYear += 1900;
		}
		timeString = timeString+' of '+MnthNam[intMonth]+' '+intYear;
		if (intHours == 0) {
			hours = '12:';
			ap = 'am.';
		} else if (intHours < 12) { 
			hours = intHours+':';
			ap = 'am.';
		} else if (intHours == 12) {
			hours = '12:';
			ap = 'pm.';
		} else {
			intHours = intHours - 12
			hours = intHours + ':';
			ap = 'pm.';
		}
		if (intMinutes < 10) {
			minutes = '0'+intMinutes;
		} else {
			minutes = intMinutes;
		}
		if (intSeconds < 10) {
			seconds = ':0'+intSeconds;
		} else {
			seconds = ':'+intSeconds;
		}
		timeString = document.all ? timeString+', '+hours+minutes+seconds+' '+ap : timeString+', '+hours+minutes+seconds+' '+ap;
		var clock = document.all ? document.all('Clock') : document.getElementById('Clock');
  		clock.innerHTML = timeString;
	  	(document.all) ? window.setTimeout(Vx_Engine.prototype.tick, 1000) : window.setTimeout(Vx_Engine.prototype.tick, 1000);
	}
};

var Vx = new Vx_Engine;
