$(document).ready(function() {
	$('.proplist_propbox_holder').mouseenter(function(){
		$('.pdpb_drawer_map_link').show();
		$('.pdpb_drawer_details_link').show();
		$('.proplist_propbox_drawer', this).animate({"width": "50px"}, 200);
	});
	$('.proplist_propbox_holder').mouseleave(function(){
		$('.pdpb_drawer_map_link').hide();
		$('.pdpb_drawer_details_link').hide();
		$('.proplist_propbox_drawer', this).animate({"width": "10px"}, 200);
	});

	//Login Menu document click close
	$("#login_menu").click(function(e) {
		e.stopPropagation();
	});
	$(document).click(function() {
		if(loginIsOpen) {
			toggleLogin('hide');
		}
		
	});

	
});

var details_tab_showing = 'A';
function show_details_map(showCode) {
	if(showCode == details_tab_showing){return false;};
	switch(showCode) {
		case 'A':
			$('.details_map_paneA').show();
			$('#dmli_A').addClass('dmt_active');
			$('#dmli_A a').removeClass('dmt_inactive');

			$('.details_map_paneB').hide();
			$('#dmli_B').removeClass('dmt_active');
			$('#dmli_B a').addClass('dmt_inactive');

			details_tab_showing = 'A';
			break;
		case 'B':
			$('.details_map_paneB').show();
			$('#dmli_B').addClass('dmt_active');
			$('#dmli_B a').removeClass('dmt_inactive');

			$('.details_map_paneA').hide();
			$('#dmli_A').removeClass('dmt_active');
			$('#dmli_A a').addClass('dmt_inactive');

			details_tab_showing = 'B';
			break
	}

	return false;
}

var loginIsOpen = false;
function toggleLogin(command) {
	if(command == undefined) {
		$('#lm_holder').toggle();
	} else {
		if(command == 'hide') {
			$('#lm_holder').hide();
			loginIsOpen = true;
		} else {
			$('#lm_holder').show();
			loginIsOpen = false;
		}
	}
	if(!loginIsOpen) {
		$('#lm_login_btn')
			.css('background-color', '#C2C2C2')
			.css('backgroundPosition', '-120px 0')
			.css('-moz-border-radius', '0')
			.css('-webkit-border-radius', '0');
		loginIsOpen = true;
	} else {
		$('#lm_login_btn')
			.css('background-color', '#cf4e33')
			.css('backgroundPosition', '0 0')
			.css('-moz-border-radius', '0 0 8px 0')
			.css('-webkit-border-radius', '0 0 8px 0');
		loginIsOpen = false;
	}
}

function OpenIntroOverlay(){
	//legacy function - name changes
	popup_joinform();
}

function popup_joinform() {
	close_btn = "<a href=\"#\" id=\"popup_close\" onclick=\"parent.TINY.box.hide(); return false;\"></a>";
	content= close_btn + "<iframe id=\"joinFormPopup\" scrolling=\"no\" src =\"/PHP/processSignUp_popup.php\" width=\"895\" height=\"466\"><p>Your browser does not support iframes.</p></iframe>";
	TINY.box.show(content,0,0,0);

	return false;
}

function popup_video(filename) {
	close_btn = "<a href=\"#\" id=\"popup_close\" onclick=\"parent.TINY.box.hide(); return false;\"></a>";
	content= close_btn + "<iframe id=\"videoPopup\" scrolling=\"no\" src =\"/PHP/video_popup.php?video=" + filename + "\" width=\"600\" height=\"450\"><p>Your browser does not support iframes.</p></iframe>";
	TINY.box.show(content,0,0,0);

	return false;
}

function popup_template(template_name, width, height) {
	if(width == undefined) {	width = '895';	}
	if(height == undefined) {	height = '466';	}
	close_btn = "<a href=\"#\" id=\"popup_close\" onclick=\"parent.TINY.box.hide(); return false;\"></a>";
	content= close_btn + "<iframe id=\"templatePopup\" scrolling=\"no\" src =\"/PHP/template_popup.php?template=" + template_name + "\" width=\"" + width + "\" height=\"" + height + "\"><p>Your browser does not support iframes.</p></iframe>";
	TINY.box.show(content,0,0,0);

	return false;
}


function show_county_group(group_num) {

	tab_count = $(".county_filter_tab").size() + $(".county_filter_tab_empty").size();
	group_num = parseInt(group_num);

	for (i = 0; i < tab_count; i++) {
		if(i != group_num && group_num != 0) {
			$('.' + i).hide()
		} else {
			$('.' + i).show()
		}
		if(i == group_num) {
			$('#county_group_' + i).addClass('county_filter_tab_active');
		} else {
			$('#county_group_' + i).removeClass('county_filter_tab_active');
		}
	}

}

function show_PropImg(caseNumber) {

	if(caseNumber != undefined) {
		close_btn = "<a href=\"#\" id=\"popup_close\" onclick=\"parent.TINY.box.hide(); return false;\"></a>";
		content= close_btn + "<span class=\"details_img_popup_holder\" ><img src=\"PHP/img.php?case=" + caseNumber + "\"/></span>";
		//for testing large images:  content= close_btn + "<div class=\"details_img_popup_holder\" ><img src=\"http://wallpaperblog.files.wordpress.com/2007/12/blue_sky_1920.jpg\"/></div>";
		TINY.box.show(content,0,0,0);
	}
	return false;
}

function do_quotes() {

	//Note:  IE wouldn't fade out the cuifon font replacement glyphs so I basically just
	//have a quote_hider div that is on top of everything that is the same color as the
	//background.  It fades in and our revealing the text below.
	$('.quote_block');
	setInterval(function(){
		$('.quote_hider').fadeIn(400, function(){
			$('.quote_block').filter(':visible').hide(function(){
				if($(this).next('.quote_block').size()){
					$(this).next().show();
				}
				else{
					$('.quote_block').eq(0).show();
				}
				$('.quote_hider').fadeOut(400);
			});
		});
	},6000);
}

function start_recent_props() {
	var refreshIntervalId = setInterval(function(){
		hidden_count = $('.recently_viewed_item').filter(':hidden').length;
		$('.recently_viewed_item').filter(':hidden').filter(':last').animate({opacity: 'toggle', height: '75px'}, 'slow');

		if(hidden_count < 4) { //start to recycle
			//alert('lessthan');
			moveme = $('.recently_viewed_item').filter(':visible').filter(':last');
			moveto = $('.recently_viewed_item').filter(':hidden').filter(':first');
			$(moveme).hide();
			$(moveme).css({height: '0px'});
			$(moveme).insertBefore(moveto);
		}
	},5000);

	//clearInterval(refreshIntervalId); //if you want to stop the interval

}

function show_tip(sender, tip_id) {
	//tip_holder_parent = $(sender).parent;
	$(sender).parent().hover(function() {
		}, function(){
			$(tip_id).hide();
	});
	$(tip_id).show();
}

function goto_state() {
	stateAbbr = $('#state_dd').val();

	if(stateAbbr != '') {
		window.location = "/hud-foreclosures-search-results-" + stateAbbr +".html"
	}
}



//OLD BELOW THIS LINE
//-----------------------------------------




var showingSlider = 1;
function sliderSlideIn(sliderNumber) {

	if(sliderNumber == showingSlider) {
		return;
	}


	jQuery('#ppp_slider_frame_' + sliderNumber).css('left', 730);
	jQuery('#ppp_slider_frame_' + showingSlider).animate({left: "-740"}, {queue:false, duration:800});
	jQuery('#ppp_slider_frame_' + sliderNumber).animate({left: "0"}, {queue:false, duration:800});

	jQuery('#slch_' + sliderNumber).css('backgroundPosition', -12);
	jQuery('#slch_' + showingSlider).css('backgroundPosition', 0);


	showingSlider = sliderNumber;


}

/**
 * The reason that autoSlideGo is separate from timerThenGo is so that It is almost
 * like having timer objects that can check to see if they should fire based on
 * if you have same popup window open when it is time to animate.  Without it,
 * I could open and close the popup a bunch of times, then there were that many
 * setTimout functions waiting to fire and then everything would animated out of
 * sync.
 */
var autoslide = false;
var popSessionID = 0;
var delay = 7000;
function autoSlideGo() {
	timeoutThenGo(popSessionID);
}

function timeoutThenGo(session) {
	setTimeout(function(){
	    if(autoslide && session == popSessionID){
			if(showingSlider > 2) {
				i = 1;
			} else {
				i = showingSlider + 1;
			}
			sliderSlideIn(i);
			autoSlideGo();
	    }
	}, delay);
}




function test() {
	alert('go');

}
