//--------------------------------------------------------------------------------------------------------------------------------------------------------------------->
/*
	PEPI OS CORE JS - COPYRIGHT 2009 PEZUS WEB DESIGN ALL RIGHTS RESERVED
	This file contains core global variables, save/load functions and the login/logout scripts.
	This file is compressed using JSMin once implemented.
	File Version: 1.0
*/
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------->
/*
	Global variables that work better than being defined locally
*/
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------->
var ROOT_URL = "http://www.pepi-os.com/";var cookieStrFnd = / ":" /;var jsPluginsLoadCount=0;var toggleMainMD;
//---------------------------------------->
var userName = "Guest";
var userPhoto = ROOT_URL+"system/images/pp3.jpg";
var encryptedPass="notSetByUser";
var ssType="ssNone";
var ssColor="#000000";
var nowTheme = "defaultTheme";
var nowWallpaper = "defaultWallpaper";
//---------------------------------------->
var sysGammaLevel = "10"; parseFloat(sysGammaLevel);
var ssDelay="1000"; ssDelay=parseFloat(ssDelay);
var ssOpacity="0.8"; ssOpacity=parseFloat(ssOpacity);
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------->
/*
	System Loader and Login Functions
*/
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------->
function loadAssets(what){
	if(what===0){
		new Asset.javascript(ROOT_URL+'system/javascript/plugins.js');
		new Asset.javascript(ROOT_URL+'system/javascript/plugins2.js');
		new Asset.javascript(ROOT_URL+'system/javascript/core_classes.js');
		new Asset.javascript(ROOT_URL+'system/javascript/core_functions.js');
		new Asset.javascript(ROOT_URL+'system/javascript/core_applications.js');
		loadAssets.delay(100, null, 1);
	}
	else if(what===1){
		$('loadingwhat').set('html', 'Compatibility Tests');
		if(jsPluginsLoadCount==5){
			if(Browser.Plugins.Flash.version<9 || Browser.Engine.trident4){
				$('loadingBar').destroy();
				new PosAlerts({id: 'compatbFailed', width: 300, height: 150, type: 'alert', title: 'Compatibility Error!', message: 'Sorry! Your system does not meet the minimum requirements.<br/>Pepi OS is not available on Internet Explorer 6 and requires the most recent version of Flash installed!'});
			}
			else{
				posIconOffsets=new PosIconOffsets();
				theGlobalZIndex=new PosGlobalZIndex();
				systemVolumeInit=new PosVolume();
				toggleFlagsClass=new PosSettingStore();
				$('loadingwhat').set('html', 'Themes');
				var firstCookie = Cookie.read('themessettings');
				if(firstCookie===null){
					tempString=ROOT_URL+"system/images/";
					new Asset.images([tempString+'menubutton.png', ROOT_URL+'system/css/wallpaper/default.jpg', tempString+'track.png', tempString+'topright.png', tempString+'topleft.png', tempString+'topinnerright.png', tempString+'topinnerleft.png', tempString+'tips.png', tempString+'taskbarletrightover.png', tempString+'taskbarletright.png', tempString+'taskbarletmiddleover.png', tempString+'taskbarletmiddle.png', tempString+'taskbarletleftover.png', tempString+'taskbarletleft.png', tempString+'taskbarback.png', tempString+'sliderhandle.png', tempString+'slider.png', tempString+'ok.png', tempString+'minusplus.png', tempString+'middleright.png', tempString+'middleleft.png', tempString+'middleinnerright.png', tempString+'middleinnerleft.png', tempString+'menubutton2.png', tempString+'mainmenutop.png', tempString+'mainmenumiddle.png', tempString+'mainmenubottom.png', tempString+'handle.png', tempString+'cancel.png', tempString+'cancel2.png', tempString+'buttons.png', tempString+'bottomright.png', tempString+'bottomleft.png', tempString+'bottominnerright.png', tempString+'bottominnerleft.png', tempString+'apply.png', tempString+'alertstopright.png', tempString+'alertstopleft.png', tempString+'alertsmiddleright.png', tempString+'alertsmiddleleft.png', tempString+'alertsbottomright.png', tempString+'alertsbottomleft.png', tempString+'pepioslogosmall.png', tempString+'expand_down.png', tempString+'expand_right.png', tempString+'mainloader.gif', tempString+'mainloaderblack.gif', ROOT_URL+'system/images/pp1.jpg', ROOT_URL+'system/images/pp2.jpg', ROOT_URL+'system/images/pp3.jpg', ROOT_URL+'system/images/pp4.jpg', ROOT_URL+'system/images/pp5.jpg', ROOT_URL+'system/images/pp6.jpg', ROOT_URL+'system/images/pp7.jpg', ROOT_URL+'system/images/pp8.jpg', ROOT_URL+'system/images/pp9.jpg', ROOT_URL+'system/images/pp10.jpg', ROOT_URL+'system/images/login.png', ROOT_URL+'system/images/loginasguest.png'], {
						onComplete: function(){
							loadAssets.delay(500, null, 2);
						}
					});	
				}
				else{
					nowTheme=firstCookie.split(cookieStrFnd)[2];
					if(nowTheme!="defaultTheme"){
						tempString=nowTheme;
						tempString=tempString.split("/");
						tempString=tempString.erase(tempString.getLast());
						tempString=tempString.join("/")+"/";
						new Asset.images([tempString+'menubutton.png', tempString+'wallpaper.jpg', tempString+'track.png', tempString+'topright.png', tempString+'topleft.png', tempString+'topinnerright.png', tempString+'topinnerleft.png', tempString+'tips.png', tempString+'taskbarletrightover.png', tempString+'taskbarletright.png', tempString+'taskbarletmiddleover.png', tempString+'taskbarletmiddle.png', tempString+'taskbarletleftover.png', tempString+'taskbarletleft.png', tempString+'taskbarback.png', tempString+'sliderhandle.png', tempString+'slider.png', tempString+'ok.png', tempString+'minusplus.png', tempString+'middleright.png', tempString+'middleleft.png', tempString+'middleinnerright.png', tempString+'middleinnerleft.png', tempString+'menubutton2.png', tempString+'mainmenutop.png', tempString+'mainmenumiddle.png', tempString+'mainmenubottom.png', tempString+'handle.png', tempString+'cancel.png', tempString+'cancel2.png', tempString+'buttons.png', tempString+'bottomright.png', tempString+'bottomleft.png', tempString+'bottominnerright.png', tempString+'bottominnerleft.png', tempString+'apply.png', tempString+'alertstopright.png', tempString+'alertstopleft.png', tempString+'alertsmiddleright.png', tempString+'alertsmiddleleft.png', tempString+'alertsbottomright.png', tempString+'alertsbottomleft.png', tempString+'pepioslogosmall.png', tempString+'expand_down.png', tempString+'expand_right.png', tempString+'mainloader.gif', tempString+'mainloaderblack.gif', ROOT_URL+'system/images/pp1.jpg', ROOT_URL+'system/images/pp2.jpg', ROOT_URL+'system/images/pp3.jpg', ROOT_URL+'system/images/pp4.jpg', ROOT_URL+'system/images/pp5.jpg', ROOT_URL+'system/images/pp6.jpg', ROOT_URL+'system/images/pp7.jpg', ROOT_URL+'system/images/pp8.jpg', ROOT_URL+'system/images/pp9.jpg', ROOT_URL+'system/images/pp10.jpg', ROOT_URL+'system/images/login.png', ROOT_URL+'system/images/loginasguest.png'], {
							onComplete: function(){
								if($('modifiedtheme')){
									$('modifiedtheme').setProperty('href', nowTheme);	
								}
								else{
									new Asset.css(nowTheme, {id: 'modifiedtheme', media: 'screen'});
								}
								loadAssets.delay(500, null, 2);
							}
						});
					}
					else{
						tempString=ROOT_URL+"system/images/";
						new Asset.images([tempString+'menubutton.png', ROOT_URL+'system/css/wallpaper/default.jpg', tempString+'track.png', tempString+'topright.png', tempString+'topleft.png', tempString+'topinnerright.png', tempString+'topinnerleft.png', tempString+'tips.png', tempString+'taskbarletrightover.png', tempString+'taskbarletright.png', tempString+'taskbarletmiddleover.png', tempString+'taskbarletmiddle.png', tempString+'taskbarletleftover.png', tempString+'taskbarletleft.png', tempString+'taskbarback.png', tempString+'sliderhandle.png', tempString+'slider.png', tempString+'ok.png', tempString+'minusplus.png', tempString+'middleright.png', tempString+'middleleft.png', tempString+'middleinnerright.png', tempString+'middleinnerleft.png', tempString+'menubutton2.png', tempString+'mainmenutop.png', tempString+'mainmenumiddle.png', tempString+'mainmenubottom.png', tempString+'handle.png', tempString+'cancel.png', tempString+'cancel2.png', tempString+'buttons.png', tempString+'bottomright.png', tempString+'bottomleft.png', tempString+'bottominnerright.png', tempString+'bottominnerleft.png', tempString+'apply.png', tempString+'alertstopright.png', tempString+'alertstopleft.png', tempString+'alertsmiddleright.png', tempString+'alertsmiddleleft.png', tempString+'alertsbottomright.png', tempString+'alertsbottomleft.png', tempString+'pepioslogosmall.png', tempString+'expand_down.png', tempString+'expand_right.png', tempString+'mainloader.gif', tempString+'mainloaderblack.gif', ROOT_URL+'system/images/pp1.jpg', ROOT_URL+'system/images/pp2.jpg', ROOT_URL+'system/images/pp3.jpg', ROOT_URL+'system/images/pp4.jpg', ROOT_URL+'system/images/pp5.jpg', ROOT_URL+'system/images/pp6.jpg', ROOT_URL+'system/images/pp7.jpg', ROOT_URL+'system/images/pp8.jpg', ROOT_URL+'system/images/pp9.jpg', ROOT_URL+'system/images/pp10.jpg', ROOT_URL+'system/images/login.png', ROOT_URL+'system/images/loginasguest.png'], {
							onComplete: function(){
								loadAssets.delay(500, null, 2);
							}
						});	
					}
				}
			}
		}
		else{
			$('loadingwhat').set('html', 'Compatibility Tests');
			loadAssets.delay(100, null, 1);
		}
	}
	else if(what===2){
		$('loadingwhat').set('html', 'Wallpaper');
		var secondCookie = Cookie.read('wallpapersettings');
		if(secondCookie===null){
			loadAssets.delay(500, null, 3);
		}
		else{
			nowWallpaper=secondCookie.split(cookieStrFnd)[2];
			if($('wallpapercss')){
				$('wallpapercss').destroy();
				if($('modifiedtheme')){
					new Asset.css(nowWallpaper, {id: 'wallpapercss', media: 'screen'}).inject('modifiedtheme',  'after');
				}
				else{
					new Asset.css(nowWallpaper, {id: 'wallpapercss', media: 'screen'}).inject('themecss',  'after');
				}
			}
			else{
				if($('modifiedtheme')){
					new Asset.css(nowWallpaper, {id: 'wallpapercss', media: 'screen'}).inject('modifiedtheme',  'after');
				}
				else{
					new Asset.css(nowWallpaper, {id: 'wallpapercss', media: 'screen'}).inject('themecss',  'after');
				}
			}
			loadAssets.delay(500, null, 3);
		}
	}
	else if(what===3){
		$('loadingwhat').set('html', 'Sounds');
		if(toggleFlagsClass.options.toggleFlag2===true){	
			wpsTemp=Cookie.read('generalsettings');
			if(wpsTemp!=null){
				systemVolumeInit.setVolume();
			}
			posSound0 = soundManager.createSound({id: 'posSound0',url: 'system/sounds/start.mp3'});
			posSound1 = soundManager.createSound({id: 'posSound1',url: 'system/sounds/end.mp3'});
			posSound2 = soundManager.createSound({id: 'posSound2',url: 'system/sounds/click.mp3'});
			posSound3 = soundManager.createSound({id: 'posSound3',url: 'system/sounds/appstart.mp3'});
			posSound4 = soundManager.createSound({id: 'posSound4',url: 'system/sounds/append.mp3'});
			posSound5 = soundManager.createSound({id: 'posSound5',url: 'system/sounds/minmax.mp3'});
			posSound6 = soundManager.createSound({id: 'posSound6',url: 'system/sounds/notification.mp3'});
			posSound7 = soundManager.createSound({id: 'posSound7',url: 'system/sounds/alertconfirmdebug.mp3'});
			systemVolumeInit.updateVolume();
			displayLoginBox.delay(500, null, 0);
		}
		else{
			soundManager.beginDelayedInit();soundManager.onload();
			loadAssets.delay(100, null, 3);
		}
	}
}
//---------------------------------------->
function displayLoginBox(what){
	if(what===0){
		$('loadingBar').destroy();
		$('loadingLogoBar').setStyles({'height': '179px', 'min-height': '179px'});
		var lBD = new Fx.Tween('loadingLogoBar',{duration:'long'}).start('margin-top','-200px');
		lBD.addEvent('onComplete', function(){  
			displayLoginBox.run(1);
		});
	}
	else if(what===1){
		var thirdCookie = Cookie.read('usernameandphoto');
		if(thirdCookie!=null){
			encryptedPass=thirdCookie.split(cookieStrFnd)[4];
			userName=thirdCookie.split(cookieStrFnd)[2];
			userPhoto=thirdCookie.split(cookieStrFnd)[3];	
		}
		new Element('div', {'id':'loadingLoginForm'}).inject('loadingLogoBar', 'after');
		new Element('form', {'id':'loadingLoginFormForm', 'action':ROOT_URL+'system/php/loginnow.php'}).inject('loadingLoginForm', 'bottom');
		$('loadingLoginFormForm').addEvent('submit', function(e){
			e.stop();
			new Request.HTML({
				evalScripts: true,
				evalResponse: true,
				url: this.getProperty('action'),
				data: this.toQueryString(),
				link: 'ignore',
				noCache: true,
				onRequest: function(){
					$('userButtonLogin').set('html', '<img src="'+ROOT_URL+'system/images/loading.gif"/>');
				},
				onSuccess: function(html){
					loginRequest();
				},
				onFailure: function(xhr){
					new PosAlerts({id: 'debugFailedLogin', width: 370, height: 110, type: 'debug', title: 'Error!', message: 'There was an error when trying to login. We are working on this issue but it may be an issue with your system as well. Click OK to send debug info.', debugCode: '0015'});
					$('userButtonLogin').set('html', '<input type="image" src="'+ROOT_URL+'system/images/login.png"/>');
				},
				onCancel: function(){
					new PosAlerts({id: 'cancellogin', width: 300, height: 110, type: 'alert', title: 'Error!', message: 'You or your browser stopped the connection to Pepi OS.'});
					$('userButtonLogin').set('html', '<input type="image" src="'+ROOT_URL+'system/images/login.png"/>');
				},
				onException: function(headerName, value){
					new PosAlerts({id: 'debugFailedLogin', width: 370, height: 110, type: 'debug', title: 'Error!', message: 'There was an error when trying to login. We are working on this issue but it may be an issue with your system as well. Click OK to send debug info.', debugCode: '0016'});
					$('userButtonLogin').set('html', '<input type="image" src="'+ROOT_URL+'system/images/login.png"/>');
				}
			}).send();
		});
		if(thirdCookie===null){
			$('loadingLoginForm').setStyles({'width':'233px','margin':'-15px 0 0 -116px'});
			new Element('div', {'id':'userPhotoLogin', 'html': '<img src="'+userPhoto+'" alt="'+userName+'"/>'}).inject('loadingLoginFormForm', 'bottom');
			new Element('div', {'id':'userIsGuest', 'html': '<img id="deletethispleaseLogin" src="'+ROOT_URL+'system/images/loginasguest.png" alt="Login as Guest" onclick="afterLoginSuccess();"/>'}).inject('loadingLoginFormForm', 'bottom');
			new Element('div', {'class':'clear'}).inject('loadingLoginFormForm', 'bottom');
		}
		else if(thirdCookie!=null && userName=="Guest"){
			$('loadingLoginForm').setStyles({'width':'233px','margin':'-15px 0 0 -116px'});
			new Element('div', {'id':'userPhotoLogin', 'html': '<img src="'+userPhoto+'" alt="'+userName+'"/>'}).inject('loadingLoginFormForm', 'bottom');
			new Element('div', {'id':'userIsGuest', 'html': '<img id="deletethispleaseLogin" src="'+ROOT_URL+'system/images/loginasguest.png" alt="Login as Guest" onclick="afterLoginSuccess();"/>'}).inject('loadingLoginFormForm', 'bottom');
			new Element('div', {'class':'clear'}).inject('loadingLoginFormForm', 'bottom');
		}
		else if(thirdCookie!=null && encryptedPass=="notSetByUser"){
			$('loadingLoginForm').setStyles({'width':'400px','margin':'-15px 0 0 -150px'});
			new Element('div', {'id':'userPhotoLogin', 'html': '<img src="'+userPhoto+'" alt="'+userName+'"/>'}).inject('loadingLoginFormForm', 'bottom');
			new Element('div', {'id':'userIsGuest', 'html': '<img src="'+ROOT_URL+'system/images/login.png" alt="Login Now" onclick="$(\'userIsGuest\').destroy();new Element(\'div\', {\'id\':\'userNameLogin2\', \'html\': \'Welcome back '+userName+'!\'}).inject(\'userPhotoLogin\', \'after\');afterLoginSuccess();"/>'}).inject('loadingLoginFormForm', 'bottom');
			new Element('div', {'class':'clear'}).inject('loadingLoginFormForm', 'bottom');
		}
		else{
			new Element('div', {'id':'userPhotoLogin', 'html': '<img src="'+userPhoto+'" alt="'+userName+'"/>'}).inject('loadingLoginFormForm', 'bottom');
			new Element('div', {'id':'userNameLogin', 'html': 'Username:<br/><input type="text" class="input" name="usernameinput" id="usernameinput"/>'}).inject('loadingLoginFormForm', 'bottom');
			new Element('div', {'id':'userPasswordLogin', 'html': 'Password:<br/><input type="password" class="input" name="userpasswordinput" id="userpasswordinput"/>'}).inject('loadingLoginFormForm', 'bottom');
			new Element('div', {'id':'userButtonLogin', 'html': '<input type="image" src="'+ROOT_URL+'system/images/login.png"/>'}).inject('loadingLoginFormForm', 'bottom');
			new Element('div', {'id':'resetSettings', 'html': '<div onclick="deleteSettings(\'all\');">I forgot my login info!</div>'}).inject('loadingLoginFormForm', 'bottom');
			new Element('div', {'class':'clear'}).inject('loadingLoginFormForm', 'bottom');
		}
	}
}
//---------------------------------------->
function afterLoginSuccess(){
	//posSound0.play();
	if($('deletethispleaseLogin')){
		$('deletethispleaseLogin').destroy();
		$('userIsGuest').setStyle('cursor','default');
	}
	var lSF = new Fx.Tween('loginLoadScreen',{duration:4000}).start('opacity',0);
	lSF.addEvent('onComplete', function(){$('loginLoadScreen').destroy()});
	//---------------------------------------->
	loadSetting('all');
	new PosUptime({id: 'uptimeDiv'});
	new PosSystemTime({id: 'posTheDate'});
	//-------------------------------------------------------------------------------------------------------->
	tipCalls = new Tips('.tipme', {className: 'tipmeclass', fixed: true, showDelay: 500, hideDelay: 10});
	tipCalls2 = new Tips('.tipme2', {className: 'tipmeclass', fixed: false, showDelay: 500, hideDelay: 10});
	if(toggleFlagsClass.options.domTipShow=="off"){
		tipCalls.attach('.tipme');tipCalls2.attach('.tipme2');
		tipCalls.detach('.tipme');tipCalls2.detach('.tipme2');
	}
	//------------------------------------------------------------------------->
	new UvumiDropdown("posMainMenuDropDown",{mode:'vertical', closeDelay: 200});
	toggleFlagsClass.setOptions({toggleFlag: false});
	toggleMainMenuFx = new Fx.Tween('posMainMenu', {link: 'chain'});
	//-------------->
	attachEvents();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------->
/*
	The SAVE and LOAD setting functions take care of most of the Cookie setting, retrieving and reading for POS.
*/
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------->
function saveSetting(setting){
	//general settings save
	if($('generalSettingsIcon') && setting=="all"){
		Cookie.write('generalsettings', $('generalSettingsIcon').getPosition().x+' ":" '+$('generalSettingsIcon').getPosition().y+' ":" '+systemVolumeInit.getVolume()+' ":" '+systemVolumeInit.getState()+' ":" '+toggleFlagsClass.options.domTipShow, {duration: 99999});
	}
	else{
		Cookie.write('generalsettings', 'hidden ":" hidden ":" '+systemVolumeInit.getVolume()+' ":" '+systemVolumeInit.getState()+' ":" '+toggleFlagsClass.options.domTipShow, {duration: 99999});
	}
	//accessibility settings save
	if($('accessibilitySettingsIcon') && setting=="all"){
		 Cookie.write('accessibilitysettings', $('accessibilitySettingsIcon').getPosition().x+' ":" '+$('accessibilitySettingsIcon').getPosition().y+' ":" '+toggleFlagsClass.options.systemfontSize+' ":" '+toggleFlagsClass.options.systemfontWeight, {duration: 99999});
	}
	else{
		 Cookie.write('accessibilitysettings', 'hidden ":" hidden ":" '+toggleFlagsClass.options.systemfontSize+' ":" '+toggleFlagsClass.options.systemfontWeight, {duration: 99999});
	}
	//security settings save
	if($('securitySettingsIcon') && setting=="all"){
		Cookie.write('securitysettings', $('securitySettingsIcon').getPosition().x+' ":" '+$('securitySettingsIcon').getPosition().y+' ":" '+toggleFlagsClass.options.sendAnonInfo, {duration: 99999});
	}
	else{
		 Cookie.write('securitysettings', 'hidden ":" hidden ":" '+toggleFlagsClass.options.sendAnonInfo, {duration: 99999});
	}
	//user settings save
	if($('userSettingsIcon') && setting=="all"){
		Cookie.write('usernameandphoto', $('userSettingsIcon').getPosition().x+' ":" '+$('userSettingsIcon').getPosition().y+' ":" '+userName+' ":" '+userPhoto+' ":" '+encryptedPass, {duration: 99999});
	}
	else{
		Cookie.write('usernameandphoto', 'hidden ":" hidden ":" '+userName+' ":" '+userPhoto+' ":" '+encryptedPass, {duration: 99999});
	}
	//gamma settings save
	if($('gammaSettingsIcon') && setting=="all"){
		Cookie.write('gammasettings', $('gammaSettingsIcon').getPosition().x+' ":" '+$('gammaSettingsIcon').getPosition().y+' ":" '+sysGammaLevel, {duration: 99999});
	}
	else{
		Cookie.write('gammasettings', 'hidden ":" hidden ":" '+sysGammaLevel, {duration: 99999});
	}
	//screen saver settings save
	if($('screenSaverSettingsIcon') && setting=="all"){
		Cookie.write('screensaversettings', $('screenSaverSettingsIcon').getPosition().x+' ":" '+$('screenSaverSettingsIcon').getPosition().y+' ":" '+ssType+' ":" '+ssDelay+' ":" '+ssOpacity+' ":" '+ssColor, {duration: 99999});
	}
	else{
		Cookie.write('screensaversettings', 'hidden ":" hidden ":" '+ssType+' ":" '+ssDelay+' ":" '+ssOpacity+' ":" '+ssColor, {duration: 99999});
	}
	//themes settings save
	if($('themesSettingsIcon') && setting=="all"){
		Cookie.write('themessettings', $('themesSettingsIcon').getPosition().x+' ":" '+$('themesSettingsIcon').getPosition().y+' ":" '+nowTheme, {duration: 99999});
	}
	else{
		Cookie.write('themessettings', 'hidden ":" hidden ":" '+nowTheme, {duration: 99999});
	}
	//wallpaper settings save
	if($('wallpaperSettingsIcon') && setting=="all"){
		Cookie.write('wallpapersettings', $('wallpaperSettingsIcon').getPosition().x+' ":" '+$('wallpaperSettingsIcon').getPosition().y+' ":" '+nowWallpaper, {duration: 99999});
	}
	else{
		Cookie.write('wallpapersettings', 'hidden ":" hidden ":" '+nowWallpaper, {duration: 99999});
	}
	
	if(systemVolumeInit.getState()=="true"){
		posSound1.play();
	}
	//alert('Your session data has been saved!\n\n Goodbye!');
}
//---------------------------->
function loadSetting(setting){
	//user settings load
	if(setting=="usernameandphoto" || setting=="all"){
		if(Cookie.read('usernameandphoto')!=null && setting!="all"){
			wpsTemp=Cookie.read('usernameandphoto');
			if(wpsTemp.split(cookieStrFnd)[0]!="hidden"){
				$('displayUSOD').setProperty('checked', true);	
			}
			$('currentUsername').set('html', wpsTemp.split(cookieStrFnd)[2]);
			$('chosenUN').setProperty('value', wpsTemp.split(cookieStrFnd)[2]);
			for(x=0;x<9999;x++){
				if(userPhoto==$$('#userphotoselection .pp img')[x].getProperty('src')){
					$$('#userphotoselection .pp').removeClass('ppover');
					$$('#userphotoselection .pp img')[x].getParent().addClass('ppover');
					$('photowanted').setProperty('value', $$('#userphotoselection .pp img')[x].getProperty('src'));
					x=9999;
				}
			}
		}
		else if(Cookie.read('usernameandphoto')==null && setting!="all"){
			$('displayUSOD').setProperty('checked', false);
			$('chosenUN').setProperty('value', userName);
			$('currentUsername').set('html', userName);
			$$('#userphotoselection .pp img')[2].getParent().addClass('ppover');
			$('photowanted').setProperty('value', $$('#userphotoselection .pp img')[2].getProperty('src'));
		}
		if(setting=="all"){
			wpsTemp=Cookie.read('usernameandphoto');
			if(wpsTemp===null){
				$('posMainMenuTopName').set('html', '<img class="tipme" src="'+userPhoto+'" alt="'+userName+'" title="'+userName+'"/> '+userName);
			}
			else{
				if(wpsTemp.split(cookieStrFnd)[0]!="hidden"){
					userSettingsApp(2);
				}
				encryptedPass=wpsTemp.split(cookieStrFnd)[4];
				userName=wpsTemp.split(cookieStrFnd)[2];
				userPhoto=wpsTemp.split(cookieStrFnd)[3];
				$('posMainMenuTopName').set('html', '<img class="tipme" src="'+userPhoto+'" alt="'+userName+'" title="'+userName+'"/> '+userName);
			}
		}
	}
	
	//general settings load
	if(setting=="generalsettings" || setting=="all"){
		if(Cookie.read('generalsettings')!=null && setting!="all"){
			wpsTemp=Cookie.read('generalsettings');
			if(wpsTemp.split(cookieStrFnd)[0]!="hidden"){
				$('displayGSOD').setProperty('checked', true);
			}
			if(wpsTemp.split(cookieStrFnd)[4]=="off"){
				$('ttOff').setProperty('checked', true);
				tipCalls.detach('.tipme');tipCalls2.detach('.tipme2');
			}
			else{
				$('ttOn').setProperty('checked', true);
				tipCalls.attach('.tipme');tipCalls2.attach('.tipme2');
			}
			systemVolumeInit.setVolume();
			systemVolumeInit.createVolume();
			if(wpsTemp.split(cookieStrFnd)[3]=="false"){
				$('ttOff1').setProperty('checked', true);
			}
			else{
				$('ttOn1').setProperty('checked', true);
			}
		}
		else if(Cookie.read('generalsettings')==null && setting!="all"){
			$('displayGSOD').setProperty('checked', true);
			$('ttOn').setProperty('checked', true);
			tipCalls.attach('.tipme');tipCalls2.attach('.tipme2');
			systemVolumeInit.createVolume();
			$('ttOn1').setProperty('checked', true);
		}
		if(setting=="all"){
			wpsTemp=Cookie.read('generalsettings');
			if(wpsTemp!=null && wpsTemp.split(cookieStrFnd)[0]!="hidden"){
				generalSettingsApp(2);
			}
			else if(wpsTemp==null){
				generalSettingsApp(1);
			}
			if(wpsTemp!=null){
				toggleFlagsClass.setOptions({domTipShow: wpsTemp.split(cookieStrFnd)[4]});	
			}
			if(wpsTemp!=null && wpsTemp.split(cookieStrFnd)[3]=="false"){
				systemVolumeInit.setOptions({state: "false"});
			}
		}
	}
	//accessibility settings load
	if(setting=="accessibilitysettings" || setting=="all"){
		if(Cookie.read('accessibilitysettings')!=null && setting!="all"){
			wpsTemp=Cookie.read('accessibilitysettings');
			if(wpsTemp.split(cookieStrFnd)[0]!="hidden"){
				$('displayASOD').setProperty('checked', true);
			}
			toggleFlagsClass.setOptions({systemfontSize: wpsTemp.split(cookieStrFnd)[2]});
			fontSize(0);
			toggleFlagsClass.setOptions({systemfontWeight: wpsTemp.split(cookieStrFnd)[3]});
			fontWeight(0);
		}
		else if(Cookie.read('accessibilitysettings')==null && setting!="all"){
			$('displayASOD').setProperty('checked', false);
			fontSize(0);
			fontWeight(0);
		}
		if(setting=="all"){
			wpsTemp=Cookie.read('accessibilitysettings');
			if(wpsTemp!=null){
				if(wpsTemp.split(cookieStrFnd)[0]!="hidden"){
					accessibilitySettingsApp(2);
				}
				toggleFlagsClass.setOptions({systemfontSize: wpsTemp.split(cookieStrFnd)[2]});
				fontSize(1);
				toggleFlagsClass.setOptions({systemfontWeight: wpsTemp.split(cookieStrFnd)[3]});
				fontWeight(1);
			}
			else{
				toggleFlagsClass.setOptions({systemfontSize: "10"});
				fontWeight(1);
			}
		}
	}
	//security settings load
	if(setting=="securitysettings" || setting=="all"){
		if(Cookie.read('securitysettings')!=null && setting!="all"){
			wpsTemp=Cookie.read('securitysettings');
			if(wpsTemp.split(cookieStrFnd)[0]!="hidden"){
				$('displaySSOD').setProperty('checked', true);
			}
			if(wpsTemp.split(cookieStrFnd)[2]=="no"){
				$('ttOff2').setProperty('checked', true);
			}
			else{
				$('ttOn2').setProperty('checked', true);
			}
			
		}
		else if(Cookie.read('securitysettings')==null && setting!="all"){
			$('displaySSOD').setProperty('checked', false);
			$('ttOn2').setProperty('checked', true);
		}
		if(setting=="all"){
			wpsTemp=Cookie.read('securitysettings');
			if(wpsTemp!=null && wpsTemp.split(cookieStrFnd)[0]!="hidden"){
				securitySettingsApp(2);
			}
			if(wpsTemp!=null && wpsTemp.split(cookieStrFnd)[2]=="no"){
				toggleFlagsClass.setOptions({sendAnonInfo: "no"});
			}
			else{
				toggleFlagsClass.setOptions({sendAnonInfo: "yes"});
			}
		}
	}
	//gamma settings load
	if(setting=="gammasettings" || setting=="all"){
		if(Cookie.read('gammasettings')!=null && setting!="all"){
			wpsTemp=Cookie.read('gammasettings');
			if(wpsTemp.split(cookieStrFnd)[0]!="hidden"){
				$('displayGASOD').setProperty('checked', true);
			}
			gammaLevel(0);
		}
		else if(Cookie.read('gammasettings')==null && setting!="all"){
			$('displayGASOD').setProperty('checked', false);
			gammaLevel(0);
		}
		if(setting=="all"){
			wpsTemp=Cookie.read('gammasettings');
			if(wpsTemp!=null){
				if(wpsTemp.split(cookieStrFnd)[0]!="hidden"){
					gammaSettingsApp(2);
				}
					sysGammaLevel=wpsTemp.split(cookieStrFnd)[2];
					updateGamma(parseFloat(sysGammaLevel/10));
			}
			else{

			}
		}
	}
	//screensaver settings load
	if(setting=="screensaversettings" || setting=="all"){
		if(Cookie.read('screensaversettings')!=null && setting!="all"){
			wpsTemp=Cookie.read('screensaversettings');
			if(wpsTemp.split(cookieStrFnd)[0]!="hidden"){
				$('displaySSSOD').setProperty('checked', true);
			}
			if(wpsTemp.split(cookieStrFnd)[2]!="ssNone"){
				$('ssType').setProperty('value', wpsTemp.split(cookieStrFnd)[2]);
				$('ssOptions').setStyle('display', 'block');
				$('ssDelay').setProperty('value', wpsTemp.split(cookieStrFnd)[3]);
				$('ssOpacity').setProperty('value', wpsTemp.split(cookieStrFnd)[4]);
			}
			else{
				$('ssOptions').setStyle('display', 'none');
			}
			for(x=0;x<9999;x++){
				if(ssColor==$$('#ssColorPicker .cb div')[x].getProperty('title')){
					$$('#ssColorPicker .cb').removeClass('cbover');
					$$('#ssColorPicker .cb div')[x].getParent().addClass('cbover');
					$('colorwanted').setProperty('value', $$('#ssColorPicker .cb div')[x].getProperty('title'));
					x=9999;
				}
			}
		}
		else if(Cookie.read('screensaversettings')==null && setting!="all"){
			$('ssOptions').setStyle('display', 'none');
			$('displaySSSOD').setProperty('checked', false);
			$$('#ssColorPicker .cb div')[1].getParent().addClass('cbover');
			$('colorwanted').setProperty('value', $$('#ssColorPicker .cb div')[1].getProperty('title'));
		}
		if(setting=="all"){
			wpsTemp=Cookie.read('screensaversettings');
			if(wpsTemp!=null){
				if(wpsTemp.split(cookieStrFnd)[0]!="hidden"){
					screenSaverSettingsApp(2);
				}
				ssType=wpsTemp.split(cookieStrFnd)[2];
				ssDelay=wpsTemp.split(cookieStrFnd)[3];
				ssOpacity=wpsTemp.split(cookieStrFnd)[4];
				ssColor=wpsTemp.split(cookieStrFnd)[5];
				ssDelay=parseFloat(ssDelay); ssOpacity=parseFloat(ssOpacity);
				if(ssType!="ssNone"){
					screenSaverFunc(1);
				}
				else{
					
				}
			}
		}
	}
	//themes settings load
	if(setting=="themessettings" || setting=="all"){
		if(Cookie.read('themessettings')!=null && setting!="all"){
			wpsTemp=Cookie.read('themessettings');
			if(wpsTemp.split(cookieStrFnd)[0]!="hidden"){
				$('displayTSOD').setProperty('checked', true);
			}
			for(x=0;x<9999;x++){
				if(nowTheme==$$('#themeselectionbox .tsb img')[x].getProperty('alt')){
					$$('#themeselectionbox .tsb').removeClass('ppover');
					$$('#themeselectionbox .tsb img')[x].getParent().addClass('tsbover');
					$('selectedTheme').setProperty('value', $$('#themeselectionbox .tsb img')[x].getProperty('alt'));
					$('themeselectionpreview').set('html', '<img src="'+$$('#themeselectionbox .tsb img')[x].getProperty('src')+'" />');
					x=9999;
				}
			}
		}
		else if(Cookie.read('themessettings')==null && setting!="all"){
			$('displayTSOD').setProperty('checked', false);
			$$('#themeselectionbox .tsb img')[0].getParent().addClass('tsbover');
			$('selectedTheme').setProperty('value', $$('#themeselectionbox .tsb img')[0].getProperty('alt'));
			$('themeselectionpreview').set('html', '<img src="'+$$('#themeselectionbox .tsb img')[0].getProperty('src')+'" />');
		}
		if(setting=="all"){
			wpsTemp=Cookie.read('themessettings');
			if(wpsTemp!=null){
				if(wpsTemp.split(cookieStrFnd)[0]!="hidden"){
					themesSettingsApp(2);
				}
				nowTheme=wpsTemp.split(cookieStrFnd)[2];
			}
		}
	}
	//wallpaper settings load
	if(setting=="wallpapersettings" || setting=="all"){
		if(Cookie.read('wallpapersettings')!=null && setting!="all"){
			wpsTemp=Cookie.read('wallpapersettings');
			if(wpsTemp.split(cookieStrFnd)[0]!="hidden"){
				$('displayWSOD').setProperty('checked', true);
			}
			for(x=0;x<9999;x++){
				if(nowWallpaper==$$('#wallpaperselectionbox .wsb img')[x].getProperty('alt')){
					$$('#wallpaperselectionbox .wsb').removeClass('ppover');
					$$('#wallpaperselectionbox .wsb img')[x].getParent().addClass('wsbover');
					$('selectedWP').setProperty('value', $$('#wallpaperselectionbox .wsb img')[x].getProperty('alt'));
					x=9999;
				}
			}
		}
		else if(Cookie.read('wallpapersettings')==null && setting!="all"){
			$('displayWSOD').setProperty('checked', false);
			$$('#wallpaperselectionbox .wsb img')[0].getParent().addClass('wsbover');
			$('selectedWP').setProperty('value', $$('#wallpaperselectionbox .wsb img')[0].getProperty('alt'));
		}
		if(setting=="all"){
			wpsTemp=Cookie.read('wallpapersettings');
			if(wpsTemp!=null){
				if(wpsTemp.split(cookieStrFnd)[0]!="hidden"){
					wallpaperSettingsApp(2);
				}
				nowWallpaper=wpsTemp.split(cookieStrFnd)[2];
				applyWallpaper(0);
			}
		}
	}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------->
/*
	This function deletes all cookies
*/
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------->
function deleteSettings(setting){
	new PosAlerts({id: 'confirmDeleteSettings', width: 300, height: 110, type: 'confirm', title: 'Last Chance!', message: 'Are you sure you want delete all your settings? Pepi OS will reboot automatically.', 
		  onYes: function(){																															 
			//general settings save
			if(setting=="generalsettings" || setting=="all"){
				Cookie.dispose('generalsettings');
			}
			//accessibility settings save
			if(setting=="accessibilitysettings" || setting=="all"){
				Cookie.dispose('accessibilitysettings');
			}
			//security settings save
			if(setting=="securitysettings" || setting=="all"){
				Cookie.dispose('securitysettings');
			}
			//user settings save
			if(setting=="usernameandphoto" || setting=="all"){
				Cookie.dispose('usernameandphoto');
			}
			//gamma settings delete
			if(setting=="gammasettings" || setting=="all"){
				Cookie.dispose('gammasettings');
			}
			//screen saver settings delete
			if(setting=="screensaversettings" || setting=="all"){
				Cookie.dispose('screensaversettings');
			}
			//themes settings delete
			if(setting=="themessettings" || setting=="all"){
				Cookie.dispose('themessettings');
			}
			//wallpaper settings delete
			if(setting=="wallpapersettings" || setting=="all"){
				Cookie.dispose('wallpapersettings');
			}
			location.reload(true);
		}, 
		onNo: function(){
			return false
		}
	});
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------->
/*
	The following is the DomReady calls
*/
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------->
window.addEvent('domready', function(){
	loadAssets(0);
});
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------->
/*
	END PEPI OS CORE JS - COPYRIGHT 2009 PEZUS WEB DESIGN ALL RIGHTS RESERVED
*/
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------->