DP = {
	addEvent: function(el, evnt, fnct) {
		if(el) {
			if(window.addEventListener) {
				el.addEventListener(evnt, fnct, null);
			} else if(window.attachEvent) {
				el.attachEvent('on'+evnt, fnct);
			}
		}
		return el;
	},
	eventListenerExample: function(e) {
		e = e || event;
		var t = e.target || e.srcElement;
	},
	hidePlaceHolder: function(e) {
		e = e || event;
		var t = e.target || e.srcElement;
		if(t.value == t.getAttribute('placeholder')) {
			t.value = '';
		}
		return;
	},
	showPlaceHolder: function(e) {
		e = e || event;
		var t = e.target || e.srcElement;
		if(t.value == '') {
			t.value = t.getAttribute('placeholder');
		}
		return;
	},
	initPlaceHolder: function() {
		var ins = document.getElementsByTagName('input'),
			l = ins.length, i = 0;
		for(i = 0; i < l; i++) {
			if(ins[i].getAttribute('placeholder')) {
				if(ins[i].value === '') {
					ins[i].value = ins[i].getAttribute('placeholder');
					DP.addEvent(ins[i], 'focus', DP.hidePlaceHolder);
					DP.addEvent(ins[i], 'blur', DP.showPlaceHolder);
				}
			}
		}
		return;
	},
//	newsRotateNext: function() {
//		var wa = document.getElementById('widget-top-home-widget-area'),
//			a = wa.getElementsByTagName('li'),
//			l = a.length, c = 0, cur = false, nxt = false, o = 0, o2 = 0,
//			fade = function() {
//				if(o+.1 < 1) {
//					o += .1;
//					o2 += 10;
//					nxt.style.opacity = o;
//					nxt.style.filter = "alpha(opacity=" + (o2) + ")";
//					setTimeout(fade, 10);
//				} else {
//					nxt.style.opacity = 1;
//					nxt.style.filter = "alpha(opacity=100)";
//					cur.style.opacity = 0;
//					cur.style.filter = "alpha(opacity=0)";
//					cur.style.zIndex = 1;
//					cur.className = cur.className.replace('current', '');
//					nxt.className += ' current';
//				}
//			};
//		for(c = 0; c < l; c++) {
//			if(a[c].className.indexOf('current') !== -1) {
//				cur = a[c];
//				cur.style.zIndex = (l-1);
//				cur.style.opacity = 1;
//				cur.style.filter = "alpha(opacity=100)";
//				if(c+1 >= l) {
//					nxt = a[0];
//				} else {
//					nxt = a[c+1];
//				}
//				nxt.style.zIndex = (l);
//				nxt.style.opacity = 0;
//				nxt.style.filter = "alpha(opacity=0)";
//				break;
//			}
//		}
//		if(cur && nxt) {
//			fade();
//		}
//	},
//	newsRotateInit: function() {
//		var wa = document.getElementById('widget-top-home-widget-area'),
//			a = wa.getElementsByTagName('li'),
//			l = a.length, c = 0;
//		for(c = 0; c < l; c++) {
//			if(c == 0) {
//				a[c].style.zIndex = (l);
//				a[c].className += ' current';
//				a[c].style.opacity = 1;
//				a[c].style.filter = "alpha(opacity=100)";
//			} else {
//				a[c].style.zIndex = 1;
//				a[c].style.opacity = 0;
//				a[c].style.filter = "alpha(opacity=0)";
//			}
//			a[c].onclick = function(e) {
//				location.href = this.getElementsByTagName('a')[0].href;
//			};
//		}
//		setInterval(DP.newsRotateNext, 5000);
//	},
	imageRotateSet: function(el) {
		var a = el.childNodes,
			l = a.length, c = 0, heightreq = 0, hasFirst = false, killthis = [];
		el.style.position = 'relative';
		for(c = 0; c < l; c++) {
			if(a[c].nodeType == 1) {
				if(a[c].offsetHeight > heightreq) {
					heightreq = a[c].offsetHeight;
				}
				a[c].style.position = 'absolute';
				a[c].style.top = '0px';
				a[c].style.left = '0px';				
				if(!hasFirst) {
					hasFirst = true;
					a[c].style.zIndex = l;
					a[c].style.opacity = 1;
					a[c].style.filter = "alpha(opacity=100)";
					a[c].className += ' current';
				} else {
					a[c].style.zIndex = 1;
					a[c].style.opacity = 0;
					a[c].style.filter = "alpha(opacity=0)";
				}
			} else {
				killthis[killthis.length] = a[c];
			}
		}
		el.style.height = heightreq + 'px';
//		el.style.clip = 'auto';
//		el.style.overflow = 'hidden';
		l = killthis.length;
		for(c = l-1; c >= 0; c--) {
			killthis[c].parentNode.removeChild(killthis[c]);
		}
	},
	imageRotateDoFade: function(el) {
		var a = el.childNodes,
			l = a.length, c = 0, cur = false, nxt = false, o = 0, o2 = 0,
			fade = function() {
				if(o+.1 < 1) {
					o += .1;
					o2 += 10;
					nxt.style.opacity = o;
					nxt.style.filter = "alpha(opacity=" + (o2) + ")";
					setTimeout(fade, 10);
				} else {
					nxt.style.opacity = 1;
					nxt.style.filter = "alpha(opacity=100)";
					cur.style.opacity = 0;
					cur.style.filter = "alpha(opacity=0)";
					cur.style.zIndex = 1;
					cur.className = cur.className.replace('current', '');
					nxt.className += ' current';
					DP.setCurrentDot(el);
				}
			};
		for(c = 0; c < l; c++) {
			if(a[c].className.indexOf('current') !== -1) {
				cur = a[c];
				cur.style.zIndex = (l-1);
				cur.style.opacity = 1;
				cur.style.filter = "alpha(opacity=100)";
				if(c+1 >= l) {
					nxt = a[0];
				} else {
					nxt = a[c+1];
				}
				nxt.style.zIndex = (l);
				nxt.style.opacity = 0;
				nxt.style.filter = "alpha(opacity=0)";
				break;
			}
		}
		if(cur && nxt && cur != nxt) {
			fade();
		}
	},
	imageRotateDoFadePrev: function(el) {
		var a = el.childNodes,
			l = a.length, c = 0, cur = false, nxt = false, o = 0, o2 = 0,
			fade = function() {
				if(o+.1 < 1) {
					o += .1;
					o2 += 10;
					nxt.style.opacity = o;
					nxt.style.filter = "alpha(opacity=" + (o2) + ")";
					setTimeout(fade, 10);
				} else {
					nxt.style.opacity = 1;
					nxt.style.filter = "alpha(opacity=100)";
					cur.style.opacity = 0;
					cur.style.filter = "alpha(opacity=0)";
					cur.style.zIndex = 1;
					cur.className = cur.className.replace('current', '');
					nxt.className += ' current';
					DP.setCurrentDot(el);
				}
			};
		for(c = 0; c < l; c++) {
			if(a[c].className.indexOf('current') !== -1) {
				cur = a[c];
				cur.style.zIndex = (l-1);
				cur.style.opacity = 1;
				cur.style.filter = "alpha(opacity=100)";
				if(c-1 >= 0) {
					nxt = a[c-1];
				} else {
					nxt = a[a.length-1];
				}
				nxt.style.zIndex = (l);
				nxt.style.opacity = 0;
				nxt.style.filter = "alpha(opacity=0)";
				break;
			}
		}
		if(cur && nxt && cur != nxt) {
			fade();
		}
	},
	imageRotateDo: function() {
		var a = document.getElementsByTagName('*'),
			l = a.length, c = 0, hasRotate = false;
		for(c = 0; c < l; c++) {
			if(a[c].className.indexOf('image-rotate') !== -1 && a[c].getAttribute('rotate') == 1) {
				if(a[c].dorotate == 1) {
					DP.imageRotateDoFade(a[c]);
				}
				hasRotate = true;
			}
		}
	},
	imageRotateAdvance: function(e) {
		e = e || event;
		var t = e.target || e.srcElement,
			d = false, r = false;
		e.returnValue = false;
		if(e.preventDefault) {
			e.preventDefault();
		}
		if(t.nodeName.toLowerCase() == 'a') {
			d = t.parentNode;
			r = d.previousSibling;
			r.dorotate = 0;
			switch(t.className) {
				case 'next':
					DP.imageRotateDoFade(r);
				break;
				case 'prev':
					DP.imageRotateDoFadePrev(r);
				break;
			}
		}
	},
	imageRotateWatchHeight: function() {
		var a = document.getElementsByTagName('*'),
			l = a.length, c = 0, hasRotate = false, cn, cnl = 0, cni = 0;
		for(c = 0; c < l; c++) {
			if(a[c].className.indexOf('image-rotate') !== -1) {
				heightreq = a[c].offsetHeight;
				cn = a[c].childNodes;
				cnl = cn.length;
				for(cni = 0; cni < cnl; cni++) {
					if(cn[cni].offsetHeight > heightreq) {
						heightreq = cn[cni].offsetHeight;
					}
				}
				a[c].style.height = heightreq+'px';
			}
		}
	},
	imageRotateDoFadeThis: function(ce) {
		var el = ce.parentNode.attachEl,
			a = el.childNodes,
			l = a.length, c = 0, cur = false, nxt = false, o = 0, o2 = 0,
			fade = function() {
				if(o+.1 < 1) {
					o += .1;
					o2 += 10;
					nxt.style.opacity = o;
					nxt.style.filter = "alpha(opacity=" + (o2) + ")";
					setTimeout(fade, 10);
				} else {
					nxt.style.opacity = 1;
					nxt.style.filter = "alpha(opacity=100)";
					cur.style.opacity = 0;
					cur.style.filter = "alpha(opacity=0)";
					cur.style.zIndex = 1;
					cur.className = cur.className.replace('current', '');
					nxt.className += ' current';
					DP.setCurrentDot(el);
				}
			};
		for(c = 0; c < l; c++) {
			if(a[c].className.indexOf('current') !== -1) {
				cur = a[c];
				break;
			}
		}
		if(ce) {
			try {
				nxt = a[ce.getAttribute('data-child')];
			} catch(err){nxt = false;}
		}
		if(cur && nxt && cur != nxt) {
			cur.style.zIndex = (l-1);
			cur.style.opacity = 1;
			cur.style.filter = "alpha(opacity=100)";
			nxt.style.zIndex = (l);
			nxt.style.opacity = 0;
			nxt.style.filter = "alpha(opacity=0)";
			el.setAttribute('rotate', '0');
			fade();
		}
	},
	setCurrentDot: function(el) {
		var a = el.childNodes,
			l = a.length, c = 0, c2 = 0;
		if(el.dots) {
			for(c = 0; c < l; c++) {
				if(a[c].className.indexOf('current') !== -1) {
					break;
				}
			}
			a = el.dots.getElementsByTagName('a');
			l = a.length;
			for(c2 = 0; c2 < l; c2++) {
				if(c2 == c) {
					a[c2].className = 'current';
				} else {
					a[c2].className = '';
				}
			}
		}
	},
	imageRotateInit: function() {
		var a = document.getElementsByTagName('*'), cls = '',
			l = a.length, c = 0, hasRotate = false, ctrl = document.createElement('div'), tmp_c, tmp_l, tmp_str = '', dots = document.createElement('div');
		for(c = 0; c < l; c++) {
			if(a[c].className.indexOf('image-rotate') !== -1) {
				a[c].dorotate = 1;
				DP.imageRotateSet(a[c]);
				hasRotate = true;
				ctrl.innerHTML = '<a href="#" class="prev">&laquo;</a><a href="#" class="next">&raquo;</a>';
				ctrl.className = 'controls';
				if(a[c].className.indexOf('no-dots') === -1) {
					tmp_l = a[c].childNodes.length;
					dots.attachEl = a[c];
					dots.className = 'navdots';
					if(a[c].className.indexOf('no-arrows') === -1) {
						dots.className += ' arrowdots';
					}
					for(tmp_c = 0; tmp_c < tmp_l; tmp_c++) {
						cls = '';
						if(tmp_c == 0) {
							cls = 'current';
						}
						if(a[c].className.indexOf('no-arrows') !== -1) {
							tmp_str += '<a href="#" class="' + cls + '" data-child="' + tmp_c + '" onclick="DP.imageRotateDoFadeThis(this); return false;"><img src="/wp-content/themes/daxko/images/circle.png" alt="View Slide"></a>';
						} else {
							tmp_str += '<a href="#" class="' + cls + '" data-child="' + tmp_c + '" onclick="DP.imageRotateDoFadeThis(this); return false;"><img src="/wp-content/themes/daxko/images/circle_dark.png" alt="View Slide"></a>';
						}
					}
					dots.innerHTML = tmp_str;
					a[c].dots = dots;
					a[c].parentNode.insertBefore(dots, a[c].nextSibling);
				}
				if(a[c].className.indexOf('no-arrows') === -1) {
					a[c].parentNode.insertBefore(ctrl, a[c].nextSibling);
				}
				a[c].setAttribute('rotate', '1');
				DP.addEvent(ctrl, 'click', DP.imageRotateAdvance);
			}
		}
		if(hasRotate) {
			setInterval(DP.imageRotateDo, 5000);
		}
		setTimeout(DP.imageRotateWatchHeight, 10);
	},
	initContent: function() {
		var i = document.createElement('input');
		if(!('placeholder' in i)) {
			DP.initPlaceHolder();
		}
		DP.imageRotateInit();
		return;
	},
	init: function() {
		DP.addEvent(window, 'load', DP.initContent);
		return;
	}
};

DP.init();

