//generic functions for use by RelBehavior instances

var windowStatus = {
	storedStatus : '',
	setToTitle : function(){
		windowStatus.store();
		window.status = this.title;
		return true;
	},
	store : function(){
		this.storedStatus = window.status;
	},
	restore : function(){
		window.status = windowStatus.storedStatus;
	}
};

function assignRelBehaviors(){
	var a, aRels = [], rel, behavior;
	for (var i = 0; (a = document.links[i]); i++) {
		if (!a.rel){continue};
		aRels = a.rel.split(' ');
		for(rel in aRels){
			behavior = eval(aRels[rel]);
			if(behavior && behavior.constructor == RelBehavior){
				behavior.assign(a, aRels[rel]);
			}
		}
	}
}


//RelBehavior constructor
function RelBehavior(){
	this.eventHandlers = new Object();
}
RelBehavior.instances = new Array();
RelBehavior.assignAll = function(){
	var foo = RelBehavior.instances;
	for(var i in foo){
		alert(i + ' - ' + foo[i]);
	}
}
RelBehavior.prototype.assign = function(a, rel){
	for(var h in this.eventHandlers){
		a[h] = this.eventHandlers[h];
	}
}
RelBehavior.prototype.setup = function(initObj){
	for(var i in initObj){
		this[i] = initObj[i];
	}
}


//RelBehavior instances

var productView = new RelBehavior();
productView.setup = function(){
	this.swapImg = document.images["productImage"];
}
productView.eventHandlers.onclick = function(){
	productView.swapImg.src = this.href;
	window.scrollTop = window.location + '#productImage';
	return false;
}
productView.eventHandlers.onmouseover = windowStatus.setToTitle;
productView.eventHandlers.onmouseout = windowStatus.restore;


var drawingView = new RelBehavior();
drawingView.setup = function(){
	this.swapImg = document.images["drawingImage"];
}
drawingView.eventHandlers.onclick = function(){
	drawingView.swapImg.src = this.href;
	window.scrollTop = window.location + '#drawingImage';
	return false;
}
drawingView.eventHandlers.onmouseover = windowStatus.setToTitle;
drawingView.eventHandlers.onmouseout = windowStatus.restore;


