/**************************************************************************************************/
/***
/***	DYNAMIC GALLERY JAVASCRIPT DOCUMENT
/***	-----------------------------------------------------------------------
/***	Written by Matthew Praetzel. Copyright (c) 2006-2008 Matthew Praetzel.
/***	-----------------------------------------------------------------------
/***	All Rights Reserved. Any use of these functions & scripts without written consent is prohibited.
/***
/**************************************************************************************************/

/*                                   **************************                                   */
/************************************   INITIALIZE VARIABLES   ************************************/
/*                                   **************************                                   */
var directory = "GALLERIES/gallery.php";
var title_timer,gallery_timer; var title_height = 30;
var current_width = 308; var current_height = 1; var max_width = 719; var max_height = 230;
var gallery_count = 4;
var background_opacity = 50;
for(var i=1;i<gallery_count+1;i++)
{
	eval("var gallery" + i + "=" + "false;");
}
/*                                   **************************                                   */
/************************************    DYNAMIC FUNCTIONS     ************************************/
/*                                   **************************                                   */
function loadGallery(which_gallery,gallery_index)
{
	var gallery_frame = document.getElementById("gallery"+gallery_index+"_frame");
	var gaallery_background = document.getElementById("gallery"+gallery_index+"_background");
	var gallery_image = document.getElementById("gallery"+gallery_index+"_image");
	var gallery_link = document.getElementById("gallery"+gallery_index+"_a");
	if(eval("gallery"+gallery_index+" == false"))
	{
		closeAllOtherGalleries(gallery_frame,gallery_image,gallery_link,gallery_index);
		setGallery(gallery_frame,gallery_image,which_gallery,gallery_index);
	}
	else
	{
		unsetGallery(gallery_frame,gallery_image,gallery_link,gallery_index);
	}
}
function setGallery(gallery_frame,gallery_image,which_gallery,gallery_index)
{
	var style_property = browser == "MSIE" ? "borderWidth" : "border-width";
	setStyle(gallery_frame,style_property,"1px");
	changeOpacity("gallery"+gallery_index+"_background",100);
	gallery_image.setAttribute("src",gallery_image.src.replace(".jpg","_over.jpg"));
	gallery_frame.setAttribute("src",directory+"?"+which_gallery);
	var style_property = browser == "MSIE" ? "zIndex" : "z-index";
	setStyle(gallery_frame,style_property,"5");
	resizeGallery(gallery_index);
	eval("gallery"+gallery_index+"= true");
}
function unsetGallery(gallery_frame,gallery_image,gallery_link,gallery_index)
{
	var style_property = browser == "MSIE" ? "borderWidth" : "border-width";
	setStyle(gallery_frame,style_property,"0px");
	changeOpacity("gallery"+gallery_index+"_background",background_opacity);
	gallery_image.setAttribute("src",gallery_image.src.replace("_over.jpg",".jpg"));
	gallery_frame.setAttribute("src","");
	gallery_link.blur();
	resizeGallery(gallery_index);
	var style_property = browser == "MSIE" ? "zIndex" : "z-index";
	setStyle(gallery_frame,style_property,"4");
	eval("gallery"+gallery_index+"= false");
}
function closeAllOtherGalleries()
{
	for(var i=1;i<gallery_count+1;i++)
	{
		if(eval("gallery" + i + "!=" + "false"))
		{
			var gallery_frame = document.getElementById("gallery"+i+"_frame");
			var gallery_image = document.getElementById("gallery"+i+"_image");
			var gallery_link = document.getElementById("gallery"+i+"_a");
			gallery_index = i;
			unsetGallery(gallery_frame,gallery_image,gallery_link,gallery_index);
		}
	}
}
function resizeGallery(gallery_index)
{
	var time_offset = 35;
	if(eval("gallery"+gallery_index+" == false"))
	{
		var width = current_width + (max_width-current_width)/10;
		var height = current_height + (max_height-current_height)/10;
		var frame_width = width - 2;
	}
	else
	{
		var width = max_width - (max_width-current_width)/10;
		var height = max_height - (max_height-current_height)/10;
		var frame_width = width;
	}
	for(var i=0;i<10;i++)
	{
		title_timer = setTimeout("resizeElement('gallery"+gallery_index+"',"+width+","+title_height+")",time_offset);
		gallery_timer = setTimeout("resizeElement('gallery"+gallery_index+"_frame',"+frame_width+","+height+")",time_offset);
		time_offset = time_offset + 35;
		width = eval("gallery"+gallery_index+" == false") ? width + (max_width-current_width)/10 : width - (max_width-current_width)/10;
		height = eval("gallery"+gallery_index+" == false") ? height + (max_height-current_height)/10 : height - (max_height-current_height)/10;
		height = parseInt(height) == 0 ? 1 : height;
		var frame_width = eval("gallery"+gallery_index+" == false") ? width - 2 : width;
	}
}

function resizeElement(which_element,width,height)
{
	var this_element = document.getElementById(which_element);
	this_element.style.width = width;
	this_element.style.height = height;
}