// CAROUSEL IMAGES

function carousel(){

	var targ = $(".carousel");
	var mainImage = $(".carousel .carouselImg");
	
	var rand = Math.floor((Math.random())*3);
	
	var CS = "";
	
	switch (rand){
		case 0:
			CS = "nandos";
			break;
		case 1:
			CS = "abbey";
			break;
		case 2:
			CS = "clitterhouse";
			break;	
		default:
			CS = "nandos";
			break;
	}
	
	mainImage.attr("src","images/content/"+CS+"-1.jpg");
	mainImage.css({"display":"block"});
	
	$("#"+CS).css({"display":"block"});

	var ul = document.createElement("ul");
	ul.className="pic-nav";
	
	var nav1 = createNav("nav1","images/content/"+CS+"-1.jpg","1");
	var nav2 = createNav("nav2","images/content/"+CS+"-2.jpg","0");
	
	ul.appendChild(nav1);
	ul.appendChild(nav2);	
	
	if (CS == "clitterhouse") {
		var nav3;
	}
	else{
		var nav3 = createNav("nav3", "images/content/" + CS + "-3.jpg", "0");
		ul.appendChild(nav3);
	}
	

	
	
	targ.append(ul);
	
	var lis = $(".pic-nav li a");

	
	lis.bind("mouseover", function(){
		if($(this).attr("rel")!="on"){
			$(this).find("img").attr("src","images/bg/pic-nav-on.png");	
		}
	});
	
	lis.bind("mouseout", function(){
		if ($(this).attr("rel") != "on") {
			$(this).find("img").attr("src", "images/bg/pic-nav-off.png");
		}	
	});
	
	lis.bind("click", function(){
		lis.find("img").attr("src","images/bg/pic-nav-off.png");
		lis.attr("rel","off");
		$(this).find("img").attr("src","images/bg/pic-nav-on.png");	
		$(this).attr("rel","on");
		
		var newSrc = $(this).attr("href");
		
		mainImage.stop();
		mainImage.animate({"opacity":"0"},250,function(){
			mainImage.attr("src",newSrc);		
			mainImage.animate({"opacity":"1"},250);
		});
		
		
		return false;
	});
	
}


function createNav(id,src,sel){

	var li = document.createElement("li");
	var a = document.createElement("a");
	var img = document.createElement("img");
	
	li.id=id;
	a.href=src;
	if (sel == 0) {
		img.src = "images/bg/pic-nav-off.png";
		a.rel = "off";
	}
	else{
		img.src = "images/bg/pic-nav-on.png";
		a.rel = "on";
	}
	img.style.width="16px";
	img.style.height="16px";
	a.appendChild(img)
	li.appendChild(a);
	return li;
	
}


function chkForm(){
	
	var __form = $("#contact-form");

	__form.bind("submit",function(){
		
		var __submit = true;

		var __fName = $("#form-name");
		var __fEmail = $("#form-email");
		var __fQuery = $("#form-query");
		
		var __list = "";
		
		if(__fName.val()==""){
			__list += "<li>Name</li>";
			__submit = false;
		}
		
		if(__fEmail.val()==""){
			__list += "<li>Email</li>";
			__submit = false;
		}
		
		if(__fQuery.val()==""){
			__list += "<li>Query</li>";
			__submit = false;
		}	
		
		
		if (__submit == false) {
			
			var __errors = "<div class='errors'><h2>Error</h2><p>Please fill in the following fields:</p><ul>"+__list+"</ul></div>"
			$(".errors").remove();
			__form.find("legend").after($(__errors));

		}		
				
		return __submit;
		
	})
	
	
}

function testimonials(){
	
	var data = [
	"<blockquote><p>\"I am writing to thank you and your team for the effort you put into ensuring that the summer 2006 amalgamation works were complete on time. The new school is now established and the buildings are working well, particularly the staff and parents’ rooms.</p><p>Many thanks also for including the additional items which I requested at a very late date – notice boards, water heater, painting etc – and which you dealt with cheerfully and efficiently.</p><p>Your own staff and sub-contractors were unfailingly polite, helpful and good-humoured.\"</p></blockquote><cite>Catherine Milton <br />Head Teacher</cite>",
	"<blockquote><p>\"On behalf of the school community I would like to say how impressed we were with your staff who carried out this refurbishment. Doug and Dave carried out the work quietly, pleasantly and extremely efficiently and are a credit to your company. Also thank you to yourself because nothing we asked seem to be too much trouble.</p><p>We would have no hesitation at all in calling your company back to carry out future refurbishment works.\"</p></blockquote><cite>Mrs Eileen Bhavssar <br />Head Teacher</cite>",
	"<blockquote><p>\"I would just like to put on record our thanks to you and your staff who have worked so well in our school in these last few months. We are getting lots of positive comments from staff, parents and pupils when they see all the areas that have been recently refurbished.</p><p>The standard of workmanship is consistently superb. All of your employess and sub contractors are extremely courteous and enthusiastic – nothing seems to be too much trouble – and they work quietly, efficiently and steadfastly. Further, we have found that suggestions made (notably by john, Tony and Gary) have been helpful in ensuring that we achieved the best results.</p><p>We look forward to working with you in the future.\"</p></blockquote><cite>Jane Canavan <br />Business Manager</cite>",
	"<blockquote><p>\"The directors have asked me to write to you after I had told them how well your two electricians, Scott and Dan had got on with the work at Collard Court.</p><p>Scott and Dan were always considerate of our elderly residents, they were clean and tidy during the works, hard working and courteous at all times. Scott would make a point liasing with the warden Mary so that she was aware if one or both of the electricians would be working within the building.</p><p>We are all very pleased with the work undertaken, it was complete with the minimum of fuss, disruption and damage to decoration. Please thank Scott and Dan on our behalf; they are a credit to your company.\"</p></blockquote><cite>Liz Abbott <br />Clerk to the Directors</cite>",
	"<blockquote><p>\"We are so thrilled at how the re-modelling has transformed out school! Everyone; children, staff, governors, parents and visitors are very impressed at the level of workmanship evident in the carpentry, glazing, ironwork, playground sheds, carpeting and security fittings that were completed during the Easter holidays. It is a wonder you project managed it to be completed during such a tight time frame.</p><p>We are so pleased with all aspects ofthe work your firm has completed, I have informed our architects that for our next Premises Development I would like your firm to build for the project. Everyone was involved from the befinning, the school was able to specify our needs and your informed opinion of what would work better, helped us reach an excellent conclusion.\"</p></blockquote><cite>Dee Mansi <br />Head Teacher</cite>",
	"<blockquote><p>\"Kirkman and Jourdain have undertaken several large building projects for our school in the last year. They came to us highly recommended and we were not disappointed! The quality of workmanship and professionalism has been outstanding.</p><p>We have been particularly impressed with Phil Haywood, who from the outset and initial meeting took on board our needs and has been a pleasure to work with throughout each project.</p><p>The friendliness of his staff and professional nature they conduct themselves around our school site has been outstanding. The quality of work provided has been outstanding and the timescale in which the work was completed was all within the expected timescale.</p><p>Having builders and contractors on site always has the potential to be added pressure on a school. This has certainly not been the case working with Kirkman and Jourdain.\"</p></blockquote><cite>Jo Djora <br />Head Teacher</cite>"
	]


	var targ = $("#quote");
	var rand = Math.floor((Math.random())*6);
	targ.empty().append(data[rand]);


}

function caseStudyJump(){
	
	var sel = $("#hp-case-studies select");
	
	sel.val(0);
	sel.bind("change",function(){
		document.location.href= $(this).val();	
	})	

}


$(document).ready(function(){

	if($(".carousel").length>0){
		
		carousel();
		
	}
	
	if($("#contact-form").length>0){
		
		chkForm();
		
	}	
	
	if($("#quote").length>0){
		
		testimonials();
		
	}
	
	if($("#quote").length>0){
		
		testimonials();
		
	}
	
	if($("#hp-case-studies").length>0){
		
		caseStudyJump();
		
	}
	
	

});

