$(document).ready(function(){ 
		$('#newsWidget_i').cycle({ 
			fx:     'fade', 
			speed:  'fast', 
			timeout: 0, 
			next:   '#nw_prev_i', 
			prev:   '#nw_next_i' 
		});
		$('#newsWidget_ii').cycle({ 
			fx:     'fade', 
			speed:  'fast', 
			timeout: 0, 
			next:   '#nw_prev_ii', 
			prev:   '#nw_next_ii' 
		});
		
		var showing_featured = false;
        var featured_property = 1;
        //how many other featured properties are there?
        var total_featured = 0
        $('.featured_property').each(
            function(){
                total_featured++;
            }
        );		
		
        //hide all featured properties...
        $().find('.featured_property').hide();

        //show the default featured property.
        $('#featured_property_'+featured_property).show();

        //show and hide the featured properties
        $('#fp_tab_i').click(
            function(){
                if(showing_featured == true){
                    showing_featured = close_featured_properties();
                }else{
                    showing_featured = open_featured_properties();
                }
                return false;
            }
        );
        $('#fp_tab_ii').click(
            function(){
                if(showing_featured == true){
                    showing_featured = close_featured_properties();
                }else{
                    showing_featured = open_featured_properties();
                }
                return false;
            }
        );
        $('#featured_properties_close').click(
            function(){
                if(showing_featured == true){
                    showing_featured = close_featured_properties();
                }else{
                    showing_featured = open_featured_properties();
                }
                return false;
            }
        );
        
        //capture clicks on prev and next elements for featured prop navigation
        $('#featured_properties_prev').click(
            function(){
                $('#featured_property_'+featured_property).slideUp(300);

                featured_property--;
                if(featured_property==0){
                    featured_property = total_featured;
                }
                $('#featured_property_'+featured_property).slideDown(300);
                return false;
            }
        );

        $('#featured_properties_next').click(
            function(){
                $('#featured_property_'+featured_property).slideUp(300);

                featured_property++;
                if(featured_property>total_featured){
                    featured_property = 1;
                }
                $('#featured_property_'+featured_property).slideDown(300);
                return false;
            }
        );		
});

function open_featured_properties(showing_featured){
    $('#featured_properties').animate({
        width: '665px',
        right: '0'
        }, 300 
    );
    $("#featureProperties").show();

    $('.featured_nav_tools').fadeIn();
    return true;
}

function close_featured_properties(showing_featured){
    $('#featured_properties').animate({
        width: '0',
        right: '-20px'
        }, 300
    );
    $("#featureProperties").hide();

    $('.featured_nav_tools').fadeOut();
    return false;
}


