/**
 *
 * @author: Jens Hoffmann <jens.hoffmann@dkd.de> (c) DKD.2oo7
 *
 */

 var BackBTN = new Class({

		options: function() {

		},


		initialize: function(elementId) {

			window.addEvent('backbutton', function(event) {
				if (event.type == "backbutton" && event.hash !== "") {
					this.backBTNaction(event.hash);
				}
			}.bind(this));

			if (window.gecko) {
				// Replace Url without hash with Hash Url, so the Back Button can jump back to the starting Page
				if (location.hash === '') {
					location.replace(location.href + '#' + window.location.pathname);
				}
			}
			if (window.webkit) {
				// Replace Url without hash with Hash Url, so the Back Button can jump back to the starting Page
				if (location.hash === '') {
					location.replace(location.href + '#' + window.location.pathname);
				}
			}

		},

		setBackBTN: function(url) {
			// IF the URL is different than the current one, store it
			if (window.gecko || window.webkit ) {

				if (location.hash.substr(2) !== url) {
					if (url.charAt(0) == "/") {
						window.hash(url);
					}
					else {
						window.hash('/' + url);
					}
				}
			} else {
				if (location.hash.substr(2) !== url) {
					window.hash('/' + url);
				}
			}
		},

		backBTNaction: function(url) {
			theMain.theContent.getContent(url);
		}

});
