$(document).ready(function(){ 
	if($.browser.msie && parseInt($.browser.version) == 6) {
		//$(document).pngFix();
	}
	
	$('div.required label').append('<span style="color:#ff0000;">*</span>');
	
	if($.browser.safari) {
		$("ul.nav li a").css("padding","17px 9px 0 9px");
		$("ul.nav li ul li a").css("padding","7px 10px");
		//$("ul.nav li a").css("background","#00ff00");
	}

	$("table.table tr:even td").css("background-color", "#f8e8cf");
//	//$("table.table tr:odd td").css("background-color", "#f4f3f0");
	$("table.table tr td:first-child").css("border-left", "1px solid #613a22");
	$("table.table tr td:last-child").css("border-right", "1px solid #613a22");
	
	$("table.home-plans-table tr:even td").css("background-color", "#f6f1e7");
	$("table.home-plans-table tr td:first-child").css("border-left", "1px solid #e5cfa6");
	$("table.home-plans-table tr td:last-child").css("border-right", "1px solid #e5cfa6");
	
	$("table.images tr td:first-child").css("border-left", "1px solid #e5cfa6");
	$("table.images tr td:last-child").css("border-right", "1px solid #e5cfa6");
	
	//$("table.results tr td:even").css("background-color", "#f6f1e7");
	$("table.results tr td:last-child").css("border-right", "1px solid #e5cfa6");
	
	$('table.slideout th a').click(function() {
		$(this).parent('th').parent('tr').next('tr').find('td').slideToggle();
		$(this).toggleClass('on');
		return false;
	});
	
	$("ul.nav").superfish({
		delay:100,
		animation: {height:'show'},
		speed:'fast',
		autoArrows:false,
		onBeforeShow: beforeShow
	});
	
	function beforeShow() {
		if($(this).prev('a').attr('id') != undefined) {
			if($(this).prev('a').attr('id') == 'about-us') {
				$(this).css('left','-114px');
			}
			if($(this).prev('a').attr('id') == 'event-calendar') {
				$(this).css('left','-128px');
			}
		}
	}
	
	$(".rollover").hover(
	  function () {
		var imagesrc = $(this).find("img").attr("src");
		$(this).find("img").attr("src",imagesrc.replace("-off","-on"));
	  }, 
	  function () {
		var imagesrc = $(this).find("img").attr("src");
		$(this).find("img").attr("src",imagesrc.replace("-on","-off"));
	  }
	);
	
	$("a.lightbox").fancybox({
		'transitionIn'	: 'fade',
		'transitionOut'	: 'fade',
		'titleShow' : true,
		'overlayOpacity' : 0.9,
		'onComplete': function() { 
			$("#fancybox-title").css({'top':'-40px', 'bottom':'auto'}); 
		} 
	});
	
	$("a.easybuild").fancybox({
		'transitionIn'	: 'fade',
		'transitionOut'	: 'fade',
		'titleShow' : true,
		'overlayOpacity' : 0.9,
		'width':861,
		'height':900,
		'onComplete': function() { 
			$("#fancybox-title").css({'top':'-40px', 'bottom':'auto'}); 
		} 
	});
	
	$("a.downloadForm").fancybox({
		'transitionIn'	: 'fade',
		'transitionOut'	: 'fade',
		'titleShow' : false,
		'overlayOpacity' : 0.9,
		'width':500,
		'height':650
	});
	
	$("a.salesForm").fancybox({
		'transitionIn'	: 'fade',
		'transitionOut'	: 'fade',
		'titleShow' : false,
		'overlayOpacity' : 0.9,
		'width':700,
		'height':750
	});
	
	$("a.repSearchForm").fancybox({
		'transitionIn'	: 'fade',
		'transitionOut'	: 'fade',
		'titleShow' : false,
		'overlayOpacity' : 0.9,
		'width':500,
		'height':250
	});
	
	$("#thumb-gallery-img").find("a").click(
	  function () {
		$("#large-gallery-img").find("img").attr('src',$(this).attr('href'));
		return false;
	  }
	);
	
	$("#thumb-gallery-img td a").each(function(){
		$.preLoadImages($(this).attr('href'));				  
	});
	
	$("p#floorPlanThumbs span a").fancybox({
		'transitionIn'	: 'fade',
		'transitionOut'	: 'fade',
		'titleShow' : true,
		'overlayOpacity' : 0.9,
		'onComplete': function() { 
			$("#fancybox-title").css({'top':'-40px', 'bottom':'auto'}); 
		} 
	});
	$("#launchFloorPlans").click(
	  function () {
		$("p#floorPlanThumbs span a").trigger('click');
	  }
	);
	
	$('#category_select').change(function(){
	  $('#category_form').submit();
	  return false;
	});
	
	$('#brochures input').click(function(){
		brochureCheck(this);
	});
	
}); 

function brochureCheck(obj) {
	if($(obj).val() == 'Portfolio of Plans') {
	  if(obj.checked) {
		  $('#cc_info').show();
	  } else {
		  $('#cc_info').hide();
	  }
	}
}

var cache = [];
// Arguments are image paths relative to the current page.
$.preLoadImages = function() {
var args_len = arguments.length;
for (var i = args_len; i--;) {
  var cacheImage = document.createElement('img');
  cacheImage.src = arguments[i];
  cache.push(cacheImage);
}
}

