$(document).ready(function(){
    initMenu();
    $('.text-container').children().hover(function(){
        $(this).addClass('hover');
    }, function(){
        $(this).removeClass('hover');
    });

    /* ---- compare properties ajax ---- */
    
    $('#comparison-sidebar-container').show();
    $('.main .center .heading .red').show();
    
    $('.comparison-btn').click(function() {
        var url = $(this).attr('href');
        $('#ajax-container').load(url);
        return false;    
    });
    
    /*
    $('#property-compare .compare-remove').click(function() {
        var url = $(this).attr('href');
        $('#property-compare-grid').load(url);
        return false;    
    });
    */
       
    $('#comparison-list .lnk-remove').click(function() {
        var url = $(this).attr('href');
        $('#ajax-container').load(url);
        return false;    
    });
    
});


function initMenu(){
    var active = $('#nav li.active');
    var active_subdrop = $('#nav .subdrop li.active');
    active.addClass('hover');
    active_subdrop.removeClass('hover').parent().parent().addClass('hover');
    $('#nav .subdrop li.active').each(function () {
        $(this).removeClass('hover');
        $(this).parent().parent().addClass('hover');
    });
    $('#nav li').hover(function(){
        if (!$(this).parent().hasClass('drop') && !$(this).parent().hasClass('subdrop')) {
            active.removeClass('hover');
        }
        if ($(this) == active_subdrop) {
            active_subdrop.parent().parent().removeClass('hover');
        }
        $(this).addClass('hover');
    }, function(){
        $(this).removeClass('hover');
        if ($(this) == active_subdrop) {
            active_subdrop.parent().parent().addClass('hover');
        }
        if (!$(this).parent().hasClass('drop') && !$(this).parent().hasClass('subdrop')) {
            active.addClass('hover');
            active_subdrop.parent().parent().addClass('hover');
        }
    });
}

function initGall(){
    $('.gallery').each(function(){
        var img_h = $(this).find('div.photo');
        
        var _list = $(this).find('ul.thumbnails a');
        _list.each(function(){
            var _el = $(this);
            if(_el.parent().hasClass('active')){
                img_h.html('<img src="'+_el.attr("href")+'" alt="'+_el.attr("title")+'"/>')
            }
            _el.click(function(){
                if(!_el.parent().hasClass('active')){
                    img_h.html('<img src="'+_el.attr("href")+'" alt="'+_el.attr("title")+'"/>');
                    _list.parent().removeClass('active');
                    _el.parent().addClass('active');
                }                
                return false;
            });
        });
    });
}




/*   
    Cufon image replacment declarations
    
    *** important **********************************
    needs to follow jQuery call because this uses 
    jQuery for dom traversal methods below
    ************************************************
    
    Also note: Cufon.now(); called at the bottom of
    HTML page template for IE
    
*/

Cufon.replace('h1 span');
Cufon.replace('h2 span');
Cufon.replace('h3 span');
Cufon.replace('strong span');
Cufon.replace('#nav li span a');