var mapToolTip = "";

function base(){

	// set up and replace nav elements
	$("div.header ul.nav li a").html("<img src='/images/sprite-nav.png' />");
	$("div.header ul.nav li").hover(
		function () { $(this).children("a").addClass("active"); }, 
		function () { $(this).children("a").removeClass("active"); }
	);
	
	// set up and replace neighboorhood subnav elements
	$("div.subnav-neighborhood").prepend("<div class='bg'></div>");
	$("div#subnav-manhattan label").html("<img src='/images/sprite-subnav-manhattan.png' />");
	$("div#subnav-manhattan ul li a").html("<img src='/images/sprite-subnav-manhattan.png' />");
	$("div#subnav-manhattan ul li").hover(
		function () { $(this).children("a").addClass("active"); }, 
		function () { $(this).children("a").removeClass("active"); }
	);
	
	
	// set up property content elements (property title, content, etc.)
	if($.browser.msie && $.browser.version <"7.0"){
		$("div.property-content").css({background:"#958A5F"});
	}
	else{
		$("div.property-content").append("<div class='bg'></div>");
	}
	//$("div.property-content div.highlights h2").html("<img src='/images/h2-highlights.gif' />");

	// set up and replace property subnav
	$("ul.subnav-property li a").html("<img src='/images/sprite-subnav-property.png' />");
	$("ul.subnav-property li").hover(
		function () { $(this).children("a").addClass("active"); }, 
		function () { $(this).children("a").removeClass("active"); }
    );

	$("ul.subnav-property-es li a").html("<img src='/images/sprite-subnav-property_es.png' />");
	$("ul.subnav-property-es li").hover(
		function () { $(this).children("a").addClass("active"); }, 
		function () { $(this).children("a").removeClass("active"); }
    );
	
	// determine number of rotation for property "flash"
	$("div.property-flash ul li:last").addClass("last");
	$("div.property-flash div.item").prepend("<div class='text-bg'></div>");
	$("div.property-flash div.item").each(function(){
		rotationCounter++;
	});

	
	// callout buttons
	$("div.callouts div").hover(
		function () { $(this).children("h1").addClass("active"); }, 
		function () { $(this).children("h1").removeClass("active"); }
	);
	
	// map icons
	$("div.map div").append("<div></div>");
	$("div.map div div").each(function(){
		mapToolTip = $(this).siblings("a").attr("title").replace(/ /g,'\u00a0');
		$(this).text(mapToolTip);
	});
	$("div.map div").hover(
		function () { $(this).children("div").fadeIn(150); }, 
		function () { $(this).children("div").fadeOut(150); }
    );

	// print page
	$("a#print").click(function(){
		$(".property-main").css('text-align','left');
		if($.browser.msie){
			$(".property-content").jqprint();
		}
		else{
			$(".property-content").printElement();
		}
	});

	//when all is ready, fade in page content
	$("div.wrapper").fadeIn();
}


var rotationCounter = "0";
var whichRotation = "0";
var keepRunning = true;
function propertyRotate(){
		
	if (keepRunning){
		if( whichRotation < rotationCounter ){
			$("div.property-flash div.item:nth-child("+whichRotation+")").fadeOut(200);
			$("div.property-flash ul li:nth-child("+whichRotation+")").removeClass("active");
			whichRotation++;
			$("div.property-flash div.item:nth-child("+whichRotation+")").fadeIn(200);
			$("div.property-flash ul li:nth-child("+whichRotation+")").addClass("active");
		}
		else{
			$("div.property-flash div.item:nth-child("+whichRotation+")").fadeOut(200);
			$("div.property-flash ul li:nth-child("+whichRotation+")").removeClass("active");
			whichRotation = "1";
			$("div.property-flash div.item:nth-child("+whichRotation+")").fadeIn(200);
			$("div.property-flash ul li:nth-child("+whichRotation+")").addClass("active");
		}
		setTimeout('propertyRotate()', 7500);
	}

	$("div.property-flash ul li").click(function(){
		keepRunning = false;
		if ( whichRotation != $(this).children("a").text() ) {
			whichRotation = $(this).children("a").text();
			$("div.property-flash div.item").fadeOut(200);
			$("div.property-flash ul li").removeClass("active");
			$("div.property-flash div.item:nth-child("+whichRotation+")").fadeIn(200);
			$("div.property-flash ul li:nth-child("+whichRotation+")").addClass("active");
		}
	});
}

function innerfade(){
	$("div.hp-flash").innerfade({ speed: 750, timeout: 5500, type: 'sequence', containerheight: '429px' }); 
	$("div.neighborhood-flash").innerfade({ speed: 750, timeout: 5500, type: 'random', containerheight: '428px' }); 
}

function table(){
	$("tr:odd").addClass("light");
	var pageHeight = $("div.results-main").height();
	$("div.results-sidebar").css({height:pageHeight});
}

function cufon(){
	Cufon.replace('.cufonated', { hover:true });	
	Cufon.replace('h1.main', { hover:true });	
	Cufon.replace('h1.rental_unit', { hover:true });
		
	Cufon.replace('h5', { hover:true });	

}

function search_and_notify(){
	$('input#search_notify').bind('click',function() {
		$("form#search_form input[type='checkbox']").each(function(){
			if($(this).attr('checked')){
				$("#notification_form").append("<input type='hidden' name='" + $(this).attr('name') + "' value='" + $(this).attr('value') + "' />");
			}
		});
	});
	$('input#search_reset').bind('click',function() {
		$("form#search_form input[type=checkbox]").attr('checked',false);
		$("form#search_form select").val('');
	});
	return true;
} 
