//Hightlighter Mootools Class
//Sample usage:
/*
	<!--
		function runHighlight(){
			var testHi = new highLighter({
				highLightURL: '2008/inc/ajax/highlight/preview.html',
				divCSS: '2008/inc/ajax/highlight/css.css',
				injectDiv: $('osu-masthead'), // Use '$$(.myClass)' for classes
				padDiv: $('footer'), // Use '$$(.myClass)' for classes
				divHeight: 100
			});		
		}
		window.addEvent("domready", runHighlight);
	-->
*/
var highLighter = new Class({
		Implements: [Options, Events],
        options: {
			linkDepth: '',
			injectDiv: $('osu-masthead'),
			divPlacement: 'before',
			highLightDivIDName: 'highlight',
			highLightURL: '/test/highlight.html',
			padDiv: $$('div.osu-footer'),
			hideCSSClass: 'osu-semantic',
			showCSSClass: 'highlightShow',
			divHeight: 100,
			divCSS: 'css.css',
			debugMe: 'false'
        },
        initialize: function(options){
                this.setOptions(options);
                this.run(this.options);
        },
		run: function(opts) {
			//console.log(opts.padDiv);
			//console.log(opts.padDiv[0].get('text'));
			
			//get, set highlight div
			var hiDiv = new Element('div', {'id' : opts.highLightDivIDName});
			hiDiv.set({
				'opacity': 0
			});
			//load css
			var css = new Asset.css(opts.divCSS, { });

			var getContent = new Request.HTML({
				url: opts.highLightURL,
				method: 'get',
				update: hiDiv,
				//evalScripts: true,
				onComplete: function(){}
			});
			getContent.send();
			
			hiDiv.inject(this.checkDollar(opts.injectDiv), opts.divPlacement);	
			
			//pin highlight div
			var sw = window.getSize();
		
			hiDiv.erase('class');
			
			hiDiv.set({
				'class': opts.showCSSClass
			});
			hiDiv.setStyles({
				'height': opts.divHeight,
				'bottom': window.getPosition().y + 0

			});
			
			//pad bottom at bottom
			this.padBottom(opts);
			
			//ie error:
			//hiDiv.set('fade', {duration: 'long'});
			
			this.oldiehacks(hiDiv,sw);
			
			hiDiv.fade(1);
			//hiDiv.pin();
	},
	checkDollar: function(item) {
		var x;
		if (item.length > 0){
			x = item[0];
		}else{
			x = item;
		}
		return x;
	},
	padBottom: function(opts) {
		var pad = this.checkDollar(opts.padDiv);
		pad.setStyles({
			'padding-bottom': opts.divHeight + 10
		});
	},
	oldiehacks: function(highDiv, sw) {
		if(Browser.Engine.trident4) {
			highDiv.setStyles({
				'position': 'absolute',
				'bottom': window.getPosition().y + 0,
				'width': sw.x
			});
			
			window.addEvent('scroll',function(e) {
				highDiv.setStyles({
					'opacity': 0,
					'display': 'none'
				});
			});
		}
	}
});