/*  behaviour_rules.js - Rules for use with the behaviour.js library.
	Behaviour lets you use CSS selectors to specify elements to which
    JavaScript events should be added. http://bennolan.com/behaviour */

var brules = {
	'a' : function(element) {
		if (element.onclick == null || element.onclick == '' || typeof(element.onclick) == undefined) {
			element.onclick = function() {
				switch (this.getAttribute('rel')) {
					case 'external':
						this.setAttribute('target', '_blank');
						return true;
						break;
				}
			}
		}
	},
	'.switcher ul a' : function(element) {
		element.onclick = function() {
			activateportfolio(this);
			return false;
		}
	},
	'.switcher img.switcher_prev' : function(element) {
		element.onmouseover = function() {
			this.style.cursor = 'pointer';
		}
		element.onclick = function() {
			prevportfolio(this);
			return false;
		}
	},
	'.switcher img.switcher_next' : function(element) {
		element.onmouseover = function() {
			this.style.cursor = 'pointer';
		}
		element.onclick = function() {
			nextportfolio(this);
			return false;
		}
	},
	'ul.reasonlist a' : function(element) {
		element.onclick = function() {
			openpub(this.getAttribute('href'), 'reason');
			return false;
		}
	},
	'ul.choiceslist a' : function(element) {
		element.onclick = function() {
			openpub(this.getAttribute('href'), 'choices');
			return false;	
		}
	},
	'ul.calendarlist a' : function(element) {
		element.onclick = function() {
			opencal(this);
			return false;	
		}
	},
	'.pubpagecontainer a' : function(element) {
		element.onclick = function() {
			switch (this.getAttribute('rel')) {
				case 'external':
					this.setAttribute('target', '_blank');
					return true;
					break;
				case 'mainwindow':
					if (window.opener) {
						window.opener.location = this.getAttribute('href');
						window.opener.focus();
						return false;
					} else {
						this.setAttribute('target', '_blank');
						return true;
					}
					break;
				default:
					return true;
			}
		}
	}
};

Behaviour.register(brules);
