function popup_window(popup)
	{
	if (!popup.href) { return false; }
	popup.name = popup.name ? popup.name : 'anonymous';
	popup.string = '';
	popup.attributes = ['height','width'];
	if ((screen.height < popup.height) || (screen.width < popup.width))
		{
		popup.attributes[2] = 'scrollbars';
		popup.scrollbars = 1;
		popup.width += 16;
		if (popup.width > screen.width) { popup.width = screen.width; }
		popup.height += 16;
		if (popup.height > screen.height) { popup.height = screen.height; }
		}
	for (prop in popup.attributes)
		{
		var actual_prop = popup.attributes[prop];
		if (popup[actual_prop] == undefined) { next; }
		if (popup.string != '') { popup.string += ","; }
		popup.string += actual_prop + "=" + popup[actual_prop];
		}
	var popup_window = window.open(popup.href, popup.name, popup.string);
	if (window.focus) { popup_window.focus(); }
	return popup_window;
	}

function popup_image_fullsize(url, winname, width, height)
	{

	popup_window({href:url, name:winname, width:width, height:height});
	return false;
	}


function pause(t)
	{
	var start = new Date();
	while (1)
		{
		var now = new Date();
		var elapsed = now - start;
		if( elapsed > t )
			{
			break;
			}
		}
	}

// function XMLHttpRequestObject() {}

//XMLHttpRequestObject.prototype.blomp = true;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
function XMLHttpRequest() {}
try
	{
	XMLHttpRequest.prototype = new ActiveXObject("Msxml2.XMLHTTP");
	}
catch (e)
	{
	try
		{
		XMLHttpRequest.prototype = new ActiveXObject("Microsoft.XMLHTTP");
		}
	catch (E)
		{
		XMLHttpRequest.prototype.blomp = true;
		}
	}
@end @*/
//if (!xmlhttp && typeof XMLHttpRequest!='undefined')
//	{
//	XMLHttpRequestObject.prototype = new XMLHttpRequest();
//	}

function zXMLHttpRequestObject()
	{
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try
		{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch (e)
		{
		try
			{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		catch (E)
			{
			xmlhttp = false;
			}
		}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
		{
		xmlhttp = new XMLHttpRequest();
		}
	return xmlhttp;
	}

//var xmlhttp = zXMLHttpRequestObject() ? true : false;

function RemoteRequest(request_obj)
	{
	if (!request_obj.url) { return false; }
	if (!request_obj.charset) { request_obj.charset = "utf-8"; }
	if (!request_obj.method) { request_obj.method = 'post'; }
	if (request_obj.method == 'post') { request_obj.urlencoded = true; }
	if (!request_obj.query) { request_obj.query = ''; }
	if (request_obj.asynchronous != false) { request_obj.asynchronous = true; }
	if (request_obj.args || request_obj.query)
		{
		request_obj.query = GetQueryString({args:request_obj.args, query:request_obj.query});
		}
	if (request_obj.method == 'get')
		{
		if (request_obj.query)
			{
			request_obj.query = '?'+request_obj.query;
			}
		request_obj.url += request_obj.query;
		request_obj.query = null;
		}
	if (!request_obj.type) { request_obj.type = 'responseText'; }
	if (!request_obj.error) { request_obj.error = function (error_message) { alert(error_message); } }
	
	var xmlhttp = XMLHttpRequestObject();
	xmlhttp.open(request_obj.method, request_obj.url, request_obj.asynchronous);

	if (request_obj.urlencoded)
		{
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset="+request_obj.charset);
		}

	if (request_obj.asynchronous)
		{
		xmlhttp.onreadystatechange=function()
			{
			if (xmlhttp.readyState==4)
				{
				if (xmlhttp.status != 200)
					{
					alert('status = '+xmlhttp.status);
					request_obj.error(xmlhttp[request_obj.type]);
					return false;
					}
				if (request_obj.callback)
					{
					request_obj.callback(xmlhttp[request_obj.type]);
					}
				else
					{
					alert('no callback - here goes\n'+xmlhttp[request_obj.type]);
					}
				}
			}
		}
	xmlhttp.send(request_obj.query);

	if (!request_obj.asynchronous) { return xmlhttp[request_obj.type]; }
	return false;
	}

function GetQueryString(request_obj)
	{
	for (var prop in request_obj.args)
		{
		request_obj.args[prop] = request_obj.args[prop].replace(/&/g, '%26');
		if (request_obj.method == 'get')
			{
			if (request_obj.args[prop] != escape(request_obj.args[prop]))
				{
				try
					{
					request_obj.args[prop] = encodeURIComponent(request_obj.args[prop]);
					}
				catch(e)
					{
					HandleEncodingError(request_obj.args[prop])
					}
				}
			}
		request_obj.query += '&'+prop+'='+request_obj.args[prop];
		}
	if (request_obj.query)
		{
		request_obj.query = request_obj.query.replace(/^(\?|&)/,'');
		}
	return request_obj.query;
	}

function HandleEncodingError(prop)
	{
	alert(prop + 'contains characters that may not be sent correctly');
	}

function CreateAPI()
	{
	}
var API = new CreateAPI();

CreateAPI.prototype.nullFunc = function() { alert('do nothing') };
//CreateAPI.prototype.send = xmlhttp ? function() { alert('send') } : CreateAPI.prototype.nullFunc;



/**
 * RUZEE.ShadedBorder 0.1
 * (c) 2006 Steffen Rusitschka
 *
 * RUZEE.ShadedBorder is freely distributable under the terms of an MIT-style license.
 * For details, see http://www.ruzee.com/
 */

var RUZEE = window.RUZEE || {};

RUZEE.ShadedBorder = {
register: {},
style_register: {},
create: function(opts) {
// ------- AR ADDITION
  var key = '';
  for (var prop in opts)
  	{
  	key += prop + ':' + opts[prop];
  	}
  if (this.register[key]) { return this.register[key]; }
// ------- AR ADDITION
  var isie = /msie/i.test(navigator.userAgent) && !window.opera;
  function sty(el, h) {
    for(k in h) {
      if (/ie_/.test(k)) {
        if (isie) el.style[k.substr(3)]=h[k];
      } else el.style[k]=h[k];
    }
  }
  function crdiv(h) {
    var el=document.createElement("samp");
    el.className = "sb-gen";
    sty(el, h);
    return el;
  }
  function op(v) {
    v = v<0 ? 0 : v;
    v = v>0.99999 ? 0.99999 : v;
    if (isie) {
      return " filter:alpha(opacity=" + (v*100) + ");";
    } else {
      return " opacity:" + v + ';';
    }
  }

  var sr = opts.shadow || 0;
  var r = opts.corner || 0;
  var bor = 0;
  var bow = opts.border || 0;
  var shadow = sr != 0;
  var lw = r > sr ? r : sr;
  var rw = lw;
  var th = lw;
  var bh = lw;
  if (bow > 0) {
    bor = r;
    r = r - bow;
  }
  var cx = r != 0 && shadow ? Math.round(lw/3) : 0;
  var cy = cx;
  var cs = Math.round(cx/2);
  var iclass = r > 0 ? "sb-inner" : "sb-shadow";
  var sclass = "sb-shadow";
  var bclass = "sb-border";
  var edges = opts.edges || "trlb";
  if (!/t/i.test(edges)) th=0;
  if (!/b/i.test(edges)) bh=0;
  if (!/l/i.test(edges)) lw=0;
  if (!/r/i.test(edges)) rw=0;

  var p = { position:"absolute", left:"0", top:"0", width:lw + "px", height:th + "px", 
            ie_fontSize:"1px", overflow:"hidden" }; var tl = crdiv(p);
  delete p.left; p.right="0"; p.width=rw + "px"; var tr = crdiv(p);
  delete p.top; p.bottom="0"; p.height=bh + "px"; var br = crdiv(p);
  delete p.right; p.left="0"; p.width=lw + "px"; var bl = crdiv(p);

  var tw = crdiv({ position:"absolute", width:"100%", height:th + "px", ie_fontSize:"1px",
                   top:"0", left:"0", overflow:"hidden" });
  var t = crdiv({ position:"relative", height:th + "px", ie_fontSize:"1px", marginLeft:lw + "px",
                  marginRight:rw + "px", overflow:"hidden" });
  tw.appendChild(t);

  var bw = crdiv({ position:"absolute", left:"0", bottom:"0", width:"100%", height:bh + "px", 
                   ie_fontSize:"1px", overflow:"hidden" });
                   
  var b = crdiv({ position:"relative", height:bh + "px", ie_fontSize:"1px", marginLeft:lw + "px",
                  marginRight:rw + "px", overflow:"hidden" });
                  
  bw.appendChild(b);

  var mw = crdiv({ position:"absolute", top:(-bh)+"px", left:"0", width:"100%", height:"100%",
                   overflow:"hidden", ie_fontSize:"1px" });

  function corner(el,t,l) {
    var w = l ? lw : rw;
    var h = t ? th : bh;
    var s = t ? cs : -cs;
    var dsb = []; var dsi = []; var dss = [];
    
    var xp=0; var xd=1; if (l) { xp=w-1; xd=-1; }
    for (var x=0; x<w; ++x) {
      var yp=0; var yd=1; if (t) { yp=h-1; yd=-1; }
      for (var y=0; y<h; ++y) {
        var div = '<div style="position:absolute; top:' + yp + 'px; left:' + xp + 'px; ' +
                  'width:1px; height:1px; overflow:hidden;';

        var xc = x - cx; var yc = y - cy - s;
        var d = Math.sqrt(xc*xc+yc*yc);
        var doShadow = false;

        if (r > 0) {
          // draw border
          if (xc < 0 && yc < bor && yc >= r || yc < 0 && xc < bor && xc >= r) {
            dsb.push(div + '" class="' + bclass + '"></div>');
          } else
          if (d<bor && d>=r-1 && xc>=0 && yc>=0) {
            var dd = div;
            if (d>=bor-1) {
              dd += op(bor-d);
              doShadow = true;
            }
            dsb.push(dd + '" class="' + bclass + '"></div>');
          }
          
          // draw inner
          var dd = div + ' z-index:2;';
          if (xc < 0 && yc < r || yc < 0 && xc < r) {
            dsi.push(dd + '" class="' + iclass + '"></div>');
          } else
          if (d<r && xc>=0 && yc>=0) {
            if (d>=r-1) {
              dd += op(r-d);
              doShadow = true;
            }
            dsi.push(dd + '" class="' + iclass + '"></div>');
          } else doShadow = true;
        } else doShadow = true;
        
        // draw shadow
        if (sr > 0 && doShadow) {
          d = Math.sqrt(x*x+y*y);
          if (d<sr) {
            dss.push(div + ' z-index:0; ' + op(1-(d/sr)) + '" class="' + sclass + '"></div>');
          }
        }
        yp += yd;
      }
      xp += xd;
    }
    el.innerHTML = dss.concat(dsb.concat(dsi)).join('');
  }
  
  function mid(mw) {
    var ds = [];

    ds.push('<div style="position:relative; top:' + (th+bh) + 'px;' +
            ' height:10000px; margin-left:' + (lw-r-cx) + 'px;' +
            ' margin-right:' + (rw-r-cx) + 'px; overflow:hidden;"' +
            ' class="' + iclass + '"></div>');

    var dd = '<div style="position:absolute; width:1px;' +
        ' top:' + (th+bh) + 'px; height:10000px;';
    for (var x=0; x<lw-r-cx; ++x) {
      ds.push(dd + ' left:' + x + 'px;' + op((x+1.0)/lw) + 
          '" class="' + sclass + '"></div>');
    }

    for (var x=0; x<rw-r-cx; ++x) {
      ds.push(dd + ' right:' + x + 'px;' + op((x+1.0)/rw) + 
          '" class="' + sclass + '"></div>');
    }

    if (bow > 0) {
      var su = ' width:' + bow + 'px;' + '" class="' + bclass + '"></div>';
      ds.push(dd + ' left:' + (lw-bor-cx) + 'px;' + su);
      ds.push(dd + ' right:' + (rw-bor-cx) + 'px;' + su);
    }

    mw.innerHTML = ds.join('');
  }

  function tb(el, t) {
    var ds = [];
    var h = t ? th : bh;
    var dd = '<div style="height:1px; overflow:hidden; position:absolute;' +
        ' width:100%; left:0px; ';
    var s = t ? cs : -cs;
    for (var y=0; y<h-s-cy-r; ++y) {
      ds.push(dd + (t ? 'top:' : 'bottom:') + y + 'px;' + op((y+1)*1.0/h) + 
          '" class="' + sclass + '"></div>');
    }
    if (y >= bow) {
      ds.push(dd + (t ? 'top:' : 'bottom:') + (y - bow) + 'px;' +
          ' height:' + bow + 'px;" class="' + bclass + '"></div>');
    }

    ds.push(dd + (t ? 'top:' : 'bottom:') + y + 'px;' +
        ' height:' + (r+cy+s) + 'px;" class="' + iclass + '"></div>');

    el.innerHTML = ds.join('');
  }

  corner(tl, true, true); corner(tr, true, false);
  corner(bl, false, true); corner(br, false, false);
  mid(mw); tb(t, true); tb(b, false);

  // AR - now assign return object to a var
  // AR - this let's us stash it for repeated use  // AR - and add in getStyle
  var return_obj = {
    style_register: RUZEE.ShadedBorder.style_register,
    getStyle: function (el, prop) {
       if (document.defaultView && document.defaultView.getComputedStyle) {
          return document.defaultView.getComputedStyle(el, null)[prop];
          } else if (el.currentStyle) {
    return el.currentStyle[prop];
    } else {
    return el.style[prop];
        }
    },
    render: function(el) {
      if (typeof el == 'string') el = document.getElementById(el);
      if (!el) { return; }
      if (!el.tagName && el.length != undefined) {
        for (var i=0; i<el.length; ++i) this.render(el[i]);
        return;
      }
      // AR - Get name or tag for style tweaks
      el.className += ' sb';
      var style_obj = {};
      var style_name = {};
      style_obj['background-color'] = this.getStyle(el, 'backgroundColor').replace(/transparent/, '');
      style_name['background-color'] = style_obj['background-color'].replace(/[ ()]/g, '').replace(/,/g, '-');
      style_name['background-color'] = style_name['background-color'].replace(/#/g, '');
      
      var elclass = '';
      for (var prop in style_name)
          {
          if (!style_obj[prop])
             {
             delete style_obj[prop];
             continue;
             }
          elclass += prop + '_' + style_name[prop];
          }
      if (elclass)
         {
         el.className += ' '+elclass;
         if (!this.style_register[elclass])
             {
             var style_map = {};
             style_map['background-color'] = 'sb-inner';
             // create style
             var el_style = '';
             el_style += 'background-color: transparent !important;\n';
             addCSSRule('.'+elclass, el_style);

             for (var prop in style_obj)
                 {
                 var el_prop_class = '.'+ elclass + ' .' + style_map[prop]
                 var el_prop_style = '';
                 el_prop_style += prop + ':' + style_obj[prop] + ';\n';
                 addCSSRule(el_prop_class, el_prop_style);
                 }
             this.style_register[elclass] = true;
             }
         }      
      // AR End styel tweaks
      
      // remove generated children
      var node = el.firstChild;
      while (node) {
        var nextNode = node.nextSibling;
        if (node.nodeType == 1 && node.className == 'sb-gen')
          el.removeChild(node);
        node = nextNode;
      }

      var iel = el.firstChild;

      var twc = tw.cloneNode(true);
      var mwc = mw.cloneNode(true);
      var bwc = bw.cloneNode(true);
      
      el.insertBefore(tl.cloneNode(true), iel); el.insertBefore(tr.cloneNode(true), iel);
      el.insertBefore(bl.cloneNode(true), iel); el.insertBefore(br.cloneNode(true), iel);
      el.insertBefore(twc, iel); el.insertBefore(mwc, iel);
      el.insertBefore(bwc, iel);

      if (isie) {
        function resize() {
          twc.style.width = bwc.style.width = mwc.style.width = el.offsetWidth + "px";
          mwc.firstChild.style.height = el.offsetHeight + "px";
        }
        el.onresize=resize;
        resize();
      }
    }
  };
  // ------- AR ADDITION
  this.register[key] = return_obj;
  return return_obj;
  // ------- AR ADDITION
}
};

// add our styles to the document
// elements without background colour will not be cornered!
document.write(
  '<style type="text/css" id="RUZEE-sb">' +
  'samp { display: block; }' +
  '.sb, .sbi, .sb *, .sbi * { position:relative; z-index:1; }' +
  '* html .sb, * html .sb *, * html .sbi, * html .sbi * { zoom:1; }' +
  '.sbi { display:inline-block; }' +
  '</style>'
);


function addCSSRule (selectorText, declarations)
	{
	var styleSheet;
	if (document.styleSheets)
		{
		if (document.styleSheets.length === 0)
			{
			var styleElement;
			if (document.createElement && (styleElement =
			document.createElement('style')))
				{
				styleElement.type = 'text/css';
				document.getElementsByTagName('head')[0].appendChild(styleElement);
				styleSheet = styleElement.sheet;
				}
			}
		if (document.styleSheets.length > 0)
			{
			styleSheet = document.styleSheets[document.styleSheets.length - 1];
			if (styleSheet.insertRule)
				{
				styleSheet.insertRule(
				selectorText + ' { ' + declarations + ' }',
				styleSheet.cssRules.length
				);
				}
			else if (styleSheet.addRule)
				{
				styleSheet.addRule(selectorText, declarations);
				}
			}
		}
	}

window.onload = function()
	{
	if (!document.all && [document.body].toString() == '[object HTMLBodyElement]' && navigator.userAgent.match(/Mac/) != null)
		{
		document.getElementsByTagName('html')[0].className = 'mac-gecko';
		}
	insertCorners('site_logo', 'blr');
	itemCorners();
	insertCorners('footer');
	insertCorners('navigation_browse');
	insertCorners('galleries');
	insertCorners('browse');
	insertCorners('sub_categories');
	insertCorners('viewed');
	insertCorners('advanced_search');
	insertCorners('item');
	insertCorners('profile_body');
	insertCorners('shopcart-contents');
	insertCorners('category_index');
	insertCorners('featured');
	insertCorners('announcements_shim', 'tlr');
	insertCorners('container');
	insertCorners('wrapper');
	h1Corners();
	formCorners();
	document.body.className += ' sb-corners';
	}



function insertCorners(element, edges, img)
	{
	if (Function.toString() == '(Internal Function)')
		{
		return;
		}
	//if (typeof element == 'string') { element = document.getElementById(element); }
	if (!element) { return; }
	if (img)
		{
		if (document.all && (document.all.toString() == '[object]') && !document.XMLHttpRequest)
			{
			img = img.replace(/png$/, 'gif');
			}
		var parsed_edges = ['tl', 'tr'];
		for (var i = 0; i < parsed_edges.length; i++)
			{
			var corner = parsed_edges[i];
			var cornerimg = document.createElement('img');
			var imgsrc = img.replace(/#POS#/, corner);
			cornerimg.src = imgsrc;
			cornerimg.className = 'rounded_'+corner;
			element.appendChild(cornerimg);
			}
		}
	else
		{
		var cornerobj = { corner: 8 };
		if (edges) { cornerobj.edges = edges; }
		var corner = RUZEE.ShadedBorder.create(cornerobj);
		corner.render(element);
		return;
		}
	//element.innerHTML = '<div class="rounded_tl"></div><div class="rounded_tr"></div><div class="rounded_bl"></div><div class="rounded_br"></div>' + element.innerHTML;
	}

function itemCorners()
	{
	var main_content = document.getElementById('main_content');
	var item_list = main_content.getElementsByTagName('ul');
	if (!item_list[0]) { return; }
	item_list = item_list[0];
	item_list = item_list.getElementsByTagName('li');
	for (var i = 0; i < item_list.length; i++)
		{
		if (item_list[i].className == 'item')
			{
			insertCorners(item_list[i]);
			}
		}
	}
function h1Corners()
	{
	var h1 = document.getElementsByTagName('h1')[0];
	if (!h1) { return; }
	h1.innerHTML = '<span>' + h1.innerHTML + '</span>';
	if (document.getElementById('item')) { return; }
	var img = null;
	if (document.getElementById('profile_body') || document.getElementById('container'))
		{
		img = 'http://www.antiquities.co.uk/images/rounded_#POS#.png';
		}
	insertCorners(h1, '', img);
	}
function imageCorners()
	{
	for (var i = 1; i < 11; i++)
		{
		insertCorners('image-'+i);
		}
	}
function featuredCorners()
	{
	insertCorners('feat-1');
	insertCorners('feat-2');
	//var featured = document.getElementById('featured');
	//var item_list = featured.getElementsByTagName('div');
	//if (!item_list[0]) { return; };
	//for (var i = 0; i < item_list.length; i++)
	//	{
	//	insertCorners(item_list[i]);
	//	}
	}
function formCorners()
	{
	var site_content = document.getElementById('site_content');
	var the_form = site_content.getElementsByTagName('form');
	if (the_form)
		{
		the_form = the_form[0];
		insertCorners(the_form);
		}
	}
