/*
/*	Dynamic design functions and onLoad events
/*	----------------------------------------------------------------------
/* 	Creates added dynamic functions and initializes loading.
*/


// ======================================================================
//
//	On document ready functions
//
// ======================================================================

$(document).ready(function() {


	
	
    // Slide down top content (topReveal)
    // -------------------------------------------------------------------
    $('.topReveal').click( function() {
        $('#ContentPanel').slideToggle(800);	// show/hide the content area
        $.scrollTo('#ContentPanel');
        return false;
    });





    // input lable replacement
    // -------------------------------------------------------------------
    $("label.overlabel").overlabel();

    // initialize anchor tag scrolling effect (scrollTo)
    // -------------------------------------------------------------------
    $.localScroll();

    // apply custom search input functions
    // -------------------------------------------------------------------
    searchInputEffect();

    // apply custom button styles
    // -------------------------------------------------------------------
    buttonStyles();

    // CSS Rounded Corners (not for IE)
    // -------------------------------------------------------------------
    if (!jQuery.browser.msie) {
        $("a.img, div.img, .textInput, input[type='text'], input[type='password'], textarea").addClass('rounded');	// items to add rounded class
        roundCorners(); // execute it!
    }

    $("#community_metro_area").change(function(){
        $("#community_state").val("");
        document.getElementById('selectcommunity_quick[state]').innerHTML = 'Any';
        
        $("#community_city").val("Any");
        document.getElementById('selectcommunity_quick[city]').innerHTML = 'Any';
        

    });
    
    
    $("#community_metro_area_adv").change(function(){
        $("#community_state_adv").val("");
        document.getElementById('selectcommunity[state]').innerHTML = 'Any';
        
        $("#community_city_adv").val("Any");
        document.getElementById('selectcommunity[city]').innerHTML = 'Any';
    });
    
    $('#community_state_adv').change(function(){
        var state = this.value;
        $('#community_city_adv').html('');
       
        
      
        
        if(document.getElementById('selectcommunity[city]')){
            document.getElementById('selectcommunity[city]').innerHTML = 'Any';
        }

       document.getElementById('selectcommunity[metro_area]').innerHTML = 'Any';
            $("#community_metro_area_adv").val("");
            
        $.get('/communities/getcities', {
            state: state
        }, function(data){
            for(var k in data)
            {
                $('#community_city_adv').append('<option value="' + data[k] + '">' + data[k] + '</option>');
            }
             $('#community_city_adv').val('Any');
        });      
    });

    $('#community_city_adv').change(function(){
        var city = this.value;

      if(document.getElementById('selectcommunity[metro_area]')){
               document.getElementById('selectcommunity[metro_area]').innerHTML = 'Any';
            $("#community_metro_area_adv").val("");
        }
     /*   $.get('/communities/getmareas', {
            city: city
        }, function(data){
            for(var k in data)
            {
                $('#community_metro_area_adv').append('<option value="' + data[k] + '">' + data[k] + '</option>');
            }
        });*/
    });

   
    $('#community_state').change(function(){
        var state = this.value;
        $('#community_city').html('');
        
  
        if(document.getElementById('selectcommunity_quick[city]'))
        {
            document.getElementById('selectcommunity_quick[city]').innerHTML = 'Any';
        }
        if(document.getElementById('selectcommunity_quick[metro_area]'))
        {
            document.getElementById('selectcommunity_quick[metro_area]').innerHTML = 'Any';
            $("#community_metro_area").val("");
        }
        $.get('/communities/getcities', {
            state: state
        }, function(data){
         
            for(var k in data)
            {
                $('#community_city').append('<option value="' + data[k] + '">' + data[k] + '</option>');
            }
            $('#community_city').val('Any');
        });
    });

    $('#community_city').change(function(){
        var city = this.value;
      if(document.getElementById('selectcommunity_quick[metro_area]'))
        {
            document.getElementById('selectcommunity_quick[metro_area]').innerHTML = 'Any';
            $("#community_metro_area").val("");
        }
    /*  if(document.getElementById('selectcommunity_quick[metro_area]'))
         {document.getElementById('selectcommunity_quick[metro_area]').innerHTML = 'Any';}
      $.get('/communities/getmareas', {city: city}, function(data){
         for(var k in data)
         {
            $('#community_metro_area').append('<option value="' + data[k] + '">' + data[k] + '</option>');
         }
      }); */
    });

});


// ======================================================================
//
//	Design functions
//
// ======================================================================



// Modal after load functions
// -------------------------------------------------------------------

function modalStart() {
    // updated styles
    $('#fancy_inner').addClass('rounded');
    roundCorners();
}





// Search input - custom effects for mouse over and focus.
// -------------------------------------------------------------------

function searchInputEffect() {

    var	searchFocus = false,
    searchHover = false,
    searchCtnr = $('#Search');
    searchInput = $('#SearchInput'),
    searchSubmit = $('#SearchSubmit');
    // Search input - mouse events
    searchCtnr.hover(
        function () {	// mouseover
            if (!searchFocus) $(this).addClass('searchHover');
            searchHover = true;
        },
        function () {	// mouseout
            if (!searchFocus) $(this).removeClass('searchHover');
            searchHover = false;
        }).mousedown( function() {
        if (!searchFocus) $(this).removeClass('searchHover').addClass('searchActive');
    }).mouseup( function() {
        searchInput.focus();
        searchSubmit.show();
        searchFocus = true;
    });
    // set focus/blur events
    searchInput.blur( function() {
        if (!searchHover) {
            searchCtnr.removeClass('searchActive');
            searchSubmit.hide();
            searchFocus = false;
        }
    });
}



// button styling function
// -------------------------------------------------------------------

function buttonStyles() {
    // Button styles

    // This will style buttons to match the theme. If you don't want a button
    // styled, give it the class "noStyle" and it will be skipped.
    //$("button:not(:has(span),.noStyle), input[type='submit']:not(.noStyle), input[type='button']:not(.noStyle)").each(function(){
    $("button .btn, input[type='submit'] .btn, input[type='button'] .btn").each(function(){
        var	b = $(this),
        tt = b.html() || b.val();

        // convert submit inputs into buttons
        if (!b.html()) {
            b = ($(this).attr('type') == 'submit') ? $('<button type="submit">') : $('<button>');
            b.insertAfter(this).addClass(this.className).attr('id',this.id);
            $(this).remove();	// remove input
        }
        b.text('').addClass('btn').append($('<span>').html(tt));	// rebuilds the button
    });

    // Get all styled buttons
    var styledButtons = $('.btn');

    // Fix minor problem with Mozilla and WebKit rendering (can also be done adding this to CSS,
    // button::-moz-focus-inner {border: none;}
    // @media screen and (-webkit-min-device-pixel-ratio:0) { button span {margin-top: -1px;} }
    if (jQuery.browser.mozilla || jQuery.browser.webkit) {
        styledButtons.children("span").css("margin-top", "-1px");
    }

    // Button hover class (IE 6 needs this)
    styledButtons.hover(
        function(){
            $(this).addClass('submitBtnHover');
        },		// mouseover
        function(){
            $(this).removeClass('submitBtnHover');
        }	// mouseout
        );
}

// Rounded corner styles
// -------------------------------------------------------------------

function roundCorners() {
    $('.rounded, .ui-corner-all').css({
        '-moz-border-radius': '4px',
        '-webkit-border-radius': '4px',
        'border-radius': '4px'
    });
}

// Font replacement
// -------------------------------------------------------------------





