/*global window, localStorage, fontSizeTitle, bigger, reset, smaller, biggerTitle, resetTitle, smallerTitle, Cookie */
var prefsLoaded = false;
var defaultFontSize = 80;
var currentFontSize = defaultFontSize;
var fontSizeTitle='Text Size:';
var bigger='<img src="templates/gulfideas/images/larger.gif">';
var smaller='<img src="templates/gulfideas/images/smaller.gif">';
var reset='<img src="templates/gulfideas/images/default.gif">';
var biggerTitle='Make Text Bigger';
var smallerTitle='Make Text Smaller';
var resetTitle='Reset Text to Orignal Size';

Object.append(Browser.Features, {
	localstorage: (function() {
		return ('localStorage' in window) && window.localStorage !== null;
	})()
});


function colorChange(e)
{
//alert(e);
//mainContent = document.getElementById('#page');

var themes = new Array();
themes[3]='black';
themes[1]='blue';
themes[4]='green';
themes[2]='red';


if(document.getElementById('page'))
	{
		document.getElementById('page').style.backgroundImage ='url(templates/gulfideas/images/'+themes[e]+'/pagebg.jpg)';
		document.getElementById('main').style.backgroundImage ='url(templates/gulfideas/images/'+themes[e]+'/topbg.jpg)';
	}

if(document.getElementById('main2')){
	document.getElementById('main2').style.backgroundImage ='url(templates/gulfideas/images/'+themes[e]+'/linkbg.jpg)';
}
/*
#page     pagebg.jpg
#main     topbg.jpg
#main2   linkbg.jpp
*/
}

function setFontSize(fontSize) {
	document.body.style.fontSize = fontSize + '%';
	//document.p.style.fontSize = fontSize + '%';
}

function changeFontSize(sizeDifference) {
	currentFontSize = parseInt(currentFontSize, 10) + parseInt(sizeDifference * 5, 10);
	if (currentFontSize > 180) {
		currentFontSize = 180;
	} else if (currentFontSize < 60) {
		currentFontSize = 60;
	}
	setFontSize(currentFontSize);
}

function revertStyles() {
	currentFontSize = defaultFontSize;
	changeFontSize(0);
}

function writeFontSize(value) {
	if (Browser.Features.localstorage) {
		localStorage.fontSize = value;
	} else {
		Cookie.write("fontSize", value, {duration: 180});
	}
}

function readFontSize() {
	if (Browser.Features.localstorage) {
		return localStorage.fontSize;
	} else {
		return Cookie.read("fontSize");
	}
}

function setUserOptions() {
	if (!prefsLoaded) {
		var size = readFontSize();
		currentFontSize = size ? size : defaultFontSize;
		setFontSize(currentFontSize);
		prefsLoaded = true;
	}
}

function addControls() {
	var container = document.id('fontsize');
	var content = '<span class="fontsizetitle">'+ fontSizeTitle +'</span><span><a title="'+ biggerTitle +'"  href="#" onclick="changeFontSize(2); return false">'+ bigger +'</a><span class="unseen">&nbsp;</span><a href="#" title="'+resetTitle+'" onclick="revertStyles(); return false">'+ reset +'</a><span class="unseen">&nbsp;</span><a href="#"  title="'+ smallerTitle +'" onclick="changeFontSize(-2); return false">'+ smaller +'</a></span>';
	container.set('html', content);
}

function saveSettings() {
	writeFontSize(currentFontSize);
}

window.addEvent('domready', setUserOptions);
window.addEvent('domready', addControls);
window.addEvent('unload', saveSettings);


function changecolor(e,color)
{
var mainContent = "";
mainContent = document.getElementById(e);
mainContent.style.backgroundColor = color;
}
