/*TruGreen Site Scriptsmonthsandseason.js: month/season selector bar*/
// globals
month_names = new Array();
month_names[1] = 'march';
month_names[2] = 'april';
month_names[3] = 'may';
month_names[4] = 'june';
month_names[5] = 'july';
month_names[6] = 'august';
month_names[7] = 'september';
month_names[8] = 'october';
month_names[9] = 'november';
month_names[10] = 'december';
month_names[11] = 'january';
month_names[12] = 'february';
// status
var season_slider = 1; 	// spring
var month_slider = 1; 	// march
var month_slider_old = 1;
// geometry
var season_slider_left_stop = 34;
var month_slider_left_stop = 38;
var seasonFX;
var reveal_timer;
function seasons_ani_intro(s, m) {
    season_slider = s;
    month_slider = m;
    $('timelineback').setStyle('visibility', 'visible');
    $('timelineseason').setStyle('visibility', 'visible');
    $('timelineseasonname').setStyle('display', 'block');
    //$('timelinemonth').setStyle('visibility', 'visible');
    $('timelinebuttonback').setStyle('visibility', 'visible');
    $('timelinebutton1').setStyle('visibility', 'visible');
    $('timelinebutton2').setStyle('visibility', 'visible');
    $('timelinebutton3').setStyle('visibility', 'visible');
    $('timelinebutton4').setStyle('visibility', 'visible');
    $('timelinebutton5').setStyle('visibility', 'visible');
    $('timelinebutton6').setStyle('visibility', 'visible');
    $('timelinebutton7').setStyle('visibility', 'visible');
    $('timelinebutton8').setStyle('visibility', 'visible');
    $('timelinebutton9').setStyle('visibility', 'visible');
    $('timelinebutton10').setStyle('visibility', 'visible');
    $('timelinebutton11').setStyle('visibility', 'visible');
    $('timelinebutton12').setStyle('visibility', 'visible');
    $('mousecatcher').setStyle('display', 'block');
    if (m < 7) {
        flare_buttons(12, m);
        x_start = season_slider_left_stop + 70 * (3 * 3) + 'px';
        x_stop = season_slider_left_stop + 210 * (s - 1) + 'px';
    } else {
        flare_buttons(1, m);
        x_start = season_slider_left_stop + 'px';
        x_stop = season_slider_left_stop + 210 * (s - 1) + 'px';
    }
    seasonFX = new Fx.Tween('timelineseason', {
        property: 'left',
        duration: 1200,
        transition: Fx.Transitions.Cubic.easeOut,
        link: 'cancel'
    });
    seasonFX.start(x_start, x_stop);
    t = setTimeout('reveal_month(' + month_slider + ')', 1600);
    //t = setTimeout('reveal_season_name()', 1600);
    //if (homepage) {
        for (a = 12; a >= 1; a--) {
            fadetype = 1;
            fade_button(a, fadetype);
            //            t = setTimeout('fade_button(' + a + ',' + fadetype + ')', 80 * (13 - a));
        }
    //}
    change_month_action(m);
}
function flare_buttons(s, e) {			// start/end month
//    if (!homepage) {
//        if (s > e) {
//            s = (Math.ceil(s / 3)) * 3;
//            e = Math.ceil(e / 3) * 3 - 2;
//            for (a = s; a >= e; a--) {
//                fadetype = 0; 			// fade in and out
//                if (a < e + 3) {
//                    fadetype = 1; 		// just fade in
//                }
//                if (a > s - 3) {
//                    fadetype = 2;
//                }
//                t = setTimeout('fade_button(' + a + ',' + fadetype + ')', 80 * (13 - a));
//            }
//        } else {
//            s = Math.ceil(s / 3) * 3 - 2;
//            e = (Math.ceil(e / 3)) * 3;
//            for (a = s; a <= e; a++) {
//                fadetype = 0; 			// fade in and out
//                if (a > e - 3) {
//                    fadetype = 1; 		// just fade in
//                }
//                if (a < s + 3) {
//                    fadetype = 2;
//                }
//                t = setTimeout('fade_button(' + a + ',' + fadetype + ')', 80 * (a + 1));
//            }
//        }
//    }
}
function fade_button(b, t) {
    $('timelinebutton' + b).set('tween', {
        duration: 400,
        transition: Fx.Transitions.Cubic.easeOut,
        link: 'chain'
    });
    $('timelinebutton' + b).setStyle('visibility', 'visible');
    if (t == 0) {											// fade in...and out
        $('timelinebutton' + b).setStyle('opacity', '0');
        $('timelinebutton' + b).tween('opacity', 0.8).tween('opacity', 0);
    }
    if (t == 1) {											// fade in
        $('timelinebutton' + b).setStyle('opacity', '0');
        $('timelinebutton' + b).tween('opacity', 1);
    }
    if (t == 2) {											// turn transparent immediately
        $('timelinebutton' + b).tween('opacity', 0);
    }
}

function reveal_month(m) {
    $('timelinemonth').setStyle('opacity', '0');
    $('timelineseasonname').setStyle('opacity', '0');
    if (Math.ceil(m / 3) != season_slider) {													// new month is not in current season, move season slider
        clearTimeout(reveal_timer); 														// clear previous slider timer events (fix for fast-click-issue)
        x_start = season_slider_left_stop + 70 * ((season_slider - 1) * 3) + 'px';
        season_slider = Math.ceil(m / 3);
        x_stop = season_slider_left_stop + 70 * ((season_slider - 1) * 3) + 'px';
        seasonFX.start(x_start, x_stop);
        flare_buttons(month_slider_old, m);
        reveal_timer = setTimeout('reveal_month(' + m + ')', 800); 							// wait and try again
    } else {
        x_pos = month_slider_left_stop + 70 * (m - 1);
        $('timelinemonth').setStyle('left', x_pos + 'px');
        $('timelinemonth').set('tween', {
            duration: 800,
            transition: Fx.Transitions.Cubic.easeOut
        });
        $('timelinemonth').tween('opacity', 1);
        reveal_season_name();
    }
}
function reveal_season_name() {
    $('timelineseasonname').setStyle('opacity', '0');
    $('timelineseasonname').set('html', seasonsname[season_slider].toUpperCase());
    x_pos = season_slider_left_stop + 61 + 210 * (season_slider - 1);
    $('timelineseasonname').set('tween', {
        duration: 600,
        transition: Fx.Transitions.Cubic.easeOut
    });
    $('timelineseasonname').setStyle('left', x_pos + 'px');
    $('timelineseasonname').tween('opacity', 1);
}
function roll_month_on(m) {
    $('timelinerollover' + m).set('src', '/Content/images/nav/month_over_' + month_names[m] + '.gif')
}
function roll_month_off(m) {
    $('timelinerollover' + m).set('src', '/Content/images/spacer.gif')
}
function arrow_left() {
    var m = month_slider - 1;
    if (m == 0) {
        m = 12;
    }
    change_month_local(m);
}
function arrow_right() {
    var m = month_slider + 1;
    if (m == 13) {
        m = 1;
    }
    change_month_local(m);
}
function change_month(m) {														// called from month buttons
    month_slider_old = month_slider;
    month_slider = m;
    reveal_month(month_slider);
    change_month_action(m);
}