
//Preloading Images for Our Work Page
if (location.pathname == "/our-work.html") {
	var imagePath = "/images/ourwork/";
	
	newImage30 = new Image(550, 500);
	newImage30.src = imagePath + "cnnmoney-yahoo1.jpg";
	newImage31 = new Image(550, 500);
	newImage31.src = imagePath + "cnnmoney-yahoo2.jpg";
	newImage32 = new Image(550, 500);
	newImage32.src = imagePath + "cnnmoney-yahoo3.jpg";

	newImage4 = new Image(550, 456);
	newImage4.src = imagePath + "spi1.jpg";
	newImage5 = new Image(550, 456);
	newImage5.src = imagePath + "spi2.jpg";
	newImage6 = new Image(550, 456);
	newImage6.src = imagePath + "spi3.jpg";
	
	newImage27 = new Image(550, 450);
	newImage27.src = imagePath + "cnnmoney1.jpg";
	newImage28 = new Image(550, 450);
	newImage28.src = imagePath + "cnnmoney2.jpg";
	newImage29 = new Image(550, 450);
	newImage29.src = imagePath + "cnnmoney3.jpg";
	
	newImage20 = new Image(550, 454);
	newImage20.src = imagePath + "sundaymass1.jpg";
	newImage21 = new Image(550, 454);
	newImage21.src = imagePath + "sundaymass2.jpg";
	newImage22 = new Image(550, 454);
	newImage22.src = imagePath + "sundaymass3.jpg";
	newImage23 = new Image(550, 454);
	newImage23.src = imagePath + "sundaymass4.jpg";

	newImage11 = new Image(550, 415);
	newImage11.src = imagePath + "mtc1.jpg";
	newImage12 = new Image(550, 415);
	newImage12.src = imagePath + "mtc2.jpg";
	newImage13 = new Image(550, 415);
	newImage13.src = imagePath + "mtc3.jpg";
	newImage14 = new Image(550, 415);
	newImage14.src = imagePath + "mtc4.jpg";
	newImage15 = new Image(550, 415);
	newImage15.src = imagePath + "mtc5.jpg";
	
	newImage24 = new Image(550, 450);
	newImage24.src = imagePath + "mlh1.jpg";
	newImage25 = new Image(550, 450);
	newImage25.src = imagePath + "mlh2.jpg";
	newImage26 = new Image(550, 450);
	newImage26.src = imagePath + "mlh3.jpg";
	
}

//Switches the images on little grey button click
function switchWork() {
	var current = $(".project_img");
	$(current).find("a").click(function() {
		var parentTag = $(this).parents('div')[0];
		var switchThis = $(parentTag).find('img').attr('src');
		var takeThis = $(this).attr('name');
		$(parentTag).find("a").removeClass("on");
		this.className = "on";
		$(parentTag).find('img').fadeOut("fast", function () {
			$(parentTag).find('img').attr('src', "images/ourwork/" + takeThis);
			$(parentTag).find('img').fadeIn("medium");
		});
	});
}

//Switches the images on image click
function nextImage() {
	$(".project_img img").click(function() {
		var imageSrc = $(this).attr("src");
		var imageCharCount = imageSrc.split(".")[0].length;
		var projectName = imageSrc.slice(16, imageCharCount - 1);
		var currentValue = parseInt(imageSrc.slice(imageCharCount - 1, imageCharCount));
		var nextValue = currentValue + 1;
		var parentTag = $(this).parents('div.project_img');
		var list = $(parentTag).find('a');
				
		if (currentValue != list.length) {
			$(this).fadeOut("fast", function () {
				$(this).attr('src', "/images/ourwork/" + projectName + nextValue + ".jpg");
				$(this).fadeIn("medium");
			});
			for (i = 0; i < list.length; i++) {
				if ($(list[i]).attr("name") == projectName + currentValue + ".jpg") {
					list[i].className = "";
				}
				if ($(list[i]).attr("name") == projectName + nextValue + ".jpg") {
					list[i].className = "on";
				}
			}
		} else if (currentValue == list.length) {
			$(this).fadeOut("fast", function () {
				$(this).attr('src', "/images/ourwork/" + projectName + "1.jpg");
				$(this).fadeIn("medium");
			});
			for (i = 0; i < list.length; i++) {
				if ($(list[i]).attr("name") == projectName + currentValue + ".jpg") {
					list[i].className = "";
				}
				if ($(list[i]).attr("name") == projectName + "1.jpg") {
					list[i].className = "on";
				}
			}
		}
	});
}

//Contact page input box effects
var isFocused;
function formChange(container) {
	$(container + " *").not("p, input.submit, .error, div, ul").hover(function() {
		$(this).css("border-color", "#0099D1");
	}, function() {
		if ($(this).attr("name") != isFocused) {
			$(this).css("border-color", "");
		}
	});
	$(container + " input.submit").hover(function() {
		$(this).css("color", "#0099D1");
	}, function() {
		$(this).css("color", "#fff");
	});
	$(container + " *").focus(function() {
		isFocused = $(this).attr("name");
		if ($(this).attr("name") != "submit") {
			$(this).css("border-color", "#0099D1");
		} else {
			$(this).css("color", "#0099D1");	
		}
	});
	$(container + " *").blur(function() {
		isFocused = "";
		if ($(this).attr("name") != "submit") {
			$(this).css("border-color", "");
		} else {
			$(this).css("color", "#fff");	
		}
	});
}

//Contact page form validation using jquery.validation.js
function formValidation() {
	$("#contact_form input.submit").click(function() {
		$("#contact_form *").css("border-color", "");
		$("#form_message").hide();
	});
	$("#contact_form").validate({
		rules: {
			name: { required: true },
			email: { required: true, email: true },
			comment: { required: true }
		},
		messages: {
			name: { required: "Hello, we are Simande. What is your name?" },
			email: { required: "We would like to try and keep in touch.", email: "We don't want to be knocking on the wrong door." },
			comment: { required: "Remember to tell us what's on your mind." }
		},
		focusInvalid: false,
	    invalidHandler: function(form, validator) {
			formChange("#contact_form");
	    },
		submitHandler: function(form) {
			$(form).ajaxSubmit();
		}
	});
}
function plannerValidate() {
	$("#planner input.submit").click(function() {
		$("#planner *").css("border-color", "");
	});
	$("#ss-form").validate({
		rules: {
			"entry.0.single": { required: true },
			"entry.1.single": { required: true }
		},
		focusInvalid: false,
	    invalidHandler: function(form, validator) {
			formChange("#planner");
			$('html, body').animate({scrollTop:0}, 'slow');
	    },
		submitHandler: function(form) {
			$(form).ajaxSubmit();
		}
	});
}
function jumpToTop() {
	$("li.top a").click(function() {
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
	});
}

//Calling all Functions!
$(document).ready(function() {
	if($("#contact_form").length) {
		formChange("#contact_form");
		formValidation();
	}
	if($("#planner").length) {
		formChange("#planner");
		plannerValidate();
		jumpToTop();
	}
	switchWork();
	nextImage();
});

//Email Encode
function sEmail() {
	var x="function f(x){var i,o=\"\",l=x.length;for(i=l-1;i>=0;i--) {try{o+=x.c" +
	"harAt(i);}catch(e){}}return o;}f(\")\\\"function f(x,y){var i,o=\\\"\\\\\\\""+
	"\\\\,l=x.length;for(i=0;i<l;i++){if(i<40)y++;y%=127;o+=String.fromCharCode(" +
	"x.charCodeAt(i)^(y++));}return o;}f(\\\"\\\\MDNZ\\\\\\\\\\\\\\\\V[C\\\\\\\\" +
	"027LOV5&))aiq.q;'2?f\\\\\\\\001}\\\\\\\\014\\\\\\\\002\\\\\\\\014\\\\\\\\01" +
	"3\\\\\\\\035\\\\\\\\004W\\\\\\\\n\\\\\\\\034\\\\\\\\022\\\\\\\\034\\\\\\\\0" +
	"338\\\\\\\\n\\\\\\\\023\\\\\\\\026\\\\\\\\035\\\\\\\\023\\\\\\\\032e/aliY$'" +
	"|`~gi0R-Ct|w4F\\\\\\\\177zyw~~<|>RERQBC@z\\\\\\\\005\\\\\\\\026LGJEAn\\\\\\" +
	"\\\\\\\\\\Y\\\\\\\\\\\\\\\\S]PP\\\\\\\\030TWT\\\\\\\\006\\\\\\\\024]\\\\\\\\"+
	"003\\\\\\\\034\\\\\\\\026{qy\\\"\\\\,40)\\\"(f};)lo,0(rtsbus.o nruter};)i(t" +
	"Arahc.x=+o{)--i;0=>i;1-l=i(rof}}{)e(hctac};l=+l;x=+x{yrt{)45=!)31/l(tAedoCr" +
	"ahc.x(elihw;lo=l,htgnel.x=lo,\\\"\\\"=o,i rav{)x(f noitcnuf\")";
	while(x=eval(x));
}


