// Redirect to arnoldclark.com //
var host = isDomain(location.host);
if (host)
	document.location = "http://www.arnoldclark.com"+location.pathname;

function isDomain(host){

	var tmp = host.split(".");

	if (tmp.length == 4){
		var isIP = true;
		for (var i=0;i<tmp.length;i++) {
			if (!isFinite(tmp[i]))
				isIP = false;
		}

		if (isIP) return false;
	}

	if (host == "arnoldclarkdrum.local" || host == "arnoldclark.local" || host == "localhost" || host == "www.arnoldclark.com" || host == "www.arnoldclarkdrum.com" || host == "arnoldclarkdrum.com")
		host = null;

	host = null;

	return host;
}
// Redirect Ends //

function getLox() {

	//var myValues = $('loc1').getCoordinates();

	//alert(myValues.left)

	for (var i=1;i<4;i++) {
		var ob = gebi("loc"+i);

		var posn =  findPos(ob);
		var coords = getObjCoords(ob)

		var rect = $('loc'+i).getCoordinates();

		//alert(rect.left);

		//alert(ob.clientLeft)


		var el = document.createElement("div");
		el.style.width = "20px";
		el.style.height = "20px";
		el.style.left = posn[0]+"px";
		el.style.top = posn[1]+"px";
		el.style.position = "absolute";
		el.style.zIndex = 10000000+i;
		el.style.background = "darkred";
		el.innerHTML = "&nbsp;";
		document.body.appendChild(el);


	}
}

// Method 1
function findPos(el) {
	var l = t = 0;
	if (el.offsetParent) {
		l = el.offsetLeft
		t = el.offsetTop
		while (el = el.offsetParent) {
			var x = el.offsetLeft;
			var y = el.offsetTop;
			if (ie7) { // move x coorinate to the left if the element or its sibling floats left.
				if (el.style.styleFloat == 'left' || el.currentStyle.styleFloat == 'left') {
					x = 0;
				}else if (el.previousSibling) {
					if (el.previousSibling.style.styleFloat == 'left' || el.previousSibling.currentStyle.styleFloat == 'left') {
						x -= el.previousSibling.offsetLeft;
					}

				}
			}
			l += x;
			t += y;
		}
	}
	return [l,t];
}

// Method 2

function Point(x, y) {
    this.x = x;
    this.y = y;
}

function getObjCoords(o) {
    var oX = 0;
    var oY = 0;
    if (o.offsetParent) {
        while (1) {
            oX+=o.offsetLeft;
            oY+=o.offsetTop;
                if (!o.offsetParent) {
                    break;
                }
            o=o.offsetParent;
        }
    } else if (o.x) {
        oX+=o.x;
        oY+=o.y;
    }
    return new Point(oX, oY);
}

var initialize = new Array();
function initPage(auto, width) {
	for (var i=0;i<initialize.length;i++) {
		try {
			eval(initialize[i]);
		}catch(E){
			//do nothing
		}
	}

	try {
		if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 6) {
			return;
		}else if (BrowserDetect.browser == 'Safari') {
			var s = document.styleSheets;
			var cssSheet = null;
			for (var i=0;i<s.length;i++) {
				if (contains(s[i].href, "/templates/")) {
					cssSheet = s[i];
					break;
				}
			}

			if (cssSheet) {
				var path = cssSheet.href.substring(0, cssSheet.href.lastIndexOf("/")+1)+"safari.css";
				var css = document.createElement("link");
				css.setAttribute("href", path);
				css.setAttribute("rel","styleSheet");
				css.setAttribute("type", "text/css");

				var head = document.getElementsByTagName("head")[0];
				head.appendChild(css);
			}
		}
	}catch(E){
		//no browser detect attached
	}

	if (document.getElementById) {
		fixColumns(true, false);
		fixColumns(auto, width);
	}
}

function fixColumns(auto, width) {
	var layout = document.getElementById("wf_Layout");

	if (!layout) return;

	var cols = new Array("left","main","right");
	var h = auto ? 0 : layout.offsetHeight+20;

	for (var i=0;i<cols.length;i++) {
		var col = document.getElementById("wf_"+cols[i]+"_column");
		if (col)
			setObH(col, h, auto);

		var buffer = document.getElementById("wf_"+cols[i]+"_column_edit_buffer") ? document.getElementById("wf_"+cols[i]+"_column_edit_buffer") : document.getElementById("wf_"+cols[i]+"_column_buffer");
		if (buffer) setObH(buffer, h, auto);
	}

	var buffer = document.getElementById("wf_main_column_buffer")
	if (buffer) {
		buffer.style.width = "auto";
		if (nn6 || (ie7 && width)) {
			buffer.style.maxWidth = (auto || !width) ? "auto" : buffer.offsetWidth+"px";
		}else
			buffer.style.width = (auto || !width) ? "auto" : buffer.offsetWidth+"px";
	}

	setObH(layout, layout.offsetHeight, auto);
}

function setObH(ob, h, auto) {
	if (nn6 || ie7) {
		ob.style.height = "auto";
		ob.style.minHeight = auto ? "0px" : h+"px";
	}else
		ob.style.height = auto ? "" : h+"px";

}
