<?xml version="1.0" encoding="utf-8"?>

<!--

    ADOBE SYSTEMS INCORPORATED
    Copyright 2008 Adobe Systems Incorporated
    All Rights Reserved.

    NOTICE: Adobe permits you to use, modify, and distribute this file
    in accordance with the terms of the license agreement accompanying it.

-->

<!--- The default skin class for the mute button of a Spark VideoPlayer 
      component while in one of the <code>fullScreen</code> skin states.  

      @see spark.components.VideoPlayer
        
      @langversion 3.0
      @playerversion Flash 10
      @playerversion AIR 1.5
      @productversion Flex 4
-->
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" 
      creationComplete="init()"
      alpha.disabledStates="0.5">

    <!-- host component -->
    <fx:Metadata>
        /** 
         * @copy spark.skins.spark.ApplicationSkin#hostComponent
         */
        [HostComponent("spark.components.mediaClasses.MuteButton")]
    </fx:Metadata>
    
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
            import spark.components.mediaClasses.VolumeBar;
            
            private function init():void
            {
                // this is essentially just binding code.  Anytime the volume changes, 
                // let us know.
                volume = hostComponent.muted ? 0 : hostComponent.volume;
                hostComponent.addEventListener(FlexEvent.VALUE_COMMIT, valueCommitHandler);
                hostComponent.addEventListener(FlexEvent.MUTED_CHANGE, valueCommitHandler);
            }
            
            private function valueCommitHandler(event:Event):void
            {
                volume = hostComponent.muted ? 0 : hostComponent.volume;
            }
            
            private var _volume:Number = 1;
            
            /**
             *  The volume of the component to represent.
             */
            public function get volume():Number
            {
                return _volume;
            }
            
            /**
             *  @private
             */
            public function set volume(value:Number):void
            {
                if (value == _volume)
                    return;
                
                _volume = value;
                
                var bar1:Array = [bar1_1, bar1_2]; // 0-.25
                var bar2:Array = [bar2_1, bar2_2]; // .25-.5
                var bar3:Array = [bar3_1, bar3_2]; // .5-.75
                var bar4:Array = [bar4_1, bar4_2]; // .75-.1
                var bars:Array = [bar1, bar2, bar3, bar4];
                
                var curValue:Number = 0;
                for (var i:int = 0; i < bars.length; i++)
                {
                    if (value <= curValue)
                        setAlphaTo(bars[i], 0);
                    else if (value >= (curValue + 0.25))
                        setAlphaTo(bars[i], 1);
                    else
                        setAlphaTo(bars[i], (value-curValue)*4);
                    
                    curValue += 0.25;
                }
            }
            
            private function setAlphaTo(bar:Array, alpha:Number):void
            {
                for (var i:int = 0; i < bar.length; i++)
                {
                    // scale this by 0.75
                    bar[i].alpha = alpha * .75;
                }
            }
        ]]>
    </fx:Script>
    
    <!-- states -->
    <s:states>
        <s:State name="up" />
        <s:State name="over" stateGroups="overStates" />
        <s:State name="down" stateGroups="downStates" />
        <s:State name="disabled" stateGroups="disabledStates" />
        <s:State name="upAndSelected" stateGroups="selectedStates, selectedUpStates" />
        <s:State name="overAndSelected" stateGroups="overStates, selectedStates" />
        <s:State name="downAndSelected" stateGroups="downStates, selectedStates" />
        <s:State name="disabledAndSelected" stateGroups="selectedUpStates, disabledStates, selectedStates" />
    </s:states>
        
    <!-- layer 1: fill -->
    <s:Rect left="1" right="1" top="1" bottom="1">
        <s:fill>
            <s:LinearGradient rotation="90">
                <s:GradientEntry color="0x585858"
                                 color.overStates="0x676767"
                                 color.downStates="0x2C2C2C"
                                 alpha="0.55" />
                <s:GradientEntry color="0x1E1E1E"
                                 color.overStates="0x363636" 
                                 color.downStates="0x585858"
                                 alpha="0.55" />
            </s:LinearGradient>
        </s:fill>
    </s:Rect>
    
    <!-- layer 2: One pixel stroke inside border -->
    <s:Rect left="1" right="1" top="1" bottom="1">
        <s:stroke>
            <s:LinearGradientStroke weight="1" rotation="90">
                <s:GradientEntry color="0xFFFFFF" alpha="0.12" />
                <s:GradientEntry color="0xFFFFFF" alpha="0.09" />
            </s:LinearGradientStroke>
        </s:stroke>
    </s:Rect>
    
    <!-- layer 3: border - put on top of the fill so it doesn't disappear when scale is less than 1 -->
    <s:Rect left="0" right="0" top="0" bottom="0" width="38" height="24">
        <s:stroke>
            <s:SolidColorStroke color="0x222222" alpha="0.66" />
        </s:stroke>
    </s:Rect>
    
    <!--- Defines the volume symbol. -->
    <s:Group horizontalCenter="0" verticalCenter="0" id="volumeSymbol">
    
        <!-- big trapezoid in center -->
        <s:Path winding="evenOdd" data="M 9 13 L 9 0 L 4 4 L 4 9 L 9 13 Z">
            <s:fill>
                <s:SolidColor color="0xFFFFFF" alpha=".75"/>
            </s:fill>
        </s:Path>
        
        <!-- smaller trapezoid on left -->
        <s:Path winding="evenOdd" data="M 3 9 L 3 4 L 0 5 L 0 8 L 3 9 Z">
            <s:fill>
                <s:SolidColor color="0xFFFFFF" alpha=".75"/>
            </s:fill>
        </s:Path>
        
        <!-- volume bars -->
        
        <!-- big volume bar representing volume values [.75, 1] -->
        <s:Line yFrom="0" yTo="12" x="16">
            <s:stroke>
                <s:LinearGradientStroke rotation="90">
                    <!--- @private -->
                    <s:GradientEntry color="0xFFFFFF" ratio=".9" id="bar4_1" />
                    <!--- @private -->
                    <s:GradientEntry color="0x000000" id="bar4_2" />
                </s:LinearGradientStroke>
            </s:stroke>
        </s:Line>
        
        <!-- middle volume bar representing volume values [.5, .75] -->
        <!--- @private -->
        <s:Line yFrom="2" yTo="10" x="14">
            <s:stroke>
                <s:LinearGradientStroke rotation="90">
                    <!--- @private -->
                    <s:GradientEntry color="0xFFFFFF" ratio=".9" id="bar3_1" />
                    <!--- @private -->
                    <s:GradientEntry color="0x404040" id="bar3_2" />
                </s:LinearGradientStroke>
            </s:stroke>
        </s:Line>
        
        <!-- middle volume bar representing volume values [.25, .5] -->
        <!--- @private -->
        <s:Line yFrom="3" yTo="9" x="12">
            <s:stroke>
                <s:LinearGradientStroke rotation="90">
                    <!--- @private -->
                    <s:GradientEntry color="0xFFFFFF" ratio=".9" id="bar2_1" />
                    <!--- @private -->
                    <s:GradientEntry color="0x404040" id="bar2_2" />
                </s:LinearGradientStroke>
            </s:stroke>
        </s:Line>
        
        <!-- small volume bar representing volume values [0, .25] -->
        <s:Line yFrom="5" yTo="7" x="10">
            <s:stroke>
                <s:LinearGradientStroke rotation="90">
                    <!--- @private -->
                    <s:GradientEntry color="0xFFFFFF" ratio=".9" id="bar1_1" />
                    <!--- @private -->
                    <s:GradientEntry color="0x404040" id="bar1_2" />
                </s:LinearGradientStroke>
            </s:stroke>
        </s:Line>
    </s:Group>
    
</s:Skin>