
Element.implement({
	getIndex: function(type) {
        type = (type) ? type : '';
        return $$(type).indexOf(this);
    },

	exists: function() {
        return (this.getIndex() >= 0);
    },

	getClassStoredValue: function(varName) {
		var c = this.get('class').split(' ');
		for(var i = 0; i < c.length; i++) {
			if(c[i].substr(0, c[i].indexOf('-')) == varName) {
				return c[i].substr(c[i].indexOf('-') + 1);
			}
		}
		return null;
	},
	
	setClassStoredValue: function(varName, varValue) {
		var c = this.get('class').split(' ');
		var curValue = this.getClassStoredValue(varName);
		if(curValue) {
			this.removeClass(varName + '-' + curValue);
		}
		this.addClass(varName + '-' + varValue);
	}
});



var Berta = new Class({
	
	Implements: Options,
	
	options: {
		paths: null,
		playerType: 'JWPlayer'
	},
	
	entriesList: null,
	galleries: new Array(),
	
	initialize: function(options) {
		this.setOptions(options);
		window.addEvent('domready', this.onDOMReady.bindWithEvent(this));
		window.addEvent('load', this.onLoad.bindWithEvent(this));
		
		if(!window.console) {
			window.console = { debug: function() { }, log: function() { } };
		}
	},
	
	onDOMReady: function(event) {
		//console.debug('Berta: dom_ready');
		
	},
	
	onLoad: function(event) {
		//console.debug('Berta: load');
		
		// init entry galleries only in "load" event because otherwise in some browsers
		// (eg. safari), the CSS sometimes is not loaded in time to get the styles from
		// the elements with javascript
		this.initEntriesList();
	},
	
	initEntriesList: function() {
		this.entriesList = $('pageEntries');
		this.entriesList.getElements('.xGalleryContainer').each(function(item) {
			var g = new BertaGallery(item, { engineRoot: this.options.paths.engineRoot, playerType: this.options.videoPlayerType });
			this.galleries.push(g);
		}.bind(this));
	}
	
});

var berta = new Berta(window.bertaGlobalOptions);
