// JavaScript Document




$(document).ready(function() {
	// this is all artists directory code... may as well load it up.
	$('a.artistThumb').click(function(event)
	{
		event.preventDefault();
		idstring = $(this).attr('id');
		clickThumb(idstring);
	});
	$('div#artistImageNav a.prevLink').click(function(event)
	{
		event.preventDefault();
		prevThumb();
	});
	$('div#artistImageNav a.nextLink').click(function(event)
	{
		event.preventDefault();
		nextThumb();
	});
	$('a#searchGo').click(function(event)
	{
	   event.preventDefault();
	   submitSearch();
	});
	$('a#home_searchGo').click(function(event)
	{
	   event.preventDefault();
	   submitSearch();
	});
});


function submitSearch()
{
	if($('input#q').length)
	{
		searchtext = $('input#q').val();
	}
	else
	{
		searchtext = $('input#home_q').val();	
	}
	if(searchtext == 'search all artists' || searchtext == ' search all artists...')
	{	
		alert('Please enter some search terms...');	
	}
	else
	{
		$('form#formQ').submit();
	}
}


function prevThumb()
{
	if(!prevImgId)
	{
		prevImgId = imageIDs[imageIDs.length-1];	
	}
	clickThumb(prevImgId);
}
function nextThumb()
{
	if(!nextImgId)
	{
		nextImgId = imageIDs[1];	
	}
	clickThumb(nextImgId);
}

function clickThumb(idstring)
{
	$('a.artistThumb').removeClass('active');
	thumb = $('a#'+idstring);
	thumb.addClass('active');
	href = thumb.attr('href');
	title = thumb.attr('title')+'&nbsp;';
	$('div#artistImage').css("background-image", "url("+href+")");  
	$('div#artistImageInfo').html(title);
	updateText(idstring);
}

var currentImgId = '';
var prevImgId = false;
var nextImgId = false;
function updateText(idstring)
{
	
	oneOf = '';
	for(c=0;c<imageIDs.length;c++)
	{
		if(imageIDs[c] == idstring)
		{
			oneOf = (c+1);
			if(c==0) // at the start
			{
				prevImgId = imageIDs[imageIDs.length-1];
				nextImgId = imageIDs[c+1];
			}
			else if(c==(imageIDs.length-1)) //at the end
			{
				prevImgId = imageIDs[c-1];
				nextImgId = imageIDs[0];
			}
			else //somewhere in the middle
			{
				prevImgId = imageIDs[c-1];
				nextImgId = imageIDs[c+1];
			}
			
		}
	}
	$('div#artistImageNav span.thumbNum').html(oneOf);
}
