/** 
 * 	Class for all Listing item behaviour
 */
var ListingItem = new Class({
    initialize: function(el, index){
		var $ = document.id;
		
		this.id 			 = index + 1;
		this.el 			 = el;
		this.imageTop 	     = staticRoot+'img/bg_itemlisttop.gif';
		this.imageTopOver 	 = staticRoot+'img/bg_itemlisttop_over.gif';
		this.imageBottom	 = staticRoot+'img/bg_itemlistbottom.gif';
		this.imageBottomOver = staticRoot+'img/bg_itemlistbot_over.gif'
		var self = this;
		
		self.el.addEvent('mouseenter', function (){
			self.changebackground('div.listItemInner', 'mouseenter');
		});
		
		self.el.addEvent('mouseleave', function (){
			self.changebackground('div.listItemInner', 'mouseleave');
		});
    },		

	changebackground: function(subel, e) {
		var $ = document.id;
		
		if (this.el.imageBottom == undefined || this.el.imageBottom == null) {
			this.el.imageBottom = 'none';
		}

		if (this.el.imageBottomOver == undefined || this.el.imageBottomOver == null) {
			this.el.imageBottomOver = 'none';
		}
		switch(e) {
			case 'mouseenter':				
				if (subel != null || subel != '') {
					jQuery($(this.el).getElement(subel)).css({
						'background-image': 'url('+this.imageTopOver+')',
						'background-color': this.el.colour	
					});
				}	
				jQuery(this.el).css({
					'background-image': 'url('+this.imageBottomOver+')',
					'background-position': 'bottom',
					'background-repeat': 'no-repeat'
				});						
				break;
			
			case 'mouseleave':							
				if (subel != null || subel != '') {
					jQuery($(this.el).getElement(subel)).css({
						'background-image': 'url('+this.imageTop+')',
						'background-color': this.el.colour	
					});
				}	
				jQuery(this.el).css({
					'background-image': 'url('+this.imageBottom+')',
					'background-position': 'bottom',
					'background-repeat': 'no-repeat'
				});										
				break;
		}			
	}
});

window.addEvent('domready', function(){
	var listItemsArray = [];
	$$('.listItem').each(function(el, i) {
		listItemsArray[i] = new ListingItem(el, i);
	});
});

