/**
 * @author philthomas
 */
var imagePath = site_root+"assets/images/imagine/newrange/Range/";
var activeRange = "chapel";

var thisPage = location.href.substring((location.href.lastIndexOf("/"))+1);
if( range_name )
	activeRange = range_name;
else if($(thisPage))
	activeRange = thisPage;

window.onload = setupDefaults();

function setupDefaults() 
{
	$('KitchenRange_Title').innerHTML = activeRange
	$('zoomButton').setAttribute("href", imagePath+"Fullsize/"+activeRange+".jpg");
	$('KitchenRange_Header').addClass(activeRange+'_Header');
	//Set the active Range thumb image
	$(activeRange).setAttribute("src", imagePath+"thumbs/"+activeRange+"_on.jpg");
	$(activeRange+'_content').setStyle('display','block');
	
	//Add Event listeners for the images
	$$('.rangeThumb').each(function(element) {	
		element.addEvents({
			'mouseover' : function() {
				swapImage(element.id,'on');
			},
			'mouseout' : function() {
				swapImage(element.id,'off');
			},
			'click' : function() {
				activateRange(element.id);
			}
		});
	});
}

function swapImage(id,type)
{
	if(activeRange != id)
		$(id).setAttribute("src", imagePath+"thumbs/"+id+"_"+type+".jpg");
}

function activateRange(id)
{
	var oldRange = activeRange;
	activeRange = id;
	
	//Set the active thumbs, and unset the previous one
	$(oldRange).setAttribute("src", imagePath+"thumbs/"+oldRange+"_off.jpg");
	$(activeRange).setAttribute("src", imagePath+"thumbs/"+activeRange+"_on.jpg");
	
	//Set the right zoom image
	$('zoomButton').setAttribute("href", imagePath+"Fullsize/"+activeRange+".jpg");
	
	//Now change the heading images and the title, and remove the old one
	$('KitchenRange_Title').innerHTML = activeRange;
	$('KitchenRange_Header').removeClass(oldRange+'_Header');
	$('KitchenRange_Header').addClass(activeRange+'_Header');
	
	//Show the new active content
	$(oldRange+'_content').setStyle('display','none');
	$(activeRange+'_content').setStyle('display','block');
}
