Effect.BlindRight = function(element) {
  element = $(element);
  var elementDimensions = element.getDimensions();
  return new Effect.Scale(element, 100, Object.extend({
    scaleContent: false,
    scaleY: false,
    scaleFrom: 0,
    scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
    restoreAfterFinish: true,
    afterSetup: function(effect) {
      effect.element.makeClipping().setStyle({
        width: '0px',
        height: effect.dims[0] + 'px'
      }).show();
    },
    afterFinishInternal: function(effect) {
      effect.element.undoClipping();
    }
  }, arguments[1] || { }));
};

Effect.BlindLeft = function(element) {
  element = $(element);
  element.makeClipping();
  return new Effect.Scale(element, 0,
    Object.extend({ scaleContent: false, 
      scaleY: false, 
      restoreAfterFinish: true,
      afterFinishInternal: function(effect) {
        effect.element.hide().undoClipping();
      } 
    }, arguments[1] || { })
  );
};


function showAllCategories() {
/*
	$$('.category').each(	function(e) {
		Effect.BlindUp(e, {duration:.5});
	});
*/

	if ($('showAllLink').hasClassName('allNotChosen')) {

		$('showPopularLink').removeClassName('popularChosen');
		$('showPopularLink').addClassName('popularNotChosen');
	
		$('showAllLink').removeClassName('allNotChosen');
		$('showAllLink').addClassName('allChosen');
	
	
		Effect.BlindUp('popularWrapper', {duration:.5});
		
		Effect.BlindDown('allCategories', {duration:.5});
	}
}

function showPopularCategories() {

	if ($('showPopularLink').hasClassName('popularNotChosen')) {
		$('showPopularLink').removeClassName('popularNotChosen');
		$('showPopularLink').addClassName('popularChosen');
	
		$('showAllLink').removeClassName('allChosen');
		$('showAllLink').addClassName('allNotChosen');
	
	
		Effect.BlindUp('allCategories', {duration:.5});
		Effect.BlindDown('popularWrapper', {duration:.5});
	}
/*
	$$('.category').each(	function(e) {
		Effect.BlindDown(e, {duration:.5, queue: {position:'front', scope:'pops'}});
	});
*/
}


function startBizNameRollover(bid, cid, left) {
	id = showBizNameRollover.delay(.4, bid, cid, left);

	$('business_'+bid).rollover = id;
}

function endBizNameRollover(bid) {
	if ($('business_'+bid).rollover != '') {
		window.clearTimeout($('business_'+bid).rollover);
		if ($('detailFloater') && $('detailFloater').visible()) {
			hideFloater('', 'hide', .1);
		}
	}
}

function showBizNameRollover(bid, cid, left) {

	biz = $('business_'+bid);
	map = $('googleMap').map;

	if (left == 1) {
		ol = 170;
	} else {
		ol = -250;
	}

	switch (cid) {
		case 1:
			cloneOnWhich = 2;
			break;
		case 2:
			cloneOnWhich = 1;
			break;
		case 3:
			cloneOnWhich = 4;
			break;
		case 4:
			cloneOnWhich = 3;
			break;
		default:
			cloneOnWhich = 1;
	}

	showDetailFloater({
		clonepos:		'category_'+cloneOnWhich,
		title:		'',
		msg:			decodeURIComponent(biz.getAttribute('popupDetails')),
		sw:			true,
		sh:			true,
		ol:			0,
		ot:			0,
		duration:		.18,
		hideClose:	true,
		animation:	'appear',
		borderStyle:	'border: none',
		contentStyle:	'border: 1px solid #F4D838;background:#f6f6f6;'
	});
	if (biz.marker != null) {
		GEvent.trigger(biz.marker, "click");
	}
//	$('googleMap').map.setCenter(new GLatLng(biz.getAttribute('latitude'), biz.getAttribute('longitude')), 13);
	if (biz.getAttribute('latitude') != '') {
		map.panTo(new GLatLng(biz.getAttribute('latitude'), biz.getAttribute('longitude')));
		map.setZoom(13);
	} else {
//		alert('create now');
		createMarkerForBusiness(bid, true);
	}

/*
	showDetailFloater({
		clonepos:		'business_'+bid,
		title:		'',
		msg:			$('business_'+bid).getAttribute('popupDetails'),
		ol:			ol,
		ot:			-50,
		w:			200,
		h:			100,
		sw:			false,
		sh:			false,
		duration:		.18,
		hideClose:	true,
		animation:	'appear',
		borderStyle:	'border: 10px solid rgba(66, 84, 132, 0.4);',
		contentStyle:	'border: 1px solid rgba(66, 84, 132);background:#FDFBE5;'
	});
*/
//	endBizNameRollover(bid);
}

function createMarkerForBusiness(bid, scrollTo) {
	biz = $('business_'+bid);
//alert('creating for '+bid+'('+biz.getAttribute('postaladdress')+')');
	map = $('googleMap').map;
	
	var geocoder = new GClientGeocoder();

	geocoder.getLatLng(biz.getAttribute('postaladdress'), function(point) {
		if (point) {
			biz.setAttribute('latitude', point.lat());
			biz.setAttribute('longitude', point.lng());
//			alert(biz.getAttribute('latitude'));

			var marker = new GMarker(point, {title:biz.getAttribute('businessname'), draggable: false});
			map.addOverlay(marker);
			GEvent.addListener(marker, "click", function() {
				map.openInfoWindowHtml(point, decodeURIComponent(biz.getAttribute('markercontent')), {maxWidth:'175'});
			});
			biz.marker = marker;

			if (scrollTo != null) {		
				GEvent.trigger(marker, "click");
				map.panTo(new GLatLng(biz.getAttribute('latitude'), biz.getAttribute('longitude')));
				map.setZoom(13);
			}			
		}
	});
}

function toggleYourMind() {
	if ($('yourMind').visible()) {
		Effect.BlindUp('yourMind', {duration:.15});
	} else {
		Effect.BlindDown('yourMind', {duration:.3, afterFinish:function() {
			$('yourMindField').focus();
		}});
	}
}

function update_member_status() {
	var status_message = $F('yourMindField');
	if (status_message != "") {
		$('yourMind').hide();
		$('yourMindProgress').update("<img src=\"/images/loading_icon/loading_div_transp.gif\" style=\"margin-right:15px;\"/> One moment...");
		$('yourMindProgress').show();
		new Ajax.Request('/updater/member/update_member_status.inc.php', {
			method: 'post',
			parameters: {
				message:status_message
			},
			onSuccess: function(transport) {
				$('yourMindProgress').update("<img src=\"/images/icons/fugue/icons/tick-circle.png\"/> Your status has been updated!");
				window.setTimeout(function() {
					$('yourMindProgress').fade();				
				}, 6000);
			},
			onFailure: function(transport) {
				alert('An unknown error occurred.');
			}
		});
	} else {
	
	}	
}

function togglefeedhide(cname) {
	$A(document.getElementsByClassName(cname)).each(Element.hide);
	$(cname).innerHTML = '<a href="javascript:void(0)" onclick="togglefeedshow(\''+cname+'\')">+ Show '+cname+'</a> ';
}
function togglefeedshow(cname) {
	$A(document.getElementsByClassName(cname)).each(Element.show);
	$(cname).innerHTML = '<a href="javascript:void(0)" onclick="togglefeedhide(\''+cname+'\')">- Hide '+cname+'</a> ';
}

function post_status_comment(status_id) {
	var status_comment = $('status_comment_'+status_id).value;

	if(status_comment != ''){
	 $('status_comments_'+status_id).innerHTML = '<div align="center"><strong>LOADING<BR><img src="/images/loading_icons/loading_div.gif"></strong></div>';
		new Ajax.Updater('status_comments_'+status_id, '/updater/member/post_status_comment.php', {
			parameters: {status_id:status_id, status_comment: status_comment}
		});
		
	} else {
	
		alert("You Didn't Type Anything!");
		
	}
}

function delete_status_comment(comment_id, status_id) {

	 $('status_comments_'+status_id).innerHTML = '<div align="center"><strong>LOADING<BR><img src="/images/loading_icons/loading_div.gif"></strong></div>';
		new Ajax.Updater('status_comments_'+status_id, '/updater/member/delete_status_comment.php', {
			parameters: {status_id:status_id, comment_id: comment_id}
		});
	
}