Ext.onReady(function() {

    new Ext.ux.Carousel('clients-controls', {
        itemSelector: 'div.slide',
        autoPlay: true,
        transitionEasing: 'easeIn',
        freezeOnHover: true,
        transitionDuration:1                 
    });

	Ext.select( 'div.client-slide a').on('click', function( e, t ){
		e.preventDefault( );
		var link = this.href;
		
		Ext.Ajax.request({
		   	url: link,
		   	success: function(response, opts) {
				Ext.fly( 'clients-target' ).update( response.responseText );
		   		Ext.select( 'div#client-info a' ).on( 'click', function( e, t ){
		   			e.preventDefault( );
		   			var link = this.href;
		   			Ext.fly( t ).parent( ).radioClass( 'active' );
		   			
		   			Ext.Ajax.request({
		   				url: link,
		   				success: function( response, opts ){
		   					Ext.fly( 'image-area' ).update( response.responseText );
		   				},
		   				failure: function( response, opts ){
		   				}
		   			});
		   		});
		   		Ext.ux.Lightbox.register('a[rel^=lightbox]');
		   	},
		   	failure: function(response, opts) {
			}
		});
	});

	Ext.select( 'div#client-info a' ).on( 'click', function( e, t ){
 		e.preventDefault( );
 		var link = this.href;
 		Ext.fly( t ).parent( ).radioClass( 'active' );
 			
 		Ext.Ajax.request({
 			url: link,
 			success: function( response, opts ){
 				Ext.fly( 'image-area' ).update( response.responseText );
 				Ext.ux.Lightbox.register('a[rel^=lightbox]');
 			},
 			failure: function( response, opts ){
 			}
 		});
 	});
 	Ext.ux.Lightbox.register('a[rel^=lightbox]');
});

