
var is_footer_visible = false;
var footer_name = "";

// GREEN BOOK SNEAK PEEK ONLY

function screenshot1()
{
	$('gb_sneakpeek_screenshot').className = "gb_sneakpeek_1 gb_sneakpeek_size"
}

function screenshot2()
{
	$('gb_sneakpeek_screenshot').className = "gb_sneakpeek_2 gb_sneakpeek_size"
}

function screenshot3()
{
	$('gb_sneakpeek_screenshot').className = "gb_sneakpeek_3 gb_sneakpeek_size"
}

function screenshot4()
{
	$('gb_sneakpeek_screenshot').className = "gb_sneakpeek_4 gb_sneakpeek_size"
}

function hide_footer_bubble(d)
{
	if (is_footer_visible)
	{
		grass_block = $('grass_block')

		if (grass_block)
		{
			$('grass_block').appear({duration: d});
		}

		$('footer_bubble_block').fade({duration: d});
		is_footer_visible = false;
	}
}

function show_footer_bubble(d)
{
	if (!is_footer_visible)
	{
		grass_block = $('grass_block')

		if (grass_block)
		{
			$('grass_block').fade({duration: d});
		}

		$('footer_bubble_block').appear({duration: d});
		is_footer_visible = true;
	}
}

function toggle_footer_bubble(name, x_pos)
{                    
	$('footer_down_arrow').setStyle({left: x_pos + 'px'})   

	if (is_footer_visible)
	{
		if (footer_name != name && footer_name != "")
		{
			footer_name = name;
		}

		else
		{
			hide_footer_bubble(0.25);
		}
	}

	else
	{
		show_footer_bubble(0.25);
		footer_name = name;
	}
}
			
function drape_show()
{
	$('drape_block').appear();
}

function drape_hide()
{
	$('drape_block').fade();
}

function random_range(start, end)
{
	return Math.floor((end-(start-1))*Math.random()) + start;
}                                                        

function bubblize(e, scope)
{
	e.appear({duration: 0.25, queue: {position: 'end', scope: scope}});    
	e.fade({duration: 0.25, delay: 1.5, queue: {position: 'end', scope: scope}});    
}

function tree() 
{
	$('tree').shake({distance: 2, duration: 0.5, mode: 'absolute', queue: {position: 'end', scope: 'qtree', limit: 1}});
	//setTimeout("leaf()", 500);
}

function leaf()
{
	// alert("shake leaf");
	// $('leaf').shake({distance: 2, duration: 0.5, mode: 'absolute', queue: {position: 'end', scope: 'qtree', limit: 1}});
}

var is_bird_visible = false;

function birdnest()
{
	if (!is_bird_visible)
	{
		is_bird_visible = true;
		$('bird_block').blindDown({duration: 0.5, afterFinish: birdnest_sayit});
	}
}

function birdnest_sayit()
{
	bubblize($('bird_bubble'), 'bird');
	setTimeout("birdnest_hide()", 3000);
}

function birdnest_hide()
{
	$('bird_block').blindUp({afterFinish: birdnest_done});
}

function birdnest_done()
{
	is_bird_visible = false;
}
       
function load_fireflies()
{            
    if (!sun_type == N)
	     return;

	for (var i = 0; i < 20; i++)
	{
		var style = '';
		style += 'left:' + random_range(0, 986) + "px;";
		style += 'top:' + random_range(0, 64) + "px;"; 
		style += 'display: none;';

		var div_id = 'firefly_' + i;

		var firefly = new Element('div', {id: div_id, className: 'firefly', style: style});
		$('fireflies').appendChild(firefly);		  

		setTimeout("firefly_start(" + div_id + ")", random_range(1000, 50000));   
	}                                    
}                                                         

function firefly_start(x)
{   
	// alert("id: " + typeof x + ": " + x.id);        

	if (typeof x != "string")
		x = x.id;      
                                            
	$(x).appear({duration: 0.2, queue: {position: 'end', scope: x.toString()}});
	$(x).fade({duration: 0.2, queue: {position: 'end', scope: x.toString()}});   

	setTimeout("firefly_start(" + x + ")", random_range(5000, 50000));

	var xx = random_range(0, 986);
	var yy = random_range(0, 44);
	$(x).setStyle({top: yy + 'px', left: xx + 'px'});
} 

function ladybug()
{   
	bubblize($('ladybug_bubble'), 'qladybug');
}   
                       
var clicks = 0;              
var last_x = 0;

function grasshopper()
{              
	clicks++;
	      
	if (clicks >= 15)
		clicks = 1;
		 
	var x = 0;
	var limit_range = 100;                 
	var diff = limit_range - 1;
	
	while (diff < limit_range)
	{          
		x = random_range(100, 800);
		
		diff = last_x - x;

		if (diff < 0)
			diff = -diff;
	}          
	
	last_x = x;               
	
	var y = random_range(300, 340);
	$('grasshopper').setStyle({top: y + 'px', left: x + 'px'})   
                   
	if (clicks == 1)
		bubblize($('grasshopper_bubble'), 'qgrasshopper');
}                
       
var dandelion_click = 0;

function dandelion()
{      
	dandelion_click++;
	
	if (dandelion_click >= 15)
		dandelion_click = 1;
		
	if (dandelion_click == 1)
		bubblize($('dandelion_bubble'), 'qdandelion');
}         
    
function go_to_pollen()
{
	d = $('dandelion');
	x = d.offsetLeft + 8;
	y = d.offsetTop;

	new Effect.Move($('bee'), {x: x, y: y, mode: 'absolute', duration: 1.5});
	// setTimeout("bubblize(" + $('bee_bubble') + ", 'bee')", 500);
	setTimeout("bubblize($('bee_bubble'), 'bee')", 1600);
	//setTimeout("firefly_start(" + div_id + ")", random_range(1000, 50000));   
	//bubblize($('bird_bubble'), 'bird');
}

function point(element)
{
	
}

// ======================================================================================
// = DROP DOWN MENU (CONVO LOGO)                                                        =
// ======================================================================================
var is_menu_visible = false;
var is_mouse_over = false;
var is_menu_ready_for_action = true;

function set_menu_ready_for_action()
{
	is_menu_ready_for_action = true;
}

function menu_over()
{              
	if (is_menu_ready_for_action)
	{
		is_menu_ready_for_action = false;
		setTimeout("set_menu_ready_for_action()", 500);

		if (!is_menu_visible && is_mouse_over)
		{
			is_menu_visible = true;
			new Effect.SlideDown($('convo_menu_block'), {duration: 0.25, queue: {position: 'parallel', scope: 'menu', limit: 2}});
			new Effect.SlideDown($('convo_menu_background'), {duration: 0.25, queue: {position: 'parallel', scope: 'menu', limit: 2}});
		}
	}
}                        

function menu_out()
{                
	if (is_menu_ready_for_action)
	{
		if (is_menu_visible && !is_mouse_over)
		{
			is_menu_ready_for_action = false;
			setTimeout("set_menu_ready_for_action()", 500);

			new Effect.SlideUp($('convo_menu_block'), {duration: 0.25, queue: {position: 'parallel', scope: 'menuout', limit: 2}});
			new Effect.SlideUp($('convo_menu_background'), {duration: 0.25, queue: {position: 'parallel', scope: 'menuout', limit: 2}});
			is_menu_visible = false;
		}
	}

	else if (!is_mouse_over)
	{
		timed_menu_out(100);
	}
}          

function timed_menu_out(i)
{
	setTimeout("menu_out()", i);
}            

function mouse_over_menu()
{
	is_mouse_over = true;
	menu_over();
}   

function mouse_out_menu()
{
	is_mouse_over = false;
	timed_menu_out(500);
}

function mouse_over_logo()
{
	is_mouse_over = true;
	menu_over();
}

function mouse_out_logo()
{
	is_mouse_over = false;
	timed_menu_out(500);
}

// ======================================================================================
// = DROP DOWN MENU (SUBSCRIBE)
// ======================================================================================
var is_join_visible = false;

function join_toggle()
{
	if (is_feedback_visible)
	{
		feedback_hide();
		setTimeout("toggle_slide(['join_block', 'join_background'])", 600);
	}

	else
	{
		toggle_slide(['join_block', 'join_background']);
	}

	is_join_visible = !is_join_visible;
}

function join_hide()
{
	if (is_join_visible)
		join_toggle();
}

// ======================================================================================
// = DROP DOWN MENU (FEEDBACK)
// ======================================================================================
var is_feedback_visible = false;

function feedback_toggle()
{
	if (is_join_visible)
	{
		join_hide();
		setTimeout("toggle_slide(['feedback_block', 'feedback_background'])", 600);
	}

	else
	{
		toggle_slide(['feedback_block', 'feedback_background']);
	}

	is_feedback_visible = !is_feedback_visible;
}

function feedback_hide()
{
	if (is_feedback_visible)
		feedback_toggle();
}

// var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
// 
// function countdown(y, m, d)
// {
// 	var now = new Date();
// 	var year = now.getYear();
// 
// 	if (year < 1000)
// 		year+=1900
// 
// 	var mon = now.getMonth();
// 	var date = now.getDate();
// 	var hour = now.getHours();
// 	var min = now.getMinutes();
// 	var sec = now.getSeconds();
// 	var todaystring = montharray[mon] + " " + date + ", " + year + " " + hour + ":" + min + ":" + sec;
// 
// 	futurestring = montharray[m-1] + " " + d + ", " + y;
// 	ddate = Date.parse(futurestring) - Date.parse(todaystring);
// 	dday = Math.floor(ddate / (60*60*1000*24) *2);
// 	dhour = Math.floor((ddate % (60*60*1000*24)) / (60*60*1000) *1);
// 	dmin = Math.floor(((ddate % (60*60*1000*24)) % (60*60*1000)) / (60*1000)*1);
// 	dsec = Math.floor((((ddate % (60*60*1000*24)) % (60*60*1000)) % (60*1000)) / 1000 * 1);
// 
// 	if(dday == 0 && dhour == 0 && dmin == 0 && dsec == 1)
// 	{
// 		$('days').innerHTML = 0;
// 		$('hours').innerHTML = "00";
// 		$('minutes').innerHTML = "00";
// 		$('seconds').innerHTML = "00";
// 		return;
// 	}
// 
// 	else
// 	{
// 		$('days').innerHTML = dday;
// 		$('hours').innerHTML = (dhour > 9) ? dhour : "0" + dhour;
// 		$('minutes').innerHTML = (dmin > 9) ? dmin : "0" + dmin;
// 		$('seconds').innerHTML = (dsec > 9) ? dsec : "0" + dsec;
// 	}
// 
// 	setTimeout("countdown(" + y + "," + m + "," + d + ")",1000);
// }                                                           
//        
