window.jsboxed = {};
(window.jsboxed['libraries/desputeauxaubin'] = new function() {

(window.jsboxed['libraries/shortcuts'] = new function() {

window['$'] = function(id) {
	return document.getElementById(id);
}

});
(window.jsboxed['libraries/css-url-preloader'] = new function() {

var dean = (window.jsboxed['vendors/events'] = new function() {
/**
 * Dean Edwards, 2005 with input from Tino Zijdel
 * http://dean.edwards.name/weblog/2005/10/add-event/
 */

// a counter used to create unique IDs
var guid = 1;

this.addEvent = function(element, type, handler) {
	// assign each event handler a unique ID
	if (!handler.$$guid) handler.$$guid = guid++;
	// create a hash table of event types for the element
	if (!element.events) element.events = {};
	// create a hash table of event handlers for each element/event pair
	var handlers = element.events[type];
	if (!handlers) {
		handlers = element.events[type] = {};
		// store the existing event handler (if there is one)
		if (element["on" + type]) {
			handlers[0] = element["on" + type];
		}
	}

	// store the event handler in the hash table
	handlers[handler.$$guid] = handler;
	// assign a global event handler to do all the work
	element["on" + type] = handleEvent;
}

this.removeEvent = function(element, type, handler) {
	// delete the event handler from the hash table
	if (element.events && element.events[type]) {
		delete element.events[type][handler.$$guid];
	}
}

function handleEvent(event) {
	var returnValue = true;
	// grab the event object (IE uses a global event object)
	event = event || fixEvent(window.event);
	// get a reference to the hash table of event handlers
	var handlers = this.events[event.type];
	// execute each event handler

	for (var i in handlers) {
		this.$$handleEvent = handlers[i];
		if (this.$$handleEvent(event) === false) {
			returnValue = false;
		}
	}
	return returnValue;
}

function fixEvent(event) {
	// add W3C standard event methods
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
}
fixEvent.preventDefault = function() {
	this.returnValue = false;
}
fixEvent.stopPropagation = function() {
	this.cancelBubble = true;
}

});
(window.jsboxed['D:/name/gagnon/mathieu/www/tools/jsbox'] = new function() {

});

var self = this;
self.preloaded = [];

/**
 * Uses css level 1 pseudo-class and properties that
 * takes url to assure preloading.
 */
dean.addEvent(window, 'load', function() {
	var props = ["background", "backgroundImage", "listStyle", "listStyleImage"];
	var pseudos = /:(active|hover|link|visited)/;
	var sheet, rules, matched;

	for (var i = 0; i < document.styleSheets.length; i++) {
		sheet = document.styleSheets[i];
		rules = sheet.cssRules || sheet.rules;

		for (j = 0; j < rules.length; j++) {
			if (rules[j].selectorText && rules[j].selectorText.match(pseudos)) {

				for (var k = 0; k < props.length; k++) {
					matched = rules[j].style[props[k]].match(/url\([\'\"]?(.*)[\'\"]?\)/);
					if (matched) {
						self.preloaded.push(new Image().src = matched[1]);
					}
				}
			}
		}
	}
});


});
var dean = window.jsboxed['vendors/events'];
var scroller = (window.jsboxed['libraries/scroller'] = new function() {

(window.jsboxed['extensions/function'] = new function() {

/**
 * Creates a new function that will execute the current function
 * in the context of the passed argument.
 * @param object context
 */
Function.prototype.bind = function(object) {
	var self = this;
	return function() {
		self.apply(object, arguments);
	}
}


/**
 * Instead of executing a function, it returns a new function
 * that will execute with the same arguments and context.
 */
Function.prototype.callback = function() {
	var self = this;
	var _arguments = arguments;
	return function() {
		self.apply(self, _arguments);
	}
}

});


/**
 * dont put any border on the container.
 * The scrollarea have to be positioned relative.
 */
this.Scroller = function(container, scrollarea) {
	var MOVE_UP = 1;
	var MOVE_DOWN = -1;
	var direction = MOVE_UP;
	var timer = null;

	var MAX_UP = 0;
	var MAX_DOWN = container.offsetHeight - scrollarea.offsetHeight;
	this.stepMilliseconds = 20;
	this.stepPixels = 2;

	//ie5 mac needs an absolute positioning
	//scrollarea.style.position = 'absolute';

	scrollarea.style.top = scrollarea.offsetTop + 'px';

	this.up = function() {
		direction = MOVE_UP;
	}

	this.down = function() {
		direction = MOVE_DOWN;
	}

	this.startUp = function() {
		this.up();
		this.start();
	}

	this.startDown = function() {
		this.down();
		this.start();
	}

	this.start = function() {
		this.stop();
		window.tata = this.step.bind(this)
		//
		// ie5 mac does not accept the reference type, only eval form
		//
		timer = setInterval("tata()", this.stepMilliseconds);
	}

	this.stop = function() {
		clearInterval(timer);
	}

	this.step = function () {
		var mouvement = parseInt(scrollarea.style.top) + direction * this.stepPixels;

		if (mouvement <= MAX_DOWN) {
  		mouvement = MAX_DOWN;
  		this.stop();
		} else if (mouvement >= MAX_UP) {
			mouvement = MAX_UP;
			this.stop();
		}

		scrollarea.style.top = mouvement + "px";
	}

}


});


document.write('<style type="text/css" media="screen">#content { overflow:hidden; }</style>');

dean.addEvent(window, 'load', function() {

	/*
	 * lang switcher
	 */
	var link_nodes = document.getElementsByTagName('link');
	var alt_lang = $('alternate-lang');
	if (alt_lang && link_nodes.length > 0) {
		for (var i = 0; i < link_nodes.length; i++) {
			if (link_nodes[i].type == 'alternate' && link_nodes[i].hreflang) {
				alt_lang.href = link_nodes[i].href;
			}
		}
	}
	
	/*
	 * Ajust the scroller.
	 */
	var content = document.getElementById('content');
	var scrollarea = document.getElementById('container');
	if (!content || !scrollarea)
		return;

	scrollarea.className = 'scrollarea';
	if (scrollarea.offsetHeight <= content.offsetHeight)
		return;

	var myScroller = new scroller.Scroller(content, scrollarea);
	//
	// Buttons creation
	// The events does not seems to work with ie5 mac on anchor,
	// so it's better to use img node. but of course it's bad to
	// hardcode the images url in here.
	//

	var btn = document.getElementById('scroll_up');
	btn.style.visibility = 'visible';

	btn.onmouseover = function() {
		myScroller.stepPixels = 2;
		myScroller.startUp();
		this.src = '/+link/images/scroll-up-hover.gif';
	}
	btn.onmousedown = function() {
		myScroller.stepPixels = 6;
	}
	btn.onmouseup = function() {
		myScroller.stepPixels = 2;
	}
	btn.onmouseout = function() {
		myScroller.stop();
		this.src = '/+link/images/scroll-up.gif';
	}

	var btn = document.getElementById('scroll_down');
	btn.style.visibility = 'visible';

	btn.onmouseover = function() {
		myScroller.stepPixels = 2;
		myScroller.startDown();
		this.src = '/+link/images/scroll-down-hover.gif';
	}
	btn.onmousedown = function() {
		myScroller.stepPixels = 6;
	}
	btn.onmouseup = function() {
		myScroller.stepPixels = 2;
	}
	btn.onmouseout = function() {
		myScroller.stop();
		this.src = '/+link/images/scroll-down.gif';
	}
});





/*
function loadHandler() {
	var gallery = $('gallery_navigation');
	if (gallery) {
		for (var i = 0; i < gallery.childNodes.length; i++) {
			if (gallery.childNodes[i].getElementsByTagName) {
				var anchor = gallery.childNodes[i].getElementsByTagName('a')[0];
				dean.addEvent(anchor, 'click', galleryNavigationHandler);
			}
			gallery.childNodes[i].tagName == 'A';
		}

	}

	function galleryNavigationHandler() {
		var id = this.href.split('=').pop();
		//$('');alert(id);
		return false;
	}
}

dean.addEvent(window, 'load', loadHandler);
*/

})
