 var wu_category_pager = new function() {
  var interval = null;
  var lastlocation = window.location.toString();
  var lastiframe = '';
  var modrewrite = false;
  var ie = (window.ActiveXObject);
  var iframe = null;
  var working = '';
  this.ajaxify = function(href) {
   if (href.indexOf('ajax=true') < 0) {
    if (href.indexOf('?') > -1) href += '&ajax=true'; else href += '?ajax=true';
   };
   return href;   
  }
  this.periodical = function() {
   var same = true;
   var iframedifference = false;
   var currentlocation = window.location.toString();
   if (ie && iframe && (lastiframe != '')) {
    same = (iframe.contentWindow.document.body.innerText == lastiframe);
    iframedifference = !same;
   };
   if (same) same = (currentlocation == lastlocation);
   if (same) return;
   lastlocation = currentlocation;
   if (ie && iframe && iframedifference) var href = iframe.contentWindow.document.body.innerText; else var href = currentlocation;
   if (modrewrite) href = href.replace('#', '/'); else href = href.replace('#', '&');
   href = wu_category_pager.ajaxify(href);
   if (href.indexOf('http://') < 0) return;
   $A($('wu_contentpadder').getElements('.wu_control')).each(function(p) {
    p.setHTML(working);
   });   
   new Ajax(href, {method: 'get', onComplete: wu_category_pager.show}).request();
   if (ie) {
    try {
    	var doc = iframe.contentWindow.document;
				 doc.open();
				 doc.write('<html><body>' + href + '</body></html>');
				 doc.close();
			 } catch(e) {};
			 lastiframe = href;
   };
  }
  this.initanc = function(anc) {
   var href = $(anc).href;
   if (href.indexOf('category/category.php?') > -1) href = href.replace('&', '#');
   else if (anc.innerHTML != '1') {
    modrewrite = true;
    href = href.split('/');
    var last = href.pop();
    href = href.join('/') + '#' + last;
   };
   anc.href = href;
   anc.name = href.substring(href.indexOf('#') + 1);
   anc.addEvent('click', wu_category_pager.load);
  }
  this.setworking = function(str) { working = str; }
  this.init = function() {
   if (ie && (iframe == null)) {
    iframe = new Element('iframe', {src: 'common/blank.html',	styles: 'visibility: hidden;'}).injectInside(document.body);
    var href = wu_category_pager.ajaxify(window.location.toString());
    try {
    	var doc = iframe.contentWindow.document;
			  doc.open();
			  doc.write('<html><body>' + href + '</body></html>');
			  doc.close();
			 } catch(e) {};
   };
   if (interval == null) interval = (wu_category_pager.periodical).periodical(100, null);
   $A($('wu_contentpadder').getElements('.wu_control')).each(function(p) {
    $A($(p).getElementsByTagName('a')).each(wu_category_pager.initanc);
   });
  }
  this.load = function(e) {
   $A($('wu_contentpadder').getElements('.wu_control')).each(function(p) {
    p.setHTML(working);
   });    
  }
  this.show = function(text) {
   $('wu_ajax_category_swap').setHTML(text);
   wu_category_pager.init();
  }
 }
