var __n = false;
function isIE() {
	if (!__n)
		__n = navigator.appVersion;

	if (__n.indexOf('MSIE') != -1)
		return __n;
	
	return false;
}

function newWin(loc, w, h) {
	if (!w) { w = 630;}
	if (!h) { h = 500;}
	window.open(loc,"images","height="+h+",width="+w+",status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
	return false;
	
}

var isDOM = document.getElementById;


var d = {
	$: function(id) {
		return document.getElementById(id);
	},
	getByTag: function(tagname) {
		return document.getElementsByTagName(tagname);
	}
}


function getById(id) {
		return document.getElementById(id);
	}


function getParentNodeByType(obj, type) {
		pn = obj.parentNode;
		if (pn.nodeName == type || pn.nodeName == type.toUpperCase()) {
				return pn;
			}
				
		return getParentNodeByType(pn, type);
	}
	
	
var PNG = {
	fixed: [],
	needFix: function (img) {
		var ie = isIE();
		if (!ie)
			return false;

		var arVersion = ie.split("MSIE")
		var version = parseFloat(arVersion[1])
	
		if ((version <= 5.5) || (!document.body.filters))
			return false;
		
		var imgName = img.src
		if (!imgName)
			return false;
		
		imgName = imgName.toUpperCase()
		if (imgName.substring(imgName.length-3, imgName.length) != "PNG")
			return false;
		
		return true;
	},
	isFixed: function(img) {
		for (f=0;f<this.fixed.length;f++) {
			if (this.fixed[f] == img)
				return true;
				
		}
		return false;
	},

	fixAll: function() {
		var imgs = document.getElementsByTagName('img');
		var imgl = imgs.length;
		
	   for(var i=0; i<imgl; i++) {
		  this.fix(imgs[i]);  
	   }
	
	},
	
	fix: function(img) {
		
		if (!this.needFix(img) || this.isFixed())
			return true;
		
		
		var src = img.src;		
		var imgName = src.toUpperCase()
		
		var imgID = (img.id) ? "id='" + img.id + "' " : ""
		var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		var imgStyle = "display:inline-block;" + img.style.cssText 
			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + src + "\', sizingMethod='scale');\"></span>" 
			 img.outerHTML = strNewHTML

		this.fixed.push(img);
	}
}

function fixPNG(img) {
	PNG.fix(img);
}

fixed_all_pngs = false;
function fixPNGs() {
	PNG.fixAll();	
}



/* flash detection from quirksmode */


var flashinstalled = 0;
var flashversion = 0;
MSDetect = "false";
if (navigator.plugins && navigator.plugins.length)
{
	x = navigator.plugins["Shockwave Flash"];
	if (x)
	{
		flashinstalled = 2;
		if (x.description)
		{
			y = x.description;
			flashversion = y.charAt(y.indexOf('.')-1);
		}
	}
	else
		flashinstalled = 1;
	if (navigator.plugins["Shockwave Flash 2.0"])
	{
		flashinstalled = 2;
		flashversion = 2;
	}
}
else if (navigator.mimeTypes && navigator.mimeTypes.length)
{
	x = navigator.mimeTypes['application/x-shockwave-flash'];
	if (x && x.enabledPlugin)
		flashinstalled = 2;
	else
		flashinstalled = 1;
}
else
	MSDetect = "true";


/* end flash detect */

var DEBUG = 1

Function.prototype.bind = function() {
  var __m_____ = this, args = Util.to_array(arguments), obj = args.shift();
  return function() { return __m_____.apply(obj, args.concat(Util.to_array(arguments)));}
}
Array.prototype.each = function(block) {
	for (var a=0; a<this.length;a++) {
		if (block(this[a], a)) { break;};
	}
}
var D = {
	init: function() { this.isReady() },
	isReady: function() {
		this.n = typeof this.n == 'undefined' ? 0 : this.n + 1;
		if (typeof document.getElementsByTagName != 'undefined' 
			&& (document.getElementsByTagName('body')[0] != null || document.body != null)) {	
				D.Event.dispatch('ready')
		} else if(this.n < 60) { setTimeout('D.isReady()', 10); } // this needs testing on IE
	},
	Event: {
		//internal event manager
		listeners: {},
		add: function(evnt, cb) {
			if (!this.listeners[evnt]) this.listeners[evnt] = [];
			this.listeners[evnt].push(cb);
		},
		remove: function(evnt) { delete this.listeners[evnt] },
		get: function(name) { return this.listeners[name] },
		dispatch: function(evntname) {
			cb = this.get(evntname)
			if (cb) for (i=0; i<cb.length;i++) cb[i].apply();
			this.remove(evntname);
		}
	},
	Element: {
		by_id: function(id) {
			return document.getElementById(id)
		},
		by_class: function(classn, parent, tag) {
			var par = D.$(parent) || document;
			var t = tag || '*';
			
			var children = par.getElementsByTagName(t);

			var elements = new Array();

			for (var i = 0; i < children.length; i++) {
				var child = children[i];
				var classNames = child.className.split(' ');
				for (var j = 0; j < classNames.length; j++) {
					if (classNames[j] == classn) {
						elements.push(child);
						break;
					}
				}
			}
			return elements;			
		},
		by_tag: function(tagname, parent) {
			if (!parent) parent = document
			var tags = parent.getElementsByTagName(tagname)
			if (!tags || tags.length == 0) return;
			return (tags.length == 1) ? tags[0] : Util.to_array(tags);
		}
	},
	$: function(el, parent, tag) {
		if (typeof el != 'string') return el;
		
		switch (el.charAt(0)) {
			case '#':
				return this.Element.by_id(el.replace('#', ''))
			break;
			case '.':
				return this.Element.by_class(el.replace('.', ''), parent, tag)
			break;
			default:
				return this.Element.by_tag(el, parent)
			break;
		}
	},
	e: function(block) {
	    var el;
	    if ('string'==typeof block) {
	        el=document.createTextNode(block);
	    } else {
	        el=document.createElement(block.tag);
	        delete(block.tag);
	        if ('undefined'!=typeof block.children) {
	            if ('string'==typeof block.children ||
	                'undefined'==typeof block.children.length
	            ) {
	                el.appendChild(D.e(block.children));
	            } else {
	                //array
	                for (var i=0, child=null; 'undefined'!=typeof (child=block.children[i]); i++) {
	                    el.appendChild(D.e(child));
	                }
	            }
	            delete(block.children);
	        }
			if ('undefined'!=typeof block.events) { 
				for (ev in block.events)
					E.add(el, ev, block.events[ev])
				
				delete block.events
			}

	        for (attr in block) {
				if (attr == 'class')
					el.className = block[attr]
				else
	            	el[attr]=block[attr];
	        }
	    }

	    return el;
	},
	children: function(el) {
		return el.childNodes
	},
	Children: {
		count: function() { return el.childNodes.length },
		by_class: function(classname, el) {}
	},
	Parent: {
		find: function(el, attrs) {
			if (!el) return false;
			for (a in attrs) {
					if (a == 'tag')
						if (el.nodeName.toUpperCase() == attrs[a].toUpperCase()) {
							return el;
						}
					//add more tests. only supports tag now
				}
			return this.find(el.parentNode, attrs);
		}
	},
	__append: function(el, els) {
		if ('string'==typeof els) {
			el.appendChild(document.createTextNode(els));
			return;
		}
		try {
			el.appendChild(els)
		} catch(e) {
			try {
				for (var i=0;i<els.length;i++) {
					el.appendChild(els[i])
				}
			} catch (e) {
				if (DEBUG) alert(e);
			}
		}
		
	},
	__insert: function(els, el) {
		InvalidNodeTypeException = function() {}
		try {
			if (el.parentNode.nodeType == 11) {
				throw new InvalidNodeTypeException()
			} else {
				el.parentNode.insertBefore(els, el)
			}
		} catch(e) {
			try {
				els.parentNode.insertBefore(el, els)
			} catch (e) {
				if (DEBUG) alert(e)
			}
		}
	},
	Insert: {
		before: function(els, el) {
			D.__insert(els, el)
		},
		first: function(el, els) {
			if (el.firstChild)
				D.__insert(el.firstChild, els)
			else
				D.__append(el, els)
		},
		last: function(el, els) {
			D.__append(el, els)
		},
		at: function(el, els, pos) {
			alert(el.childNodes[0])
			D.__insert(el.childNodes[pos], els)
		}
		
	},
	Style: {
		apply: function(elem, styles) {
			for (style in styles) {
				elem.style[style] = styles[style]
				if (style == 'opacity' && window.ActiveXObject) {
						elem.style.filter = "alpha(opacity="+styles[style]*100+")";
				}
			}
		}
	}
}


var E = {
	add: function(obj, evt, func) {
		if (document.addEventListener) obj.addEventListener(evt, func, false);
		else if(document.attachEvent) obj.attachEvent('on'+evt,func);
		},
	remove: function(obj, evt, func) {
			obj.removeEventListener(evt, func, false);
		},
	get: function(e, p) {
			var e = e || window.event;
			if (p) E.pd(e);
			return t = e.target || e.srcElement;
		},
	pd: function(e) {
			if (e.stopPropagation) e.stopPropagation();	 
			else if(e.cancelBubble) e.cancelBubble = true;			
			if (e.preventDefault) e.preventDefault();
			else e.returnValue = false; 
	},
	pos: function(e) {
		var left = 0;
		var top  = 0;
		while (e.offsetParent){
			left += e.offsetLeft;
			top  += e.offsetTop;
			e     = e.offsetParent;
		}
		left += e.offsetLeft;
		top  += e.offsetTop;

		return {x:left, y:top};
	}
}


var Util = {
		clean: function(parobj) {
			var notWhiteSpaceNode = /\S/;				
			for (i=0;i<parobj.childNodes.length;i++){
				if ((parobj.childNodes[i].nodeType == 3)
				&& (!notWhiteSpaceNode.test(parobj.childNodes[i].nodeValue))) {
					parobj.removeChild(parobj.childNodes[i]);
						i--;
				}
			}
		},
		to_array: function(it) {
			if (!it) return [];
			if (it.toArray)
				return it.toArray();
		 	else {
		    	var r = [];
		    	for (var i = 0; i < it.length; i++)
					r.push(it[i]);
				return r;
			}
		}
	}








window.onload = function() {
		//setTextScroller();
		fixPNGs();
	};















