var $maxClick;

$(document).ready(function(){
/*////////////////////////////////////////////////////////////////*/
/* Bottom text: Community Specials and the welcome text on the main page */
/* This will adjust the height of both columns to keep them at the same height */
	var $mt = $('#mainText').height();
	var $tm = $('#textMsg').height();
	var $sb = $('#specialBox').height();
	var $pb = ($mt - $sb)+parseInt($('#textMsg p').css('margin-bottom'));
	
	/* Set the community special div to the same height as the bottomText div */
	if($('#mainText').height() > 256 && $('#specialBox').height() <= $mt){
		$('#specialBox').height($mt);
		$('#textMsg p').css('margin-bottom',$pb+'px');	
	} else if($('#specialBox').height() > 256){
		$('#mainText').height($sb);		
	} else {
		$('#mainText, #specialBox').height(256);	
		if($('#textMsg').height() < 205){
		$pb = (205 - parseInt($('#textMsg').height()));
		}		
		$('#textMsg p').css('margin-bottom',$pb+'px');
	}
/*////////////////////////////////////////////////////////////////*/
/* Navigation hover effects */	
	$('#mainNav li').not('li.mainBlankCol').hover(function(){
		$(this).css('cursor','pointer');
		$(this).css('backgroundColor', '#806850');
	},function(){
		$(this).css('backgroundColor', '#000000');	
	});
	
	$('#topNav li').not('li.topBlankCol, li.liSpacer, li#home').hover(function(){
		$(this).css('cursor','pointer');
		$(this).css('backgroundColor', '#806850');
	},function(){
		$(this).css('backgroundColor', '#000000');	
	});
	
	$('#topNav li#home').hover(function(){
		$(this).css('cursor','pointer');
		$(this).css('backgroundColor', '#000000');
	},function(){
		$(this).css('backgroundColor', '#806850');	
	});
/*////////////////////////////////////////////////////////////////*/
/* Social stuff like Facebook and Twitter */
	$('img.social').hover(function(){
		var thisId = $(this).attr('id');
		switch (thisId){
			case 'facebook':
				var src = ($(this).attr('src') === 'images/icon-F.jpg')
				? 'images/icon-F2.jpg'
				: 'images/icon-F.jpg';
			break;
			case 'twitter':
				var src = ($(this).attr('src') === 'images/icon-T.jpg')
				? 'images/icon-T2.jpg'
				: 'images/icon-T.jpg';
			break;
		};
		
		$(this).attr('src',src);		
	});
/*////////////////////////////////////////////////////////////////*/
/* In the interior pages make sure the left panel is the same height */
/* as the interior content div */

	if($('#shadowBox').height() > 400){
	$('#leftPanel').height($('#shadowBox').height());
	}else{
		$('#leftPanel').height(811);
	}
	

	$('#imgContainer ol li:first-child img').css({
		borderColor:'#313133'
	})
	
	$('#nextBtn').click(function(){
		
		$currentSet++;
		
		if($currentSet <= $maxClicks){
		$("#imgContainer ol").animate({"right": '+='+$displayWidth+'px'}, "slow");
		}else{
		$("#imgContainer ol").animate({"right": '-='+$fullWidth+'px'}, "slow");
		$currentSet = 0;
		}

	});
	
	$('#prevBtn').click(function(){
		if($currentSet >= 1){
		$currentSet--;
		$("#imgContainer ol").animate({"right": '-='+$displayWidth+'px'}, "slow");
		}else{
		$("#imgContainer ol").animate({"right": '+='+$fullWidth+'px'}, "slow");
		$currentSet = $maxClicks;
		}

	});
	
	$('.tours img').hover(function(){			
		$(this).css({'borderColor':'#313133'});
	},function(){
		$(this).css({'borderColor':'#c0c0c0'});
	});
	
	$('#imgContainer li img').click(function(){
		$('#imgContainer li img').css({'borderColor':'#c0c0c0'});
		$(this).css({'borderColor':'#313133'});
	});

/*////////////////////////////////////////////////////////////////*/
/* floorplan table */
/*////////////////////////////////////////////////////////////////*/	
	$('table#floorplansTable tr:not([th]):odd').css({'background-color':'#806850'});
	$('table#floorplansTable tr:not([th]):even').css({'background-color':'#ffffff'});
	
	
	$('table#floorplansTable tr').hover(function(){
		$('td', this).addClass('trOver');
		}, function() {
		$('td',this).removeClass('trOver');
	}).click(function() {
		$('td').removeClass('trClick');
		$('td', this).toggleClass("trClick");
		$('#fpNameLabel').html($('td.modelName',this).text());
		showFloorPlan(this);
	});

/*////////////////////////////////////////////////////////////////*/
/* Show the starting address box for point-to-point direction  */
/*////////////////////////////////////////////////////////////////*/
	$('#directionLink').click(function(){
		$('#getDirection').slideDown('slow');
		$('input#saddr').focus();
	});
	
	$('img#walkIcon').click(function(){
		$('form#getDirection').attr({ 
			action: 'http://maps.google.com/maps'
		});		
		$('form#getDirection').submit();
	});
	$('#closer').hover(function()
		{
		$(this).css({
			'backgroundColor': '#313133',
			'color': '#bdb76b'
		});
		},function()
		{
		$(this).css({
			'backgroundColor':'#b75727',
			'color': '#ffffff'
		});					
	});

	$('#closer').click(function(){
		$('input#saddr').val('');
		$('#getDirection').slideUp('slow');
	});

/*////////////////////////////////////////////////////////////////*/
/* Neigborhood Information */
/*////////////////////////////////////////////////////////////////*/
	$('#neigborhoodInfo .heading:not(:first-child)').css('margin-top', '30px');

/*////////////////////////////////////////////////////////////////*/
/* Apply Online */
/*////////////////////////////////////////////////////////////////*/
	$('div#mainNav li#apply, div#footerMenuDiv li#footerApply').click(function(){
		window.open('https://secure.resiteit.com/apps/?cid=2022','','toolbar=no, location=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, width=640 ,height=600');
	});

/*////////////////////////////////////////////////////////////////*/
/* Pay Rent Online */
/*////////////////////////////////////////////////////////////////*/
	$('div#topNav li#rent, div#footerMenuDiv li#footerRent').click(function(){
		var $url = "https://property.onesite.realpage.com/templates/template_08residentportal/login/login.asp?w=villasatwestroad&t=template_08residentportal&u=1 , payrent , true";
		window.open($url,'','toolbar=no, location=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, width=640 ,height=600');
	});

/*////////////////////////////////////////////////////////////////*/
/* Neighborhood Services */
/*////////////////////////////////////////////////////////////////*/
$('#services a').click(function(){
	//console.log($(this).attr('href').substr(1,$(this).attr('href').length));
	
	var srv = $(this).attr('href').substr(1,$(this).attr('href').length);
	$('.heading').css({'background-color':'transparent', 'color':'#b75727'});
	$('#'+srv).css({'background-color':'#806850', 'color':'#ffffff'});
	

});
	
});

/*////////////////////////////////////////////////////////////////*/
/* Display floorplan image */
/*////////////////////////////////////////////////////////////////*/
function showFloorPlan(plans){
	//var imagePath = "http://app.resiteit.com/control/marketing/displayfloorpic.php?";
	var fpImg = "<a href='floorplandetail.php?UType"+plans.id+"&cid="+$cid+"' target='_block'><img style='display:block;' src='"+$imageRoot+plans.id+"' /></a>"
	prntBtn = "<a href='floorplandetail.php?UType"+plans.id+"&cid="+$cid+"' target='_block'><img src='images/print-btn.jpg' /></a>";
	
	$('#plans').empty();
	$('#plans').append(fpImg);
	$('#prntButton').empty().append(prntBtn);
	
	$('#plans a img').load(function(){
		if($('#plans a img').width() > 608){	
			$('#plans a img').css({
					width: 609
			});
		} else {
			var here = parseInt((609-$('#plans a img').width())/2);
			$('#plans a img').css({
					'margin-left': here
			});
		}
	});
	$('html, body').animate({scrollTop:0}, 'slow');
};
/*////////////////////////////////////////////////////////////////*/
/* Neighborhood Services */
/*////////////////////////////////////////////////////////////////*/


