function changeStyle(id, style){
	document.getElementById(id).className = style;
}

// fading functions
var opac = Array();
function setOpacity(id, opacity) {
	document.getElementById(id).style.opacity = opacity;
	document.getElementById(id).style.filter = "alpha(opacity="+(opacity*100)+")";
	opac[id] = opacity;
}

function setImage(id) {
	var current_image = document.getElementById('current_image').innerHTML;
	if (id != current_image) {
		for (i=1; i<=10; i++) {
			setTimeout("setOpacity('slideshow_"+current_image+"', "+((10-i)/10)+")", i*30);
			setTimeout("setOpacity('slideshow_"+id+"', "+(i/10)+")", i*30);
		}
		document.getElementById('current_image').innerHTML = id;
	}
}

var fading = Array();
function fadeButton(id,restore) {
	var speed = 30;
	var timer = 0;
	if(undefined === window.fading[id]) {
		fading[id] = Array();
		setOpacity(id,1);
	} else {
		for (i=0;i<=10;i++) clearTimeout(fading[id][i]);
	}
	if (restore) {
		for(i = (opac[id]*10); i <= 10; i++) {
			fading[id][i]=setTimeout("setOpacity('" + id + "',"+(i/10)+")",(timer * speed));
			timer++;
		}
	} else {
		for(i = (opac[id]*10); i >= 0; i--) {
			fading[id][i]=setTimeout("setOpacity('" + id + "',"+(i/10)+")",(timer * speed));
			timer++;
		}
	}
}

function setPhoto(number_pic){
	document.cookie = 'number_pic='+number_pic;
}

function setloader(){
	document.cookie = 'loader=true';
}

var slideTotal;
var slideCounter = 0;
var slideIndex = 0;
var slideNextIndex = 1;
function slideOpacity(index, opacity, nextIndex, nextOpacity) {
	setOpacity('slideshow_'+index, opacity);
	setOpacity('slideshow_'+nextIndex, nextOpacity);
}

function slideshow(total) {
	slideTotal = total;
	setInterval("slide()", 60);
}

function slide() {
	if (slideCounter > 100) {
		slideCounter = 0;
		slideIndex = slideNextIndex;
		slideNextIndex = (slideNextIndex + 1) % slideTotal;
	} else if (slideCounter <= 10) {
		nextOpacity = slideCounter / 10;
		opacity = 1 - nextOpacity;
		setOpacity('slideshow_'+slideIndex, opacity);
		setOpacity('slideshow_'+slideNextIndex, nextOpacity);
		slideCounter++;
	} else {
		slideCounter++;
	}
}

// Ajax Post Form
// Property Search Functions
function xmlhttpPost(script, form, func, vars) {
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open('POST', script, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			window[func](self.xmlHttpReq.responseText);
		}
	}
	// Collect form variables to send
	var qstr = vars;
	if (undefined != document[form]) {
		f = document[form];
		for (i=0;i<f.length;i++) {
			qstr += '&'+f.elements[i].name+'='+f.elements[i].value;
		}
	}
	if (qstr.substring(0,1)=='&') qstr = qstr.substring(1);
	self.xmlHttpReq.send(qstr);
}
function enquiryQuery() {
	if (document.enquiry_form.name.value == '') {
		alert('Please enter your name');
	} else if (document.enquiry_form.email.value == '') {
		alert('Please enter your email address');
	} else if (document.enquiry_form.tel.value == '') {
		alert('Please enter your phone number');
	} else {

		$('#formbody').hide('slow');
		$('#waiting').show('slow');
		document.getElementById('enquiry_bt').removeAttribute('onclick');
		document.getElementById('enquiry_bt').innerHTML = 'THANK YOU - someone will be in touch as soon as possible';
		xmlhttpPost('/posten.php','enquiry_form','enquiryResult','');
	}
}

function enquiryResult(result){
	document.getElementById('enquiry_bt').innerHTML = '';
	document.getElementById('enquiry_bt').setAttribute('onclick',"enquiryQuery()");
	if ($.parseJSON(result).error==false) {
		$('#waiting').hide('slow');
		$('#message').show('slow');
	} else {
		var errormsg=$.parseJSON(result).msg;
		alert(errormsg);
	}
}

