/* 
	The following information must not be removed:
	Lytebox
	Written by: Paul Armstrong, Paul Armstrong Designs
	Site: http://paularmstrongdesigns.com
	Idea and some functions from "Sweet Titles":
		http://www.dustindiaz.com/sweet-titles/
	Example & Documentation: http://paularmstrongdesigns.com/examples/js/awesome-titles/
	Thu Jun 22 22:38:39 2006

	This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License
	http://creativecommons.org/licenses/by-sa/2.5/
	
	Required Yahoo! UI Libraries:
		* yahoo.js
		* dom.js
		* event.js
		* animation.js
*/
var Awesome = window.Awesome || {};

Awesome.titles = function() {
	var $D = YAHOO.util.Dom;
	var $E = YAHOO.util.Event;
	var $A = YAHOO.util.Anim;
	var $Ease = YAHOO.util.Easing;
	var $ = $D.get;
	var elements = new Array('a', 'abbr', 'acronym');
	
	/* getWindowWidth() and getWindowHeight()
	* Returns the amount of pixels that the browser is wide and high.
	*/
	function getWindowWidth() {
		var pageWidth;
		if (self.innerHeight) {	// Awesome Browsers
			pageWidth = self.innerWidth;
		} else if (document.documentElement && document.documentElement.clientHeight) { 
			// Exploder 6 Strict Mode
			pageWidth = document.documentElement.clientWidth;
		} else if (document.body) { // Other Exploders Versions
			pageWidth = document.body.clientWidth;
		}
		return pageWidth;	
	}
	function getWindowHeight() {
		var pageHeight;
		if (self.innerHeight) {	// Awesome Browsers
			pageHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { 
			// Exploder 6 Strict Mode
			pageHeight = document.documentElement.clientHeight;
		} else if (document.body) { // Other Exploders Versions
			pageHeight = document.body.clientHeight;
		}
		return pageHeight;
	}

	return {
		init : function() {
			var titleBox = document.createElement('p');
			document.getElementsByTagName('body')[0].appendChild(titleBox);
			titleBox.id = 'aTitles';
			$D.setStyle('aTitles', 'opacity', '0');
			
			var allEls = new Array();
			for(i = 0; i < elements.length; i++) {
				var thisEl = document.getElementsByTagName(elements[i]);
				for(j = 0; j < thisEl.length; j++) {
					allEls.push(thisEl[j]);
				}
			}

			var titleLinks = new Array();
			var titles = new Array();
			for(i = 0; i < allEls.length; i++) {
				var title = allEls[i].getAttribute('title');
				if (navigator.appName != "Microsoft Internet Explorer") {
					if(title != null) {
						titleLinks.push(allEls[i]);
					}
				} else {
					if(title != '') {
						titleLinks.push(allEls[i]);
					}
				}
			}

			$E.addListener(titleLinks, 'mouseover', this.titlePop);
			$E.addListener(titleLinks, 'mouseout', this.titleHide);
			$E.addListener(titleLinks, 'click', this.titleHide);
		},
		
		titlePop : function(e) {
			var newTitle = $(this).getAttribute('title');
			$('aTitles').innerHTML = newTitle;
			this.setAttribute('title', ''); // remove title so browser doesn't show tooltip
			var x = parseInt($E.getPageX(e))+10;
			var y = parseInt($E.getPageY(e))+10;
			
			// fudge the position if it is off the document size
			if(x+100 >= getWindowWidth()) { x = x-100; }
			if(y+30 >= getWindowHeight()) { y = y-30; }
			
			$D.setStyle('aTitles', 'top', y+'px');
			$D.setStyle('aTitles', 'left', x+'px');
			var show = new $A('aTitles', { opacity: { from: 0, to: 0.9 } }, 0.4 );
			show.onStart.subscribe(function() {
				$D.setStyle('aTitles', 'display', 'block');
			});
			show.animate();
		},

		titleHide : function() {
			this.setAttribute('title', $('aTitles').innerHTML); // replace info into title attr
			var hide = new $A('aTitles', { opacity: { to: 0 } }, 0.1);
			hide.animate();
			$D.setStyle('aTitles', 'display', 'none');
		}
	}
}();
YAHOO.util.Event.on(window, 'load', Awesome.titles.init, Awesome.titles, true);


