$(document).ready(function(){

	$('.contactButton').click(function (e) {
		$('#contactForm').modal({	
			opacity:65,
			persist: true
		});
		return false;
	});
	$('.appointmentButton').click(function (e) {
		$('#appointmentForm').modal({	
			opacity:65,
			persist: true
		});
		return false;
	});

/*added here*/
	checkHash();

	function checkHash() {
		var thisUrl = window.location;
		thisUrl = thisUrl.toString();
		var checkContact = thisUrl.indexOf("#contactForm");
		var checkAppt = thisUrl.indexOf("#appointmentForm");
if(checkContact > -1) {
	$('.contactButton').trigger("click");		
} else if (checkAppt > -1){
	$('.appointmentButton').trigger("click");	}}
/*to here*/

	//Gallery Slider
	var slides = $(".homeSlide"),
		slidesNum = $(slides).length,
		slideWidth = $(slides).outerWidth(),
		nextButton = $(".nextButton"),
		prevButton = $(".prevButton"),
		slideHolder = $("#slideHolder");
		
	slideHolder.width(parseFloat(slideWidth * slidesNum));

	slideHolder.css("right", parseFloat(slideWidth * (slidesNum-1) * (-1)));

	$(slides[0]).addClass("active");
	
	nextButton.click(function(){
		var activeIndex = $(".active").index();
		if($(slideHolder).css("right") != "0px"){
			$(slideHolder).animate({
				right: '+=' + parseFloat(slideWidth)
			}, 500);
			$(slides).removeClass("active");
			$(slides[activeIndex + 1]).addClass("active");
		}
	});
	prevButton.click(function(){
		var activeIndex = $(".active").index();
		if(activeIndex){
			$(slideHolder).animate({
				right: '-=' + parseFloat(slideWidth)
			}, 500);
			$(slides).removeClass("active");
			$(slides[activeIndex - 1]).addClass("active");
		}
	});

	var inputs = $("input[type='text'],textarea");
	$.each(inputs,function(i,e) {
		var placeholder = $(e).attr("placeholder");
			$(e).val(placeholder);	
			$(e).blur(function() {
				resetInput($(this));
			});
			$(e).focus(function() {
				if($(this).val() == placeholder) {
					$(this).val("");
				}
			});
		});

	function resetInput(elem) {
		if($(elem).val() == "") {
				var placeholder = $(elem).attr("placeholder");
				$(elem).val(placeholder);
			}
	}
		
	if($("#banner").html().length == 0){
		prepBannerImages($("#banner"));
	}
});



function prepBannerImages(dest){
	var imageOptions = [
		{
			"name": "banner1.png"
		},
		{
			"name": "banner2.png"
		},
		{
			"name": "banner3.png"
		},
		{
			"name": "banner4.png"
		},
		{
			"name": "banner5.png"
		},
		{
			"name": "banner6.png"
		},
		{
			"name": "banner7.png"
		},
		{
			"name": "banner8.png"
		},
		{
			"name": "banner9.png"
		}
	],
		imagePath = "assets/images/",
		usedNumbers	=	[],
		ceiling = imageOptions.length,
		randomNumber = Math.floor(Math.random()*ceiling),
		numberList	=	[randomNumber];
	usedNumbers.push(randomNumber);
	for(var x = 1; x < 4; x++) {
		numberList[x] = Math.floor(Math.random()*ceiling);	
		while ($.inArray(numberList[x],usedNumbers) >= 0) {
			numberList[x] = Math.floor(Math.random()*ceiling);	
		}
		usedNumbers.push(numberList[x]);
	}
	
	var htmlCode = "<img src='" + imagePath + imageOptions[numberList[0]].name + "' />" +
					"<img src='" + imagePath + imageOptions[numberList[1]].name + "' />" +
					"<img src='" + imagePath + imageOptions[numberList[2]].name + "' />" +
					"<img src='" + imagePath + imageOptions[numberList[3]].name + "' />";

	dest.append(htmlCode);
}



