var site = null;
$(function() { site = new Horne(); });

function Horne() {
	this.activePage = null;
	this.setupBehaviour();
}

Horne.prototype.setupBehaviour = function() {
	
	$('#invite-text').hide();
	
	$('#banner-main-horne').click(function() {
    	$('#container, #footer').fadeOut(function() {
      		window.location = 'http://www.horne.co.uk/';
    	});
  	});
  
	var me = this;
  $('#banner-main-optitherm').click(function() { me.showContent(); });
  $('#horne-logo').click(function() { me.hideContent(); });
	$('#nav a.actuator').click(function() { $('#awards-logo').fadeOut(); me.toPage(this.id.replace(/-actuator$/, '')); });
	$('#nav a#awards-actuator').click(function() { $('#awards-logo').fadeIn(); });
	
	$('#send').click(function() {
		$('#contact-us').ajaxSubmit({dataType: 'script'});
	});
	
	$(window).load(function() {
		setTimeout(function() {
			$('#banner-main-optitherm').click();
		}, 1000);
	});
	
	
}

Horne.prototype.showContent = function() {
	var me = this;
	$('#buttons').slideUp(1000, function() {
		$('#content').slideDown(1000, function() {
			if (!me.activePage) me.toPage(me.firstPageId());
		})
	});
}

Horne.prototype.hideContent = function() {
	$('#content').slideUp(1000, function() {
    	$('#buttons').slideDown(1000);
  	});
}

Horne.prototype.toPage = function(p) {
	
	if (this.activePage == p) return;
	
	$('#nav a').removeClass('selected');
	$('#' + p + '-actuator').addClass('selected');
	
	$('#content .active').fadeOut().removeClass('active');
  	//if (this.activePage == 'invite-to-iheem') $('#invite-text').fadeOut();

	$('#' + p).fadeIn().addClass('active');
	//if (p == 'invite-to-iheem') $('#invite-text').fadeIn();
	
	this.activePage = p;
	
}

Horne.prototype.firstPageId = function() {
	return $('#content .inner').get(0).id;
}

Horne.prototype.formErrors = function(fields) {
	$('#contact-us *').removeClass('field-error');
	for (var i = 0; i < fields.length; i++) {
		$('#contact-us [@name=' + fields[i] + ']').addClass('field-error');
	}
}

Horne.prototype.formSuccess = function() {
	$('#contact-us').html('<h2>Thank you</h2>');
}