
var ConnectorPhotos = new Class({

    ajaxLocationPicker:false,
    photoBox:false,
    sidebar:'f',
    whereami:'your area',

    initialize: function(  )
    {
        // <p>Finding Photos <img src="/images/ajax-loader.gif" alt="Loading" /></p>
        if( $( 'connectorPhotoBox' ) ){

            // ok we found the photo box lets store it for later
            this.photoBox = $( 'connectorPhotoBox' );
            
            if( this.photoBox.parentNode.className == 'local_photos widget' ){
                this.sidebar = 't';
            }

            if( $( 'whereami' ) ){
                this.whereami = $( 'whereami' ).getText();
            }

            this.showLoader();

            // ok lets look for the photos
            this.findPhotos();

        }
    },

    findPhotos:function()
    {

        new Ajax("/js/functions/getPhotos.php",{
            method:'post',
            data:'sidebar=' + this.sidebar ,
            onComplete:this.findPhotosResponse.bind(this),
            onFailure:function( response ){ this.hideLoader.bind(this); }
        }).request();

    },

    findPhotosResponse:function( response )
    {

        var results;
        eval( response );


        if( !results.error && results.html.length > 0 ){
            this.hideLoader();
            this.photoBox.setHTML( results.html );
        }

    },

    showLoader:function()
    {
        if( this.photoBox ){
            // setup image loader
            var ajaxProgressContainer = new Element('div',{'class':'ajaxProgressContainer'});
            new Element('h5').setText('Searching for Local photos in ' + this.whereami + '.').injectInside( ajaxProgressContainer );
            new Element('img',{'src':'/images/ajax-loader.gif'}).injectInside( ajaxProgressContainer );
            this.photoBox.empty();
            ajaxProgressContainer.injectInside( this.photoBox );
        }
    },

    hideLoader:function()
    {
        if( this.photoBox ){
            this.photoBox.empty();
        }
    }

});
window.addEvent( 'domready', function() {
    var clPhotos = new ConnectorPhotos();
});