/**
 * Class for managing appearance settings
 * @author Kamen Hursev
 */
function AppearanceSettings(defaultColor, defaultTitleFont, defaultBodyFont)
{
    this.defaultColor = defaultColor;
    this.defaultTitleFont = defaultTitleFont;
    this.defaultBodyFont = defaultBodyFont;
    
    this.selectedColor = defaultColor;
    this.selectedTitleFont = defaultTitleFont;
    this.selectedBodyFont = defaultBodyFont;
    
    this.customizableTicksSelectors = new Array('.customTick');
    this.customizableBackgroundSelectors = new Array('.customBackground');
    this.customizableBackgroundColorSelectors = new Array('.customBackgroundColor');
    this.customizableLogoSelectors = new Array('.customLogo');
    this.customizableColorSelectors = new Array('.customColor');
    
    this.customizableTitleFontSelectors = new Array('.customTitleFont');
    this.customizableBodyFontSelectors = new Array('.customBodyFont');
    
    //Sets style for the provaded selectors style = {styleName: value} the prototype way
    var _setPreview = function(selectors, style)
    {
        selectors.each(function(selector)
        {
            $$(selector).each(function(i)
            {
                i.setStyle(style);
            });
        });
    };
    
    /**
     * Preview for the color setting
     */
    this.previewColor = function(newColor)
    {
        if (newColor == '')
        {
            _setPreview(this.customizableBackgroundSelectors, {backgroundImage: ''});
            _setPreview(this.customizableLogoSelectors, {backgroundImage: ''});
            _setPreview(this.customizableTicksSelectors, {backgroundImage: ''});
        }
        else
        {
            var strNewColor = new String(newColor);
    
            _setPreview(this.customizableBackgroundSelectors,
                        {
                            backgroundImage: 'url("/style/images/bgr_headers/'
                                             + strNewColor.substring(1).toLowerCase()
                                             + '.gif")'
                        });
            _setPreview(this.customizableLogoSelectors,
                        {
                            backgroundImage: 'url("/style/images/bgr_logos/'
                                             + strNewColor.substring(1).toLowerCase()
                                             + '.png")'
                        });
             _setPreview(this.customizableTicksSelectors,
                        {
                            backgroundImage: 'url("/style/images/bgr_ticks/'
                                             + strNewColor.substring(1).toLowerCase()
                                             + '.gif")'
                        });
        }
        
        _setPreview(this.customizableColorSelectors, {color: newColor});
		
		if (newColor == '#000000')
		{
			$('profiletitle').setStyle({color: '#FE7706'});
		}
    };
    
    /**
     * Changes the selected color setting
     */
    this.selectColor = function(newColor)
    {
        this.previewColor(newColor);
        this.selectedColor = newColor;
    };
    
    /**
     * Resets the color setting back to the selected one.
     */
    this.resetColor = function()
    {
        this.previewColor(this.selectedColor);
    };
    
    this.previewTitleFont = function(font)
    {
        _setPreview(this.customizableTitleFontSelectors, {fontFamily: font});
    };
    
    this.selectTitleFont = function(font)
    {
        this.previewTitleFont(font);
        this.selectedTitleFont = font;
    };
    
    this.resetTitleFont = function()
    {
        this.previewTitleFont(this.selectedTitleFont);
    };
    
    this.previewBodyFont = function(font)
    {
        _setPreview(this.customizableBodyFontSelectors, {fontFamily: font});
    };
    
    this.selectBodyFont = function(font)
    {
        this.previewBodyFont(font);
        this.selectedBodyFont = font;
    };
    
    this.resetBodyFont = function()
    {
        this.previewBodyFont(this.selectedBodyFont);
    };
    
    /**
     * Resets all the settings
     */
    this.fullReset = function()
    {
        this.selectColor(this.defaultColor);
        this.selectTitleFont(this.defaultTitleFont);
        this.selectBodyFont(this.defaultBodyFont);
    };
}
