/* javascript */


function
show_info( show_info_id )
{
    var top  = get_absolute_top( g_show_area_id );
    var left = get_absolute_left( g_show_area_id );

    hide_all();
    show_it( left, top, show_info_id );

}

function
hide_info( hide_info_id )
{
    hide_it( hide_info_id );
}


// Image replacement
function
show_big_image( image_url, image_name, image_index )
{
    document.big_image.src = image_url;
    document.big_image.alt = image_name;
    document.image_name.image_name.value = image_name;
    g_current_image = image_index;
}

function
show_next_image()
{
    g_current_image++;
    if ( g_current_image >= g_n_images ) g_current_image = 0;
    show_big_image( g_images[g_current_image],  g_titles[g_current_image], g_current_image );
}

function
show_prev_image()
{
    g_current_image--;
    if ( g_current_image < 0 ) g_current_image = g_n_images-1;
    show_big_image( g_images[g_current_image],  g_titles[g_current_image], g_current_image );
}


// Image Slide show

var fade_out_seq = 0;

function
do_fade_out( top, left, width, height )
{
    if ( fade_out_seq == 0 ) {
        g_top = top; g_left = left; g_width = width; g_height = height;
    } else {
        top = g_top; left = g_left; width = g_width; height = g_height;
    }

    fade_out_seq++;
    if ( fade_out_seq > 20 ) {
        fade_out_seq = 0;
        fade_out_callback();
        delete_div( "fade_out" );
    } else {
        create_div( "fade_out", top, left, width, height * (fade_out_seq/20) ); // top -> bottom
        setTimeout( "do_fade_out()", 25 );
    }
}

function
fade_out( obj, callback )
{
    fade_out_callback = callback;
    var o = get_object( obj );

    var left    = get_absolute_left( o );
    var top     = get_absolute_top( o );
    var width   = o.width;
    var height  = o.height;

    // alert ( "left: " + left + " " + "top: " + top + " width: " + width + " height: " + height );
    do_fade_out( top, left, width, height );

}

var fade_in_seq = 0;

function
do_fade_in( top, left, width, height )
{

    if ( fade_in_seq == 0 ) {
        g_top = top; g_left = left; g_width = width; g_height = height;
    } else {
        top = g_top; left = g_left; width = g_width; height = g_height;
    }

    fade_in_seq++;
    if ( fade_in_seq > 20 ) {
        fade_in_seq = 0;
        delete_div( "fade_in" );
    } else {
        create_div( "fade_in", top, left, width, (height - (height * (fade_in_seq/20))) ); // bottom-> top
        if ( fade_in_seq == 1 ) {
                fade_in_callback();
        }
        setTimeout( "do_fade_in()", 25 );
    }
}

function
fade_in( obj, callback )
{
    fade_in_callback = callback;
    var o = get_object( obj );

    var left    = get_absolute_left( o );
    var top     = get_absolute_top( o );
    var width   = o.width;
    var height  = o.height;

    // alert ( "left: " + left + " " + "top: " + top + " width: " + width + " height: " + height );
    do_fade_in( top, left, width, height );

}

var g_slide_show            = false;
var g_button_position_id    = 'slide_show_button_position';
var g_play_id               = 'slide_show_button_play';
var g_stop_id               = 'slide_show_button_stop';

function
show_button( show_button_id )
{
    var top  = get_absolute_top( g_button_position_id );
    var left = get_absolute_left( g_button_position_id );

    show_it( left, top, show_button_id );

}

function
hide_button( hide_button_id )
{
    hide_it( hide_button_id );
}


function show_play() { show_button( g_play_id ); }
function hide_play() { hide_button( g_play_id ); }
function show_stop() { show_button( g_stop_id ); }
function hide_stop() { hide_button( g_stop_id ); }

function
slide_show_next()
{
    if ( g_slide_show ) {
        fade_in( document.big_image, show_next_image );
    }
}

var g_slide_show_timeout_id=0;

function
slide_show()
{
    if ( g_slide_show ) {
        fade_out( document.big_image, slide_show_next );
        g_slide_show_timeout_id = setTimeout( "slide_show()", 7*1000 );
    } else {
        g_slide_show_timeout_id = 0;
    }

    return;
}

function
slide_show_stop()
{
    g_slide_show = false;
    if ( g_slide_show_timeout_id ) clearTimeout( g_slide_show_timeout_id );
    hide_stop();
    show_play();
}

function
slide_show_play()
{
    g_slide_show = true;

    if ( g_n_images > 1 ) {
        hide_play();
        show_stop();
        slide_show();
    } else {
        show_play();
    }
}

// show / hide layered components
var g_show_area_id          = 'show_position';
var g_mortgage_calculator_id= 'mortgage_calculator';
var g_tell_your_friend_id   = 'tell_your_friend';
var g_ask_member_id         = 'ask_member';
var g_print_listing_id      = 'print_listing';


function
hide_all()
{
    hide_info( g_mortgage_calculator_id );
    hide_info( g_tell_your_friend_id );
    hide_info( g_ask_member_id );
    hide_info( g_print_listing_id );
}

function show_mortgage_calculator() { show_info( g_mortgage_calculator_id ); }
function hide_mortgage_calculator() { hide_info( g_mortgage_calculator_id ); }
function show_tell_your_friend() { tell_your_friend_reset(); show_info( g_tell_your_friend_id ); }
function hide_tell_your_friend() { hide_info( g_tell_your_friend_id ); }
function show_ask_member() { ask_member_reset(); show_info( g_ask_member_id ); }
function hide_ask_member() { hide_info( g_ask_member_id ); }
function show_print_listing() { show_info( g_print_listing_id ); }
function hide_print_listing() { hide_info( g_print_listing_id ); }


var g_map_config = new google_map_config_v2();

function
bl_map_start()
{
    if ( !GBrowserIsCompatible() ) {
        alert( "Sorry. Google map is not available. Because \n\nThe browser is not able to connect to Google map server at this moment.\n\nOr your browser is not compatible with Google map." );
        return;
    }

    var center = g_map_data_list.shift();
    google_map_v2( center, g_map_data_list, g_map_config );
}

function
bl_map_stop()
{
    GUnload();
}

function
bl_view_start()
{
    if ( typeof g_map_data_list != 'undefined' ) {
        bl_map_start();
    }
}

function
bl_view_stop()
{
    if ( typeof g_map_data_list != 'undefined' ) {
        bl_map_stop();
    }
}

/* vim: set expandtab sw=4 ts=4 sts=4: */

