// JavaScript Document
var pic_no = 0;
var total_pics = 0;
var title = "";
var pictures = new Array();
var loaded = false;

var molly = new Array("images/molly/molly-1.jpg",
				      "images/molly/molly-2.jpg",
				      "images/molly/molly-3.jpg",
				      "images/molly/molly-4.jpg",
				      "images/molly/molly-5.jpg",
				      "images/molly/molly-6.jpg",
				      "images/molly/molly-7.jpg",
				      "images/molly/molly-8.jpg",
				      "images/molly/molly-9.jpg",
				      "images/molly/molly-10.jpg");

var vegas = new Array("images/vegas/vegas-1.jpg",
					  "images/vegas/vegas-2.jpg",
					  "images/vegas/vegas-3.jpg",
					  "images/vegas/vegas-4.jpg",
					  "images/vegas/vegas-5.jpg",
					  "images/vegas/vegas-6.jpg",
					  "images/vegas/vegas-7.jpg",
					  "images/vegas/vegas-8.jpg",
					  "images/vegas/vegas-9.jpg");

var maggie = new Array("images/maggie/maggie-1.jpg",
					   "images/maggie/maggie-2.jpg",
					   "images/maggie/maggie-3.jpg",
					   "images/maggie/maggie-4.jpg",
					   "images/maggie/maggie-5.jpg",
					   "images/maggie/maggie-6.jpg",
					   "images/maggie/maggie-7.jpg",
					   "images/maggie/maggie-8.jpg",
					   "images/maggie/maggie-9.jpg",
					   "images/maggie/maggie-10.jpg",
					   "images/maggie/maggie-11.jpg");

var shilo = new Array("images/shilo/shilo-1.jpg",
					  "images/shilo/shilo-2.jpg",
					  "images/shilo/shilo-3.jpg",
					  "images/shilo/shilo-4.jpg",
					  "images/shilo/shilo-5.jpg",
					  "images/shilo/shilo-6.jpg",
					  "images/shilo/shilo-7.jpg",
					  "images/shilo/shilo-8.jpg",
					  "images/shilo/shilo-9.jpg",
					  "images/shilo/shilo-10.jpg");

										
var puppies = new Array("images/puppies/puppies-1.jpg",
					    "images/puppies/puppies-2.jpg",
					    "images/puppies/puppies-3.jpg",
					    "images/puppies/puppies-4.jpg",
					    "images/puppies/puppies-5.jpg",
					    "images/puppies/puppies-6.jpg",
					    "images/puppies/puppies-7.jpg",
					    "images/puppies/puppies-8.jpg",
					    "images/puppies/puppies-9.jpg",
					    "images/puppies/puppies-10.jpg",
					    "images/puppies/puppies-11.jpg");

var grown_up = new Array("images/grown_up/puppy-1.jpg",
						 "images/grown_up/puppy-2.jpg",
						 "images/grown_up/puppy-3.jpg",
						 "images/grown_up/puppy-4.jpg",
						 "images/grown_up/puppy-5.jpg",
						 "images/grown_up/puppy-6.jpg",
						 "images/grown_up/puppy-7.jpg",
						 "images/grown_up/puppy-8.jpg",
						 "images/grown_up/puppy-9.jpg",
						 "images/grown_up/puppy-10.jpg",
						 "images/grown_up/puppy-11.jpg",
						 "images/grown_up/puppy-12.jpg",
						 "images/grown_up/puppy-13.jpg",
						 "images/grown_up/puppy-14.jpg",
						 "images/grown_up/puppy-15.jpg",
						 "images/grown_up/puppy-16.jpg",
						 "images/grown_up/puppy-17.jpg",
						 "images/grown_up/puppy-18.jpg",
						 "images/grown_up/puppy-19.jpg",
						 "images/grown_up/puppy-20.jpg",
						 "images/grown_up/puppy-21.jpg",
						 "images/grown_up/puppy-22.jpg");

var retired = new Array("images/retired/retired_preamble-1.gif",
						"images/retired/bugs-1.jpg",
						"images/retired/bugs-2.jpg",
						"images/retired/bugs-3.jpg",
						"images/retired/cali-1.jpg",
						"images/retired/cali-2.jpg",
						"images/retired/cali-3.jpg");

// variables needed for the buttons
var loaded_images = new Array();
var clicked_image = "";

function preload_gallery_buttons()
{
	loaded_images["img_molly"] = new Image();
	loaded_images["img_molly"].src = "images/gallery/molly.gif";
	loaded_images["img_molly_o"] = new Image();
	loaded_images["img_molly_o"].src = "images/gallery/molly_o.gif";
	
	loaded_images["img_vegas"] = new Image();
	loaded_images["img_vegas"].src = "images/gallery/vegas.gif";
	loaded_images["img_vegas_o"] = new Image();
	loaded_images["img_vegas_o"].src = "images/gallery/vegas_o.gif";
	
	loaded_images["img_maggie"] = new Image();
	loaded_images["img_maggie"].src = "images/gallery/maggie.gif";
	loaded_images["img_maggie_o"] = new Image();
	loaded_images["img_maggie_o"].src = "images/gallery/maggie_o.gif";
	
	loaded_images["img_shilo"] = new Image();
	loaded_images["img_shilo"].src = "images/gallery/shilo.gif";
	loaded_images["img_shilo_o"] = new Image();
	loaded_images["img_shilo_o"].src = "images/gallery/shilo_o.gif";
	
	loaded_images["img_puppies"] = new Image();
	loaded_images["img_puppies"].src = "images/gallery/puppies.gif";
	loaded_images["img_puppies_o"] = new Image();
	loaded_images["img_puppies_o"].src = "images/gallery/puppies_o.gif";
	
	loaded_images["img_grown_up"] = new Image();
	loaded_images["img_grown_up"].src = "images/gallery/grown_up.gif";
	loaded_images["img_grown_up_o"] = new Image();
	loaded_images["img_grown_up_o"].src = "images/gallery/grown_up_o.gif";

	loaded_images["img_retired"] = new Image();
	loaded_images["img_retired"].src = "images/gallery/retired.gif";
	loaded_images["img_retired_o"] = new Image();
	loaded_images["img_retired_o"].src = "images/gallery/retired_o.gif";

	loaded_images["previous"] = new Image();
	loaded_images["previous"].src = "images/gallery/previous.gif";
	loaded_images["previous_o"] = new Image();
	loaded_images["previous_o"].src = "images/gallery/previous_o.gif";
	
	loaded_images["play"] = new Image();
	loaded_images["play"].src = "images/gallery/play.gif";
	loaded_images["play_o"] = new Image();
	loaded_images["play_o"].src = "images/gallery/play_o.gif";
	
	loaded_images["pause"] = new Image();
	loaded_images["pause"].src = "images/gallery/pause.gif";
	loaded_images["pause_o"] = new Image();
	loaded_images["pause_o"].src = "images/gallery/pause_o.gif";
	
	loaded_images["next"] = new Image();
	loaded_images["next"].src = "images/gallery/next.gif";
	loaded_images["next_o"] = new Image();
	loaded_images["next_o"].src = "images/gallery/next_o.gif";
}


function selection_clicked(src_image)
{
	
}

function load_pics(the_array)
{
	var i;
	pictures.length = 0;
	for (i = 0; i < the_array.length; i++)
	{
		pictures.push(new Image);
		pictures[i].src = the_array[i];
	}
}



function set_picture(direction)
{
	if(loaded)
	{
		switch(direction)
		{
			case "next":
				if (pic_no == total_pics)
				{
					pic_no = 1;
				}
				else
				{
					pic_no++;
				}
				break;
			case "previous":
				if (pic_no == 1)
				{
					pic_no = total_pics;
				}
				else
				{
					pic_no--;
				}
				break;
			default: break;
		}
		document.getElementById("pic_no").innerHTML = pic_no;
		document.getElementById("picture_frame_2").innerHTML = "<img src=\"" + pictures[(pic_no - 1)].src + "\" />";
		//document.getElementById("picture_frame_1").innerHTML = document.getElementById("picture_frame_2").innerHTML;
		//document.getElementById("picture_frame_2").style.opacity = ".5";
		//document.getElementById("picture_frame_1").style.opacity = "0";
		clearInterval(fade_interval);
		fade_picture("fade_out", "picture_frame_1");
	}
}

var fade_interval;
var g_fade_dir;
var g_img_id;
function fade_picture(fade_dir, img_id)
{
	g_fade_dir = fade_dir;
	g_img_id = img_id;
	//alert("Img ID: " + img_id + " fade_dir:" + fade_dir);
	fade_interval = setInterval(fade, 25);
}

function fade()
{
	var current_opacity = 0;
	if(navigator.userAgent.toLowerCase().indexOf("msie") >= 0)
	{
		current_opacity = document.getElementById(g_img_id).filters.alpha.opacity / 100;
	}
	else
	{
		current_opacity = parseFloat(document.getElementById(g_img_id).style.opacity);
	}
	switch(g_fade_dir)
	{
		case "fade_in":
			if(current_opacity >= 1)
			{
				current_opacity = 1;
				fade_interval = clearInterval(fade_interval);
			}
			else
			{
				current_opacity = current_opacity + .1;
			}
			break;
		case "fade_out":
			if(current_opacity <= 0)
			{
				current_opacity = 1;
				fade_interval = clearInterval(fade_interval);
				document.getElementById(g_img_id).innerHTML = document.getElementById("picture_frame_2").innerHTML;
				if(navigator.userAgent.toLowerCase().indexOf("msie") >= 0)
				{
					document.getElementById("picture_frame_2").filters.alpha.opacity = 100;
				}
				else
				{
					document.getElementById("picture_frame_2").style.opacity = 1;
				}
			}
			else
			{
				current_opacity = current_opacity - .1;
			}
			break;
	}
	if(navigator.userAgent.toLowerCase().indexOf("msie") >= 0)
	{
		document.getElementById(g_img_id).filters.alpha.opacity = current_opacity * 100;
	}
	else
	{
		document.getElementById(g_img_id).style.opacity = current_opacity;
	}
}
//pause and play functions
var play_pause = "pause";
var slide_counter = 0;
function play_click_handler(interval)
{
	if(slide_counter == 0)
	{
		//alert(slide_counter);
		slide_counter = setInterval("set_picture('next')", interval);
	}
	document.getElementById(play_pause).src = loaded_images[play_pause].src;
	play_pause = "play";
	document.getElementById(play_pause).src = loaded_images[play_pause + "_o"].src;
}

function pause_click_handler()
{
	clearInterval(slide_counter);
	slide_counter = 0;
	if(play_pause == "play")
	{
		document.getElementById(play_pause).src = loaded_images[play_pause].src;
	}
	document.getElementById("pause").src = loaded_images["pause_o"].src;
	play_pause = "pause";
}
function play_pause_mouseover_handler(src_img, swap_img)
{
	if(play_pause != src_img)
	{
		swap_image(src_img, swap_img);
	}
}
function play_pause_mouseout_handler(src_img)
{
	if(play_pause != src_img)
	{
		swap_image(src_img, src_img);
	}
}

//general button functions
function mouseover_handler(src_img, swap_img)
{
	if(clicked_image != src_img)
	{
		swap_image(src_img, swap_img);
	}
}

function mouseout_handler(src_img)
{
	if(clicked_image != src_img)
	{
		swap_image(src_img, src_img);
	}
}
function next_prev_click_handler(direction)
{
	pause_click_handler();
	set_picture(direction);
}

function swap_image(src_image, swap_image)
{
	document.getElementById(src_image).src = loaded_images[swap_image].src;
}

function click_handler(src_image, pics)
{
	pause_click_handler();
	display_pic(pics);
	if(clicked_image != "")
	{
		document.getElementById(clicked_image).src = loaded_images[clicked_image].src;
	}
	clicked_image = src_image;
	document.getElementById(clicked_image).src = loaded_images[clicked_image + "_o"].src;

}

//selection is the name of the array 
function display_pic(selection)
{
	//pause_click_handler(); //remove the interval for swapping pictures
	loaded = true;
	load_pics(eval(selection));
	document.getElementById("picture_frame_1").innerHTML = "<img src=\"" + pictures[0].src + "\" />";
	document.getElementById("picture_frame_2").innerHTML = "<img src=\"" + pictures[0].src + "\" />";
	total_pics = pictures.length;
	pic_no = 1;
	document.getElementById("pic_no").innerHTML = pic_no;
	document.getElementById("total_pics").innerHTML = total_pics;
	//document.getElementById("heading").innerHTML = selection;
}