// <![CDATA[

( function( $ )
{
    
    window.SelectSkin = {};
    window.SelectSkin.setText = function( a, b )
    {
        x = document.getElementById( a );
        
        if( x )
        {
            x.innerHTML = b.options[ b.selectedIndex ].innerHTML;
        }
    };
    
    function skin( i )
    {
        $selectContainer = $( this );
        
        // Remove the class for non JS browsers
        $selectContainer.removeClass( 'my-skinnable-select' );
        
        // Add the class for JS Browers
        selectContainer.addClass( 'skinned-select' );
  
        // Find the select box
        selectContainer.children().before( '<div class="select-text">a</div>' ).each(
            function()
            {
                $( this ).prev().text( this.options[ 0 ].innerHTML );
            }
        );
        
        // Store the parent object
        var parentTextObj = selectContainer.children().prev();
       
        // As we click on the options
        selectContainer.children().click(
            function()
            {
                // Set the value of the html
                parentTextObj.text( this.options[ this.selectedIndex ].innerHTML );
            }
        );
    }
    
    function init()
    {
        $( '.my-skinnable-select' ).each( skin );
    	
        var $css = $( '<link />' ).attr(
            {
                rel  : 'stylesheet',
                type : 'text/css',
                href : 'fileadmin/css/skinned-select.css'
                
            }
        );
        
        $( 'head' ).append( $css );
    }
    
    function fixIE()
    {
        $( 'DIV.skinnedSelect DIV.text' ).hide().remove();
        $( 'DIV.skinnedSelectLittle DIV.text' ).hide().remove();
    }
    
    if( !$.browser.msie )
    {
        $( init );
    }
    else
    {
        $( fixIE );
    }
    
} )( jQuery );

// ]]>
