

/************ START londonboroughs ********************/

var LondonBorough = function(){
    var baseUrl = '/';
    var isAnimating = false;
    
    function searchBorough(el){
        
        var intPropertyID = parseInt(el.id.replace('borough', ''));
        
        $('borough').set('html', el.alt);
        
        new Request.JSON({
            url: baseUrl + 'handlers/custom/townlist_byregion.ashx?bid=' + intPropertyID,
            onComplete: function(result) {
                var strTowns = '';
            
                if (result.count && parseInt(result.count) > 0){
                    
                    document.location.href = baseUrl + 'Findaproperty/Results.aspx?propsearch=true&resulttype=list&londontowns=' + intPropertyID;

                } else {
                
                    toggleView(true);
                
                }
                
            }
        }).send();
    }
    
    function toggleView(blnShow){
        var item = $('side-bar-content');

        if (!isAnimating){
        
            isAnimating = true;
        
            if (blnShow){
            
                item.setStyle('display', 'block');
                var objSlideFX = new Fx.Tween(item, {duration: 'long'});
                objSlideFX.start('opacity', 0, 1).chain(function(){ 
                    isAnimating = false;
                }); 
                    
            } else {
                
                var objSlideFX = new Fx.Tween(item, {duration: 'long'});
                objSlideFX.start('opacity', 1, 0).chain(function(){ 
                    item.setStyle('display', 'none');
                    isAnimating = false;
                }); 
                    
            }
        }
            
    };
    
    return {
        init: function(url){
            baseUrl = url;
            isAnimating = false;
        
            $('side-bar-content').setStyle('visibility', 'hidden');
            $('side-bar-content').setStyle('opacity', '0');
        
            $$('div#gmap-wrapper map area').each(function(el){
                el.addEvent('click', function(e) {
                    e.stop();
            
                    searchBorough(el);
                });
            });
            
            $('side-bar-close').addEvent('click', function(e) {
                e.stop();
                toggleView(false);
            });
            
            $('side-bar-close-link').addEvent('click', function(e) {
                e.stop();
                toggleView(false);
            });
        
        }
    }
}();