// parse URL for _GET values
var iPage = 100;
var iSet = 0;

var aTmpValues = self.location.href.split('?');
if (aTmpValues.length > 1)
{
    var strGetValues = aTmpValues[1];
    var aGetValues = strGetValues.split('&');
    for (i=0; i < aGetValues.length; ++i)
    {
    	var aGet = aGetValues[i].split('=');    	
    	if (aGet[0] == 'case') iPage = aGet[1];		
    	if (aGet[0] == 'set') iSet = aGet[1];   	
    }
}


function SizeChange(thisid)
{
	var thiselem;
	if (document.getElementById(thisid))
		thiselem = document.getElementById(thisid);
	else thiselem = this;
	
	if (!thiselem.currentWidth) thiselem.currentWidth = RestoreWidth;
		DoSizeChangeMem(thisid,thiselem.currentWidth,SelectedWidth,10,10,1,1); 
	
	DoSizeChangeMem(iPage+'thumb',SelectedWidth,RestoreWidth,10,10,1,1);

	setTimeout("FadeAttributeCol('big_title','color',50,80,105,30,47,62)",200);
}


// Events for AJAX loaded index list
var indexLinks,getIndex;
var SelectedHeight,SelectedWidth;
var RestoreWidth,RestoreHeight;

function IndexEvents()
{
	indexLinks = document.getElementById('case_index').getElementsByTagName('A');

	var divWidth = 769;
	var numCases = indexLinks.length;
	if (ie6) divWidth = (divWidth - 2); 
	SelectedWidth = 125;
	SelectedHeight = 80;
	RestoreWidth = Math.ceil((divWidth - SelectedWidth) / (numCases - 1));
	RestoreHeight = Math.ceil(SelectedHeight * (RestoreWidth / SelectedWidth));

	for (i = 0; i < indexLinks.length; ++i)
	{
		if (indexLinks[i].id != iPage)
		{
			indexLinks[i].firstChild.style.height = RestoreHeight + 'px';
			indexLinks[i].firstChild.style.width = RestoreWidth + 'px';
		} else {
			indexLinks[i].firstChild.style.height = SelectedHeight + 'px';
			indexLinks[i].firstChild.style.width = SelectedWidth + 'px';			
		}
		
		indexLinks[i].onmouseover = function() { this.firstChild.style.borderBottom = '3px double #A2D4FF' };
		indexLinks[i].onmouseout = function() { this.firstChild.style.borderBottom = 'none' };		
		indexLinks[i].onclick = function()
		{
			if (parseInt(this.id) != iPage)
			{
				SizeChange(this.id+'thumb');
				iPage = this.id;
				iSet = 0;
				getGallery = new ajaxObject('get_gallery.php', processGallery);
				getGallery.update('case='+iPage+'&set='+iSet+'&js=1');
				
			} else {
				window.location = 'index.php?case='+iPage+'&set='+iSet+'&js=1';
			}
			
			return false;
		};
	}
}


// AJAX process functions
function processIndex(responseText, responseStatus)
{
	if (responseStatus==200)
	{
		if (document.getElementById('index_container'))
		{
			document.getElementById('index_container').innerHTML=responseText ;
			IndexEvents();	
		}
	} else {
	alert(responseStatus + ' -- Error Processing Request');
	}
}


function processGallery(responseText, responseStatus)
{
	if (responseStatus==200)
	{
		if (document.getElementById('get_gallery'))
		{
			document.getElementById('get_gallery').innerHTML=responseText;
			LoadedGalleryEvents();
		}
	} else {
		alert(responseStatus + ' -- Error Processing Request');
	}
}


// Event Handlers
function GalleryEvents()
{
	PreloadImages( '../images/tl.gif', '../images/tr.gif' );			
	getGallery = new ajaxObject('get_gallery.php', processGallery);
	getGallery.update('case='+iPage+'&set='+iSet+'&js=1');
		
	PreloadCssImages();	
	IndexEvents();
	AddLoadEvent(function() { DisableSelection('container'); });
}

PreLoadEvent(GalleryEvents);


