jQuery(document).ready(
	function() {
		var anchors = document.links
		for (var i=0; i<anchors.length; i++) {
			var anchor = anchors[i];
			//anchor.setAttribute("HREF", "#");
			link = anchor.getAttribute("HREF");
			if(anchor.rel == "js") {
				anchor.onclick = popUp;
			}
			else if (link.substring(0, 4) == "http" && link.substring(0, 28) != "http://www.sunnysideup.co.nz") {
				anchor.target = "_blank";
				anchor.className = "outsideLink"
			}
		}

		jQuery(".hSection").hide();

		jQuery("h2").each(
			function() {
				var text = jQuery(this).text();
				jQuery(this).html('<a href="#">' + text + '</a>');
				jQuery(this).click(
					function() {
						jQuery(this).next().toggle();
						return false;
					}
				);
			}
		);
	}
);


function contentResize() {
	var el = document.getElementById("content");
	var OldWidth = (el.offsetWidth);
	if(OldWidth > 1024) {
		newContentWidth = 1004;
	}
	else if(OldWidth < 200) {
		newContentWidth = 200;
		var elImages = document.getElementById("randomImage");
		elImages.style.display = "none";
	}
	else {
		newContentWidth = 0;
	}
	if(newContentWidth) {
		el.style.width = newContentWidth + "px";
	}
}


function emailwriter(contact, email, host, subject) {
		document.write('<a href="' + 'mail' + 'to:' + email + '@' + host + '?subject=' + subject + '">' + contact + '</a>');
}


var imageShowArray = Array("0", "0", "0","0");
function showImage(imageNumber) {
	var el = document.getElementById("image" + imageNumber);
	var contentElement = document.getElementById("content");
	if(imageShowArray[imageNumber]) {
		contentElement.className = "faded";
		el.style.clip = 'rect(0 370px auto 0px)';//
		el.style.zIndex = "10";
		imageShowArray[imageNumber] = 0;
	}
	else {
		contentElement.className = "notFaded";
		el.style.clip = 'rect(0 370px 100px 270px)';
		el.style.zIndex = "1";
		imageShowArray[imageNumber] = 1;
	}
	return true;
}


function urlEncode(string) {
	var t = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++) {
		if(i > 0) {
			t += '-';
		}
		t += splitstring[i];
	}
	return escape(t);
}

function popUp() {
	var url = this.getAttribute("HREF");
	var win = null;
	var features = 'width=950,height=650';
	var name = "Pop-up window";
	win = window.open(url, name, features);
	return false;
}

function insertIframe() {
	var url = this.getAttribute("HREF");
	var iframeDiv = document.createElement("iframe");
	iframeDiv.location = url;
	iframeDiv.setAttribute('width',"500");
	iframeDiv.setAttribute('height',"500");
	this.appendChild(iframeDiv);
	return false;
}

function showMoreInfo(el) {
	if($(el).next().is(":hidden")) {
		$(el).next().slideDown();
	}
	else {
		$(el).next().slideUp();
	}
	return true;
}