$( '.ds-deal-media a img, .rfloat img' ).click( function(){
    if( $( this ).closest( '.rfloat' ).length ){
        var image = $( this ).attr( 'src' ).split( '/' );
        image[ image.length - 2 ] = "large";
        image = image.join( '/' );
        for( var i = 0; i < window.images.length; ++i ){
            if( image == window.images[ i ] ){
                window.step = i;
            }
        }
    }
    else{
        var image = window.images[ 0 ];
        window.step = 0;
    }
    TINY.box.show( {
        image: image,
        boxid: 'tinypanel',
        animate: 'true'
    } );
    $( '.tbox .tcontent' )
        .prepend( '<a href="" class="left"><span></span></a>' )
        .children( 'a.left' ).hide().click( function(){
            --window.step;
            $( '.tbox a.right, .tbox a.left' ).hide();
            $( '.tbox .tcontent' ).fadeOut( function(){
                $( '.tbox a.right' ).show();
                window.step != 0 && $( '.tbox a.left' ).show();

                $( this ).children( 'img' ).attr( 'src', window.images[ window.step ] ).attr('width',700)
                .load( function(){
                    $( this ).parent().fadeIn();
                } );
            } );
            return false;
        } ).end()
        .append( '<a href="" class="right"><span></span></a>' )
        .children( 'a.right' ).hide().click( function(){
            ++window.step;
            $( '.tbox a.right, .tbox a.left' ).hide();
            $( '.tbox .tcontent' ).fadeOut( function(){
                $( '.tbox a.left' ).show();
                window.step != window.images.length - 1 && $( '.tbox .right' ).show();
                $( '.tinner' ).css( 'backgroundImage', '' );
                $( this ).children( 'img' ).attr( 'src', window.images[ window.step ] ).attr('width',700)
                .load( function(){
                    $( this ).parent().fadeIn();
                    TINY.box.size( $( '.tbox img' ).width(), $( '.tbox img' ).height(), 1 );
                } );
            } );
            return false;
        } );
    if( window.step != 0 ){
        $( '.tbox .tcontent .left' ).show();
    }
    if( window.step + 1 !== window.images.length ){
        $( '.tbox .tcontent .right' ).show();
    }
    return false;
} );

