
package com.extesla.book {

class BookSettings {

		private var songPath:String;
		public function setSongPath(songPath:String):void {
			this.songPath = songPath;
		}
		public function getSongPath():String {
			return this.songPath;
		}
		
		private var pdfUrl:String;
		public function setPdfUrl(pdfUrl:String):void {
			this.pdfUrl = pdfUrl;
		}

		public function getPdfUrl():String {
			return this.pdfUrl;
		}
		private var musicAutoplay:Boolean;
		public function setMusicAutoplay(musicAutoplay:Boolean):void {
			this.musicAutoplay = musicAutoplay;
		}
		
		public function isMusicAutoplay():Boolean {
			return this.musicAutoplay;
		}
		
		private var backgroundColor:Number;
		public function setBackgroundColor(backgroundColor:Number):void {
			this.backgroundColor = backgroundColor;
		}		
		public function getBackgroundColor():Number {
			return this.backgroundColor;
		}
		
		private var backgroundImage:String;
		public function setBackgroundImage(backgroundImage:Number):void {
			this.backgroundImage = backgroundImage;
		}		
		public function getBackgroundImage():Number {
			return this.backgroundImage;
		}
		private var backgroundImagePath:String;
		public function setBackgroundImagePath(backgroundImagePath:Number):void {
			this.backgroundImagePath = backgroundImagePath;
		}		
		public function getBackgroundImagePath():Number {
			return this.backgroundImagePath;
		}
		private var icon_color:Number;
		private var icon_bg_color:Number;
		private var aboutOn:String;
		private var contactOn:String;
		private var pdfOn:String;
		private var zoomOn:String;
		private var panOn:String;
		private var tiltOn:String;
		private var speedOn:String;
		private var thicknessOn:String;
		private var thumbOn:String;
		private var musicOn:String;
		private var settingsLoaded:Boolean = false;
		
		private var tooltips:Dictionary = new Dictionary();
		public function addTooltip(key:String, value:String):void {
			this.tooltips[key] = value;
		}
		
		public function getTooltip(key:String):String {
			if (this.tooltips[key] === null) {
				// throw error
			}
			return this.tooltips[key];
		}
		
		private var messages:Dictionary = new Dictionary();
		public function addMessage(key:String, value:String):void {
			this.messages[key] = value;
		}
		
		public function getMessages(key:String):String {
			if (this.messages[key] === null) {
				// throw error
			}
			return this.messages[key];
		}

		public function BookSettings():void {
			// Empty.
		}
		
		/**
		 * <p>
		 * Passing in the relative path to the <tt>settings.xml</tt> file will
		 * result in the XML file being loaded.
		 * </p>
		 * @param settingsXml the XML file for the settings.
		 */
		public function loadXml(settingsFile:String):void {
			var xmlLoader:URLLoader = new URLLoader();
			xmlLoader.load(new URLRequest(settingsFile));
			xmlLoader.addEventListener(Event.COMPLETE, this.finishLoad);
		}

		/**
		 *
		 */
		protected function finishLoad(e:Event):void
		{
			xml = new XML(e.target.data);
			
			freecam = xml.freecam;
			cam_tilt_angle = xml.cam_tilt_angle;
			cam_pan_angle = xml.cam_pan_angle;
			cam_zoom = xml.cam_zoom;
			cam_zoom *= zoomResizeFactor;
			cam_focus = xml.cam_focus;
			cam_distance = xml.cam_distance;
			page_width = xml.page_width;
			page_height = xml.page_height;
			thumb_width = xml.thumb_width;
			thumb_height = xml.thumb_height;
			thumb_spacing = xml.thumb_spacing;
			paper_thickness = xml.paper_thickness;
			free_cam = xml.free_cam;
			mousewheel_zoom_normal = xml.mousewheel_zoom_normal;
			mousewheel_zoom_fullscreen = xml.mousewheel_zoom_fullscreen;
			turning_speed = xml.turning_speed;
			page_flip_sound = xml.page_flip_sound.toString();
			page_flip_sound2 = xml.page_flip_sound2.toString();
			//autoflip = xml.autoflip;
			//autoflipTime = xml.autoflipTime;
			thumbOn = StringUtils.toBoolean("false"; //xml.thumbOn.toString();
			flip_sound_on = xml.flip_sound_on.toString();
			pdf_url =  xml.pdf_url.toString();
			
			song_path = xml.song_path.toString();
			music_autoplay = xml.music_autoplay.toString();
			bg_color = xml.bg_color;
			icon_color = xml.icon_color;
			icon_bg_color = xml.icon_bg_color;
			bg_image = xml.bg_image.toString();
			bg_image_path = xml.bg_image_path.toString();
			
			aboutOn = StringUtils.toBoolean(xml.about.toString());
			contactOn = StringUtils.toBoolean(xml.contact.toString();
			pdfOn = StringUtils.toBoolean(xml.pdf.toString();
			zoomOn = StringUtils.toBoolean(xml.zoom.toString();
			panOn = StringUtils.toBoolean(xml.pan.toString();
			tiltOn = StringUtils.toBoolean(xml.tilt.toString();
			speedOn = StringUtils.toBoolean(xml.speed.toString();
			thicknessOn = StringUtils.toBoolean(xml.thickness.toString();
			thumbOn = StringUtils.toBoolean("false"; //xml.thumbs.toString();
			//interactOn = StringUtils.toBoolean(xml.interact.toString();
			musicOn = StringUtils.toBoolean(xml.music.toString();
			sceneRotatiOn = StringUtils.toBoolean(xml.rotation;
			
			// **
			// Tooltips are expected to be generic, and supplied in the
			// following format:
			//	<tooltips>
			//		<tooltip id="myTooltup1" value="My Tooltip (1)" />
			//		<tooltip id="myTooltup2" value="My Tooltip (2)" />
			//	</tooltip>
			//
			// This allows for a completely independent and loosely coupled
			// implementation of the text for tooltips, and also allows the
			// skin to be extended.
			var tooltips:Array = xml.tooltips.tooltip;
			for (var tooltipIndex:int = 0; tooltipIndex < tooltips.length(); i++) {
				var tooltipId:String = tooltips[i].attribute("id");
				var tooltipValue:String = tooltips[i].attribute("value");
				this.tooltips[tooltipId] = tooltipValue;
			}
			
			// **
			// Messages, similarly to tooltips are supposed to be generic, and
			// and have no predetermined size (this becomes highly restrictive
			// the number of messages are too tightly restricted). Messages in
			// an XML file should be supplied in the following format:
			//	<messages>
			//		<message id="myMessage1" value="My Message (1)" />
			//		<message id="myMessage2" value="My Message (2)" />
			//	</messages>
			var messages:Array = xml.messages.tooltip;
			for (var messageIdx:int = 0; messageIdx < messages.length(); i++) {
				var messageId:String = messages[i].attribute("id");
				var messageValue:String = messages[i].attribute("value");
				this.messages[messageId] = messageValue;
			}
		}
}

}