$(function(){
	
	if($('body').attr('id') != 'site'){
		$('#userLeftHeading').html('<b>אפשרויות לדף זה:</b>');
		$('#addFavourite').parent().css('display', 'none');
		$('#addOpinion').parent().css('display', 'none');
	
	};
	
	var UserHeight = $('#panel-userBar').height();
	$('#panel-userBar').css('bottom', (-UserHeight) + 38);

	$('#closeUserBar').click(function(){
		var UserHeight = $('#panel-userBar').height();
		$('#panel-userBar').animate({ bottom: (-UserHeight) + 38 ,opacity: 1}, 500 );
	});
	
	$('#panel-userBar td a').click(function(){
		var id = $(this).attr('id');
		$('#userLoadingContent').show();
				
		if(	$('#panel-userBar').css('bottom') == '0px'){
			var userPanelTop = $('#panel-userBar').css('top');
			var UserHeight = $('#panel-userBar').height();
		}
		switch (id){
			
			case 'profile':
			
				$.post('/user/ajax/profile/',
					function(data){
						$('#panel-userBar').height(UserHeight);
						$('#userAjaxContent').html(data);
						var newHeight = $('#userAjaxContent').height() + 65;
						var newHeights = $('#userAjaxContent').height();
						 $('#closeUserBar').css('margin-top', newHeights-32 );
						$('#panel-userBar').animate({ bottom: 0,height:newHeight + 'px', opacity: 1}, 500 );
						$('#userLoadingContent').hide();
					}
				);
				 
			break;
			
			case 'favorites':
				$.post('/user/favorites/list/format/html' ,
					function(data){
							$('#panel-userBar').height(UserHeight);
						$('#userAjaxContent').html(data);
						var newHeight = $('#userAjaxContent').height() + 65;
						var newHeights = $('#userAjaxContent').height();
						 $('#closeUserBar').css('margin-top', newHeights-32 );
						$('#panel-userBar').animate({ bottom: 0,height:newHeight + 'px', opacity: 1}, 500 );
						$('#userLoadingContent').hide();
					}
					
				);
			break;
			case 'myLottery':
				$.post('/user/ajax/mylottery/',
					function(data){
							$('#panel-userBar').height(UserHeight);
						$('#userAjaxContent').html(data);
						var newHeight = $('#userAjaxContent').height() + 65;
						 var newHeights = $('#userAjaxContent').height(); 						 
						 $('#closeUserBar').css('margin-top', newHeights-32 );
						$('#panel-userBar').animate({ bottom: 0,height:newHeight + 'px', opacity: 1}, 500 );
						$('#userLoadingContent').hide();
					}
				);
			break;
			case 'myMail':
			case 'myMailImg':
				$.post('/user/ajax/mymail/',
					function(data){
							$('#panel-userBar').height(UserHeight);
						$('#userAjaxContent').html(data);
						var newHeight = $('#userAjaxContent').height() + 65;
						 var newHeights = $('#userAjaxContent').height(); 						 
						 $('#closeUserBar').css('margin-top', newHeights-32 );
					$('#panel-userBar').animate({ bottom: 0,height:newHeight + 'px', opacity: 1}, 500 );
						$('#userLoadingContent').hide();
					}
				);
			break;
			case 'addLottery':
				$.post('/user/ajax/addlottery/',
					function(data){
						$('#panel-userBar').height(UserHeight);
						$('#userAjaxContent').html(data);
						var newHeight = $('#userAjaxContent').height() + 65;
						var newHeights = $('#userAjaxContent').height(); 						 
						$('#closeUserBar').css('margin-top', newHeights-32 );
						$('#panel-userBar').animate({ bottom: 0,height:newHeight + 'px', opacity: 1}, 500 );
						$('#userLoadingContent').hide();
					}
				);
			break;
			case 'addFavourite':
				$.post('/user/favorites/form' , {siteID: $('#addFavourite').attr('siteID') },
					function(data){
							$('#panel-userBar').height(UserHeight);
						$('#userAjaxContent').html(data);
						var newHeight = $('#userAjaxContent').height() + 65;
						var newHeights = $('#userAjaxContent').height(); 						 
						$('#closeUserBar').css('margin-top', newHeights-32 );
						$('#panel-userBar').animate({ bottom: 0,height:newHeight + 'px', opacity: 1}, 500 );
						$('#userLoadingContent').hide();
					}
				);
			break;
			case 'addOpinion':
			
				$.get('/user/user/post/format/html/siteID/' + $('#addOpinion').attr('siteID') , function(data) {
				  		$('#panel-userBar').height(UserHeight);
						$('#userAjaxContent').html(data);
						var newHeight = $('#userAjaxContent').height() + 65;
						var newHeights = $('#userAjaxContent').height(); 						
						$('#closeUserBar').css('margin-top', newHeights-32 );
						$('#panel-userBar').animate({ bottom: 0,height:newHeight + 'px', opacity: 1}, 500 );
						$('#userLoadingContent').hide();
				});

			break;
			case 'sendFriend': 
				$.post('/user/user/sendfriend/format/dummy',{url:$(this).attr('url') , 'title': $(this).attr('urlTitle'),first:true},
					function(data){
						$('#panel-userBar').height(UserHeight);
						$('#userAjaxContent').html(data);
						var newHeight = $('#userAjaxContent').height() + 65;
						var newHeights = $('#userAjaxContent').height(); 						 
						$('#closeUserBar').css('margin-top', newHeights-32 );
						$('#panel-userBar').animate({ bottom: 0,height:newHeight + 'px', opacity: 1}, 500 );
						$('#userLoadingContent').hide();
					}
				);
			break;
			
			default:
				
				return true;
			break;
			
		};
		
		return false;
	});
});
