// $Id: client.js 872 2009-05-17 21:53:05Z fedot $
function noop(){}
(function(){
	var o = {
		host: 'http://dev.wbeez.com',
		api: '/client/view/bf79c3220e57faff487b810215b78c17',
		re : /\.(gif|jpg|jpeg|png|tif|tiff|tga|bmp)$/i
	}
	function h(f, s, a){
		var s = s || document;
		var a = a || [];
		return function(){
			if (arguments.length){
				for(var i=0;i<arguments.length;i++)
					a.push(arguments[i]);
			}
			return f.apply(s,a);
		}
	}
	
	function init(){
		var f = document.createElement('form'), s = document.createElement('input'), l = document.getElementsByTagName('a'), i=0;
		//f.name = "_exo";
		f.setAttribute('method', 'POST');
		f.style.display = 'none';
		s.type = 'hidden';
		s.name = 'source';
		f.appendChild(s);
		o.f = f;
		o.s = s;
		document.body.appendChild(f);
		for (i=0;i<l.length;i++){
			if (l[i].getElementsByTagName('img').length==1){
				// We found it ;)
				pl(l[i]);
			}
		}
	}
	
	function pl(l){
		var n = l.href;
		if (typeof l.onclick!='undefined'){
			var cl = l.getAttribute('onclick') || '';
			//_clog(n==document.location.href+'#',cl ,n, document.location.href);
			if ( cl == 'return hs.expand(this)'){
				//_clog('matched expand');
				l.onclick = '';
			}
			if (n==document.location.href+'#'){
				if (/^ShowBild/.test(cl)){
					n = cl.replace(/.+'(.+)'.+/,'$1');
					l.onclick = '';
					se(l, 'click', h(ox, l, [n]));
				}
			}
		}
		if (o.re.test(n)){
			l.setAttribute('data-href', n);
			l.href = 'javascript:noop()';
			se(l, 'click', h(ox, l, [n]));
		}
		
	}
	
	function ox(source, evt){
		//o.s.value = source;
		o.f.setAttribute('target', uid());
		interval = 1;
		if (/blogspot.com/.test(source)){
			o.f.setAttribute('action', source);
			o.f.submit();
			source = source.replace(/(\/s\d+)-h\//i,'$1/');
			//o.s.value = source;
			interval = 1000;
		}
		
		o.s.value = source;
		window.setTimeout(function(){
			o.f.setAttribute('action', o.host+o.api);
			o.f.submit();
		},interval);
		st(evt);
		return false;
	}
	function uid(){
		return '_exo'+uid.id++;
	}
	uid.id = (new Date().getTime());
	/**
	 * Some core functions
	 */
	
	function se(l,e,f){
		var c = h(f,l);
		if (l.addEventListener){
			l.addEventListener(e, c, false);
			return true;
		} else if (l.attachEvent) return l.attachEvent("on"+e, c);
	}
	
	function st(e){
	  if (!e) var e = window.event;
	  e.cancelBubble = true;
	  if (e.stopPropagation) e.stopPropagation();
	}
	
	/**
	 * Loading client
	 */
	if (typeof window.onload == "function"){
		oldload = window.onload;
		window.onload = function(){
			init();
			oldload.apply(window);
			window.onload = oldload;
		}
	} else {
		window.onload = init;
	}
})();