$(document).ready(function(){
	if(typeof(start_idx) != "undefined") {
		$('.tabs li').removeClass('active');
		$('.tabs li:eq('+start_idx+')').addClass('active');
		callback($('.tabs li.active a').attr('id'), $('.tabs li.active a').attr('rel'));
	}else {
		start_idx = 0;
	}
	$('.tab-content').hide();
	$('.tab-content:eq('+start_idx+')').fadeIn();
	$(".tabs > li a").click(function(){
		if(!$(this).parent('li').hasClass('active')) {
			var idx = $(".tabs > li a").index(this);
			$('.tabs li').removeClass('active');
			$(this).parent('li').addClass('active');
			$('.tab-content:eq('+idx+')').fadeIn();
			$('.tab-content').not('.tab-content:eq('+idx+')').css("display", "none");
			var type = $(this).attr('rel')
			callback($(this).attr('id'), type);
		}
		return false;
	});
	
	function callback(id, type) {
		$('#'+id+'-canvas').html('');
		switch(type){
			case "google":
				showMap(id+'-canvas');
			break;
			case "streetview":
				streetView(id+'-canvas', PropAddress);
			break;
			case "walkscore":
				$('#'+id+'-canvas').html(call_walkscore(PropAddress));
			break;
			default:
				var Elements = type.split("|");
				if(Elements[0] == 'hide') {
					for(i=1;i<Elements.length;i++) {
						if($(Elements[i]).css('display') != "none") {
							$(Elements[i]).hide();
						}
					}
					if(Elements[Elements.length-1] == "mapView") {
						mapView(id+'-canvas', Listings);
					}
				}else if(Elements[0] == 'show') {
					for(i=1;i<Elements.length;i++) {
						if($(Elements[i]).css('display') == "none") {
							$(Elements[i]).fadeIn();
						}
					}
				}
			break;
		}
		return false;
	}
});

