/** 
 * @fileoverview
 *
 * The main pageObject for this theme -- If you have any questions feel free to ask, 
 * I very much don't mind explaining things. All code for this theme was written by
 * me or given with permission of the original authors. Please leave these comments
 * in place so that users can better understand the code they see and make changes
 * if they need to.  Thanks.
 *
 <pre>
        Copyright (c) 2000-2008 Palaquest Internet Solutions and Design
        Written by Jason "Palamedes" Ellis (palamedes at rocketmail.com)
        URL:  http://www.randomstringofwords.com/
        Version: 08.07.06.001
        All rights reserved.

        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:

        - Redistributions of source code must retain the above copyright notice,
            this list of conditions and the following disclaimer.
        - Redistributions in binary form must reproduce the above copyright notice,
            this list of conditions and the following disclaimer in the
            documentation and/or other materials provided with the distribution.
        - Neither the name of Palaquest Internet Solutions & Design nor the names of its
            contributors may be used to endorse or promote products derived from
            this software without specific prior written permission.

        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
        LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        POSSIBILITY OF SUCH DAMAGE.
 </pre>
*/

	function pageObject() {
		this.editing = 'cc1c';
		this.requests = Array();
	}
	pageObject.prototype = {

		init : function () {
			// Create our colorChooser Object
			this.colorChooser = new rsow.colorChooser();

			// Attach Color Chooser to theme
			this.attachButton();
			// Get the users settings

			// Make sure our theme knows who it is
			if (window.currentTheme) {
				this.colorChooser.setPreset(window.currentTheme);
				this.colorChooser.updatePageColors();
			}

// setCookie('testCookie', 'testing'); 

		},

		// Attach the color Chooser to the color chooser tab.
		attachButton : function () {
			if ($('colorChooser')) {
				var dis = this;
				/** Define the ColorChooser
				 * I have created my colorchooser to be pretty mailleable, as such
				 * we have to define everything here. 
				 */
				this.colorChooser.setMainDiv('colorChooser');
				this.colorChooser.setOverlay('overlays');
				this.colorChooser.setExample('colorExample');
				this.colorChooser.setPickerDiv('picker');
				this.colorChooser.setPickerCursorImg('ccPickerCursor');
				this.colorChooser.setPickerOffset(249,42);
				this.colorChooser.setSliderDiv('slide');
				this.colorChooser.setSliderCursorImg('ccSliderCursor');
				this.colorChooser.setSliderOffset(414,42);
				this.colorChooser.setSize(144);

				// Set the 6 inputs that define primary, secondary and tertiary colors
				this.colorChooser.setInputs(['cc1c','cc1t','cc2c','cc2t','cc3c','cc3t']);

				// The ID of the select box that does overlay choosing
				this.colorChooser.setOverlayChooser('colorChooserOverlaySelector');
			
				// The ID of the select box that does preset choosing
				this.colorChooser.setPresetChooser('colorChooserPresetSelector');

				// Set css classes that are changed when that color type is edited [optional]
				this.colorChooser.setClassesPrimary(['cc1']);
				this.colorChooser.setClassesSecondary(['cc2']);
				this.colorChooser.setClassesTertiary(['cc3']);

				// Set element ID's that are changed when that color type is edited [optional]
				//this.colorChooser.setElementsPrimary(['bodyID','horizMenu']);
				//this.colorChooser.setElementsSecondary(['someID','someOtherID']);
				//this.colorChooser.setElementsTertiary(['foo','bar','sie']);

				// Set the editor to the current input as defined by the pObj
				this.colorChooser.setEditing(this.editing);
	
				// Attach the "click" event to the colorChooser Tab
				addListener($('colorChooserButton'), 'click', function() { dis.toggleColorChooser(this, arguments); } );

				// Attach the Presets event to the preset select box
				addListener($('colorChooserPresetSelector'), 'change', function() { dis.onChangePreset(this, arguments); } );

				// Attach the Overlay event to the overlays select box
				addListener($('colorChooserOverlaySelector'), 'change', function() { dis.setBackgroundOverlay(this, arguments); } );

				// Attach an onclick even to the input boxes so we know who to be "editing"
				addListener($('cc1c'), 'click', function() { dis.onClickInput(this, arguments); } );
				addListener($('cc1t'), 'click', function() { dis.onClickInput(this, arguments); } );
				addListener($('cc2c'), 'click', function() { dis.onClickInput(this, arguments); } );
				addListener($('cc2t'), 'click', function() { dis.onClickInput(this, arguments); } );
				addListener($('cc3c'), 'click', function() { dis.onClickInput(this, arguments); } );
				addListener($('cc3t'), 'click', function() { dis.onClickInput(this, arguments); } );
			}
		},
		// onClick event to slide open the colorchooser
		toggleColorChooser : function () {
			if (this.colorChooser.visible) {
				this.colorChooser.mover.verticalSlide([-210]);
				this.colorChooser.visible = false;

                // Assume a change has been made, and set that cookie!
                setCookie('theme', this.colorChooser.getTheme());
			} else {
				this.colorChooser.mover.verticalSlide([0]);
				this.colorChooser.visible = true;
			}
		},

		setBackgroundOverlay : function() {
			var a = arguments;
			this.colorChooser.setBodyOverlay(a[1][1].value);
		},

		onChangePreset : function() {
			var a = arguments;
			var obj = a[1][1];
			var preset = {};
			// Custom Preset = something they have created.
			switch (obj.value) {
				case 'standard': preset = {'preset':'standard','overlay':'overlaySpirals', 'colors':['#395891','#d1d4de','#95ad2a','#ffffff','#ccd4ed','#3c4373']}; break;
				case 'businesscasual': preset = {'preset':'businesscasual','overlay':'', 'colors':['#688ba0','#ffffff','#001d30','#d5e1ed','#ff672d','#ffebde']};	break;
                case 'borealis': preset = {'preset':'borealis','overlay':'overlaySpirals2', 'colors':['#657d2d','#e3e6cf','#acb588','#2f3d19','#305c6e','#d3dee6']}; break;
                case 'blueberrylime': preset = {'preset':'blueberrylime','overlay':'overlayStripesVert', 'colors':['#263248','#d1d4de','#95ad2a','#ffffff','#6e7791','#e1e3f0']}; break;
                case 'cherrycheesecake': preset = {'preset':'cherrycheesecake','overlay':'overlaySpirals', 'colors':['#4c1b1b','#ebdad8','#bf9971','#3d1814','#b9121b','#f0c9c9']}; break;
                case 'classicgreen': preset = {'preset':'classicgreen','overlay':'overlayBlocks', 'colors':['#2f5c24','#e1f2df','#333333','#dddddd','#8a882f','#ffffff']}; break;
                case 'classicred': preset = {'preset':'classicred','overlay':'overlayGatorskin', 'colors':['#821509','#e3d2cf','#333333','#dddddd','#c27306','#f7e8c8']}; break;
                case 'elegantportfolio': preset = {'preset':'elegantportfolio','overlay':'overlayAbstract', 'colors':['#41524d','#ced9d7','#b56d2e','#ede2d3','#783e1a','#edded1']}; break;
	            case 'monochrome': preset = {'preset':'monochrome','overlay':'overlayBark', 'colors':['#555555','#eeeeee','#aaaaaa','#222222','#000000','#cccccc']}; break;
                case 'midnightvisions': preset = {'preset':'midnightvisions','overlay':'overlayCarbon', 'colors':['#181818','#cccccc','#678f13','#dbedc0','#cc7700','#f2e5cb']}; break;
                case 'midnightvisions2': preset = {'preset':'midnightvisions2','overlay':'overlayBark', 'colors':['#181818','#cccccc','#2064a8','#cbddf5','#942994','#f7daf5']}; break;
                case 'sahara': preset = {'preset':'sahara','overlay':'overlayCracked', 'colors':['#574d2f','#e8deca','#b0a174','#2e2b18','#b0922e','#ffffff']}; break;
                case 'smoothsailing': preset = {'preset':'smoothsailing','overlay':'overlayCarbon', 'colors':['#587058','#d3e8d5','#587789','#c5d5e3','#e86850','#dec7bf']}; break;
                case 'softandsweet': preset = {'preset':'softandsweet','overlay':'overlayFoliage', 'colors':['#433c40','#ded3d8','#a18584','#f5eae9','#d11b5c','#ebd1d7']}; break;
                case 'spangled': preset = {'preset':'spangled','overlay':'overlayStripesVert', 'colors':['#001a2e','#d1ddeb','#8f0000','#f2dcda','#9c9457','#edecd5']}; break;
                case 'sunnysideup': preset = {'preset':'sunnysideup','overlay':'overlayHills', 'colors':['#2587c4','#ffffff','#222222','#dddddd','#f08c00','#ffffff']}; break;
                case 'thincandyshell': preset = {'preset':'thincandyshell','overlay':'overlayStripesVert', 'colors':['#cedaed','#152f59','#b4cf9b','#324222','#c783a8','#f7dfea']}; break;
                case 'torrino': preset = {'preset':'torrino','overlay':'overlayMosaic', 'colors':['#61282f','#dbd7d7','#72929e','#f5fafc','#232e3d','#c5c9d1']}; break;
                case 'warmvintage': preset = {'preset':'warmvintage','overlay':'overlayStripesVert', 'colors':['#342f29','#dbd6c5','#8f4721','#ebd8c7','#587265','#dff0e9']}; break;
			}

			// Now set the preset
			if (obj.value != 'custom') {
				this.colorChooser.setPreset(preset);
			}
		},

		// Input onClick -- Set the editor to edit this guy now
		onClickInput : function() {
			var a = arguments; var obj = a[1][1];
			// Set who are are editing in the colorChooser
            this.colorChooser.setEditing(obj.id);	
			// Change the 'selected' class of the DD's (Not the realm of the colorChooser)
			$(this.editing).parentNode.className = '';
			this.editing = obj.id;
			$(this.editing).parentNode.className = 'selected';
		}

	}

	// Create an instance of our page object
	var pObj = new pageObject();
	// Now init the page object and do so in such a way as it knows what "this" means.
	addListener(window, 'load', new Function("pageObject.prototype.init.apply(pObj);"));
