// non-gondola-specific js for the cummings site
$(function(){
    // home page featured properties
    var propertyWrapper = $('#property_wrapper');
    if(propertyWrapper.length > 0) {
    	propertyWrapper.cycle({ 
            prev:   '#btnPrev', 
            next:   '#btnNext', 
            timeout: 0,
            speed: 500
        });
    }
    
    // home page MLS search
    var mlsLink = $('#link-search-mls');
    var mlsForm = $('#frm-search-mls');
    var quickForm = $('#quick-form')
    if(mlsLink.length == 1 && mlsForm.length == 1) {
        mlsForm.hide();
        mlsLink.click(function(e){
            e.preventDefault();
            mlsForm.slidetoggle();
        });
    }
    
    $('.quick-search-toggle').toggle(function(){
  	  $(this).html('Return to Quick Search');
  	  $('#quick-form').hide();
  	  $('#quick-search-submit').hide();
  	  $('#search-mls-form').show();
    }, function() {
      $(this).html('Search by MLS Number');
      $('#search-mls-form').hide();
  	  $('#quick-form').show();
  	  $('#quick-search-submit').show();
  	});
    
    // accordion navigation
    var navItems = $('#head-nav>li:has(ul)');
    if(navItems.length > 0) {
        // determine which (if any) accordions should open by default
        var activeIndex = false;
        navItems.each(function(i){
            var subnavs = $(this).find('ul li a');
            subnavs.each(function(x){
                var subnav = $(this);
                if(location.href.indexOf(subnav.attr('href')) > -1) {
                    activeIndex = i;
                }
            });
        });
        // initialize the accordions
        navItems.accordion({
            collapsible: true,
            header: 'a.top',
            active: activeIndex
        });
    }
});
