$(document).ready(function(){
	$(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'light_square'});
	 	
		flashembed("#flash_holder_home", {
			src: 'flash/image_area_home2.swf',
			wmode: "transparent",
			allowScriptAccess: "always",
			id: "EIface",
			version:  [9, 0]
		});	

	var n = $(".slide").length;
	var homeLoc = new Array(n);
	for (k=1; k<=n; k++)
		{

			homeLoc[k] = k * 26 + 752 - 26;
			$("#slide-" + k + ":not(.open)").css("left", homeLoc[k]);

		}
	
	$('a[name]').click(function(){
		var aname = $('a[name]');
		//alert(aname);
		var n = $(".slide").length;


		if ($(this).attr('name') == 'home'){
			var thisIsIt = false;
			var thisPane = 1;
			// intiate play on the Flash movie residing on the first (opening) pane only
			flashembed("#flash_holder_home", {
			src: 'flash/image_area_home2.swf',
			wmode: "transparent",
			allowScriptAccess: "always",
			id: "EIface",
			version:  [9, 0]
	});

		}

		if ($(this).attr('name') == 'amenities'){
			var thisIsIt = false;

				var thisPane = 2;
				// intiate play on the Flash movie residing on the second pane only
				flashembed("#flash_holder_amenities", {
				//src: "flash/EIFace.swf",
				src: 'flash/amenities.swf',
				wmode: "transparent",
				allowScriptAccess: "always",
				id: "EIface2",
				version:  [9, 0]
	});



		}
		if ($(this).attr('name') == 'floorplans'){
			var thisIsIt = false;

				var thisPane = 3;



		}
		if ($(this).attr('name') == 'neighborhood'){
			var thisIsIt = false;

				var thisPane = 4;
				// intiate play on the Flash movie residing on the forth pane only
				flashembed("#flash_holder_neighborhood", {
				//src: "flash/EIFace.swf",
				src: 'flash/neighborhood.swf',
				wmode: "transparent",
				allowScriptAccess: "always",
				id: "EIface3",
				version:  [9, 0]
	});



		}
		if ($(this).attr('name') == 'news'){
			var thisIsIt = false;

				var thisPane = 4;



		}
		if ($(this).attr('name') == 'gallery'){
			var thisIsIt = false;

				var thisPane = 5;



		}
		if ($(this).attr('name') == 'about'){
			var thisIsIt = false;

				var thisPane = 6;
				// intiate play on the Flash movie residing on the sixth pane only
				flashembed("#flash_holder_aboutus", {
				//src: "flash/EIFace.swf",
				src: 'flash/about_us.swf',
				wmode: "transparent",
				allowScriptAccess: "always",
				id: "EIface1",
				version:  [9, 0]
	});



		}
		if ($(this).attr('name') == 'info'){
			var thisIsIt = false;

				var thisPane = 7;



		}
		if ($(this).attr('name') == 'contact'){
			var thisIsIt = false;

				var thisPane = 8;
				// insert Atlas 1x1 only when pane eight has been opened
				$('#img_redir').prepend('<img height="1" width="1" src="http://view.atdmt.com/action/083110_HuntingdonPlace_MDPage">');
				
		}



		var activePane = parseInt($('.active').attr('id').substring(6,7))



		if(activePane < thisPane){
			for (q=thisPane; q>=1; q--){
				var p = q;
				var openLoc = p * 26 - 26;
				$('#slide-' + q + ':not(#slide-1)').animate({'left': openLoc + 'px'}, 200).addClass('open').removeClass('closed');
				}
				// the image replace code below has been removed from the for loop
				var thisName = false;
				var stringToReplace = $('#slide-' + activePane + ' .slidebutton').children('img').attr('src');
				var onstringToReplace = $('#slide-' + thisPane + ' .slidebutton').children('img').attr('src');
				var _tabimageVar = '.gif';
				if (thisPane != activePane){
				//if (thisPane > 0){
					// both '.gif' and '_on.gif' are stored in the variable '_tabimageVar' to replace the entire '_on.gif' string rather than append it to the preexisting '_on'
					_tabimageVar = ('_on.gif');
						var newString = stringToReplace.replace(_tabimageVar, '.gif');
							$('#slide-' + activePane + ' .slidebutton').children('img').attr('src', newString);
							//alert("forward nav image being replaced = "+_tabimageVar+ " on closing pane "+activePane+ " forward nav new image = "+newString);
							_tabimageVar = ('.gif');
						var newonString = onstringToReplace.replace(_tabimageVar, '_on.gif');
							$('#slide-' + thisPane + ' .slidebutton').children('img').attr('src', newonString);		function thisMovie(movieName) {
  								if (navigator.appName.indexOf("Microsoft") != -1) {
    							return window[movieName];
  								} else {
    							return document[movieName];
  									}
								}
							//alert(thisPane);
							//alert("forward nav image being replaced = "+_tabimageVar+ " on opening pane "+thisPane+ " forward nav new image = "+newonString);

				thisName == true;
				//alert('activepaneUp = ' + activePane);
				//alert('thispaneUp = ' + thisPane);
				}
				$('#slides li').removeClass('active');
				$('#slides li#slide-' + thisPane).addClass('active');
		}
		

		if (activePane > thisPane){
				nextActivePane = activePane + 1;
				thisNextPane = thisPane + 1;
			for (q=thisNextPane; q<=n; q++){
				var p = q;
				var closeLoc = p * 26 + 726;
				$('#slide-' + q + ':not(#slide-1)').animate({'left': closeLoc + 'px'}, 200).addClass('closed').removeClass('open');

			}
			var j = p;
			var stringToReplace = $('#slide-' + activePane + ' .slidebutton').children('img').attr('src');
			var onstringToReplace = $('#slide-' + thisPane + ' .slidebutton').children('img').attr('src');
			var thispanelisactive = false;
			var _tabimageVar = '.gif';
			if (thisNextPane != nextActivePane){
				_tabimageVar = ('_on.gif');
					var newString = stringToReplace.replace(_tabimageVar, '.gif');
						$('#slide-' + activePane + ' .slidebutton').children('img').attr('src', newString);
						//alert("backwards nav image being replaced = "+_tabimageVar+ " on closing pane "+activePane+ " backwards nav new image = "+newString);
				_tabimageVar = ('.gif');
					var newonString = onstringToReplace.replace(_tabimageVar, '_on.gif');
						$('#slide-' + thisPane + ' .slidebutton').children('img').attr('src', newonString);
						//alert("backwards nav image being replaced = "+_tabimageVar+ " on opening pane "+thisPane+ " backwards nav new image = "+newonString);
			//alert('activepaneBack = ' + activePane);
			//alert('thispaneBack = ' + thisPane);
			}
			$('#slides li').removeClass('active');
			$('#slides li#slide-' + thisPane).addClass('active');

		}
		});

	//alert(thisPane);
});

var appointment = $("#appointment");
// newsletter topics are optional, hide at first
var inital = appointment.is(":checked");
var fields = $("#comments, #month, #day, #year, #aapt_time")[inital ? "removeClass" : "addClass"]("gray");
var fieldsInputs = (fields).attr("disabled", !inital);
// show when newsletter is checked
appointment.click(function() {
	fields[this.checked ? "removeClass" : "addClass"]("gray");
	fieldsInputs.attr("disabled", !this.checked);
});



