$(document).ready(function() {
	var height_difference = $('#nav_container_cell').height() - $('#nav_container_div').height();
	$('#nav_container_div').css({ height:$('#nav_container_cell').height() });
	var new_scroller_height = $('#nav_container_div_scroller').height() + height_difference;
	$('#nav_container_div_scroller').css({ height:new_scroller_height });
});

function common_setupPanes() {
	panes_viewed = new Array();
	last_pane_viewed = -1;
}

function common_showPane(showID, alias, useFlash, gotoFloorplan, delay) {
	var _delay = 400;

	if (typeof(delay) != "undefined") {
		_delay = delay;
	}
	
	if(last_pane_viewed == showID) {
		var newlink = "./" + alias + "/" + $('#item_alias_' + showID).text();
		if(gotoFloorplan == 1) newlink += "/floorplans";
		return goto(newlink);
	}
	
	var x = 0;
	while(document.getElementById('pane_' + x)) {
		if(x != showID) {
			$('#pane_' + x).hide();
			$('#block_' + x).removeClass("homes_nav_block_selected");
			$('#block_' + x).addClass("homes_nav_block");
			$('#block_link_' + x).removeClass("hide");
			$('#nav_info_' + x + ' tr:even').removeClass("nav_info_hl_sel");
			$('#nav_info_' + x + ' tr:even').addClass("nav_info_hl");
		} else {
			if(useFlash == 1) {
				var imgstr = $('#image_string_' + showID).text();
				if(imgstr.split(",").length > 1) {
					var str = panes_viewed.toString();
					if(str.search('h' + showID) == -1) {
						var so = new SWFObject("../../content/common/flash/image_viewer.swf", "image_viewer_" + showID + "_embedded", "430", "311", "8", "#fff");
						so.addVariable("i", imgstr);
						so.addParam("wmode", "transparent");
						so.addParam("menu", "false");
						so.write("image_viewer_" + showID);
						panes_viewed.push('h' + showID);
					}
				}
			}
			if (_delay > 100) {
				$('#pane_' + showID).fadeIn(_delay);
			} else {
				$('#pane_' + showID).show(_delay);
			}
			$('#block_' + showID).removeClass("homes_nav_block");
			$('#block_' + showID).addClass("homes_nav_block_selected");
			$('#block_link_' + showID).addClass("hide");
			$('#nav_info_' + showID + ' tr:even').removeClass("nav_info_hl");
			$('#nav_info_' + showID + ' tr:even').addClass("nav_info_hl_sel");
			last_pane_viewed = showID;
		}
		++x;
	}
	return false;
}

function common_goto(url) {
	window.location.href = url;	
	return false;
}

function common_setupInventorySweep(rows) {
	pages = rows - 1;
	var offset = $('#search_results_div').offset();
	/* $('#search_results_div').css({ position:"relative", top:(offset.top - 230) }); */
	$('#search_results_div').css({ position:"relative" });
	$('#search_results_link_0').addClass("inv_page_active");
	$('#link_prev').hide();
	last_link = 0;
	return true;
}

function common_doInventorySweep(row, delay, scroll_amount) {
	var _delay = 300; // default sweep speed
	var _scroll_amount = 726; // default sweep amount in pixels
	
	if (delay != undefined) {
		_delay = delay;
	}
	
	if(scroll_amount != undefined) {
		_scroll_amount = scroll_amount;
	}
	
	if(row != last_link) {
		var left = ((row - 0) * _scroll_amount) * -1;
		$('#search_results_rows').animate({ left:left }, { queue:false, duration:_delay });
		$('#search_results_link_' + last_link).removeClass("inv_page_active");
		$('#search_results_link_' + row).addClass("inv_page_active");
		
		if(row == 0) $('#link_prev').hide();
		else $('#link_prev').show();
		
		if(row >= pages) $('#link_next').hide();
		else $('#link_next').show();
		
		last_link = row;
		return true;
	}
	return false;
}

function common_toggleInAddition(siteID, blocks, delay) {
	var _delay = 300; // default sweep speed
	
	if (delay != undefined) {
		_delay = delay;
	}
	
	var currentImg = $('#inadditionimage').attr("src");

	if (typeof(currentImg) != "undefined") {
		var inadd_height = (((blocks / 3) >= 1 ? blocks / 3 : 1) * $('#in_addition div.rr_container_basics:first').height()) + $('#in_addition_header').height() + 100;
		if(currentImg.substring(currentImg.length - 8) == "plus.html") {
			$('#inadditionimage').attr("src","/content/" + siteID + "/images/inadd_minus.jpg");
			$('#in_addition').animate({ height:inadd_height }, { queue:false, duration:_delay });
			return false;
		}
		$('#inadditionimage').attr("src","/content/" + siteID + "/images/inadd_plus.jpg");
		$('#in_addition').animate({ height:"75px" }, { queue:true, duration:_delay });
	}
}	

function common_swapImage(image_container, new_image, clicked_image) {
	$(clicked_image).parent().children().removeClass("active-image");
	$(clicked_image).addClass("active-image");
	$(image_container).hide().attr('src', new_image).fadeIn(400);
	return false;
}

