$(document).ready(function() {
	// Store url for current page as global variable
	var current_page = document.location.href
	
		// Apply selected states depending on current page
		if ( current_page === "http://zylstraauto.toriantest.com/" || current_page === "http://zylstraauto.toriantest.com/Home/tabid/1290/Default.aspx" )  {
			$("ul#Nav li a:eq(0)").addClass('active');
		} else if (current_page.match(/Diesel/)) {
			$("ul#Nav li a:eq(1)").addClass('active');
		} else if (current_page.match(/About/)) {
			$("ul#Nav li a:eq(2)").addClass('active');
		} else if (current_page.match(/Contact/)) {
			$("ul#Nav li a:eq(3)").addClass('active');
		} else if (current_page.match(/ClubCard/)) {
			$("ul#Nav li a:eq(4)").addClass('active');
		} else { // Do not mark any nav links as selected
			$("ul#Nav li").removeClass('active');
		};
	
	//var td = $(".DynamicForms_Maintable tbody tr td:odd");
	//td.attr("rowspan", "2");
	
	$("td.NormalBold p").remove();
	$("td.NormalBold br:even").remove();
	
	$(".DynamicForms_Maintable tbody tr:nth-child(2)").addClass("group");
	$(".DynamicForms_Maintable tbody tr:nth-child(4)").addClass("group");
	
	$('.group').each(function() {
		var head = $(this);

		if(!head.parent().hasClass('form-section')) {
		head.before("<div class=\"form-section\"></div>");

		var wrap = head.prev();
		var curr = head;

			do {
				var currEl = curr;
				curr = curr.next();
				currEl.appendTo(wrap);
			}
			while(curr.length > 0 && !curr.hasClass('group'));
		}
	});

	
	// Image Gallery
	$(".galleryPhoto").click(function() {
		var image = $(this).clone();
		var closeBtn = $('.closeBtn');
		var title = image.attr("title");
		var photoDetails = $('.photoDetails');
		$('.modalImage').addClass('show');
		photoDetails.text(title);
		image.appendTo('.imageHolder');
		image.removeClass('galleryPhoto');
		image.css("top", ($(window).height() / 2) - (image.height() / 2) );
		image.css("left", ($(window).width() / 2) - (image.width() / 2) );
		closeBtn.css("top", ($(window).height() / 2) - (image.height() / 2) - 10 );
		closeBtn.css("left", ($(window).width() / 2) - (image.width() / 2) - 10 );
		photoDetails.css("top", ($(window).height() / 2) - (image.height() / 2) - 32 );
		photoDetails.css("left", ($(window).width() / 2) - (image.width() / 2) + 25 );
		closeBtn.click(function () {
			$('.modalImage').removeClass('show');
			image.remove();
		});
		image.click(function () {
			$('.modalImage').removeClass('show');
			$(this).remove();
		});
	});
	
});
