/**
 * @author uloydl
 */

if (typeof(mobile) == "undefined") var mobile = {};

/*
 * Class to check if the banners (usually written into the page with document.write)
 * are "empty" wich means there is a 2x2 px image in the markup
 */
mobile.DartWatcher = Class.create({
	_bannerWrapper: null,
	_options: null,
	showBanner: false, 
	
	initialize: function(bannerWrapper, options){
		
		this._bannerWrapper = $(bannerWrapper);
		
		this._options = Object.extend({
				nullHtmlElement: "table img[src*='http://pics.ebaystatic.com/aw/pics/de/mobile_de/1x1.gif'], table img[src*='http://pics.ebaystatic.com/aw/pics/de/mobile_de/default_2x2.GIF']",
				toggleAction: "display"
			}, options);
		
		if (this._bannerWrapper){
			var isNullElement = this._checkNullElement();
			
			if (!isNullElement){
				//it's real content, toggle visibility or display
				if (this._options.toggleAction == "display") {
					this._bannerWrapper.setStyle({display: "block"});
				} else if (this._options.toggleAction == "visibility"){
					this._bannerWrapper.setStyle({visibility: "visible"});
				}
				//handy if you want to add some additional styles after the check
				this.showBanner = true;
			} else {
				//nothing to show
				this._bannerWrapper.hide();
			}
		}
	},
	
	//the bannerWrapper Element for changing styles if banner is displayed
	getBannerWrapper: function(){
		return this._bannerWrapper;
	},
	
	_checkNullElement: function(){
		var nullElement = this._bannerWrapper.down(this._options.nullHtmlElement);
		
		if (nullElement){
			return true;
		} else {
			return false;
		}
		
	}
});