$(setupFrontMainViewListing);

function setupFrontMainViewListing()
{	
	$(".MagicZoom img").each(function() {
		var img = $(this);//.find('img');
		w = $(this).width();
		h = $(this).height();			
		$(this).parent().attr('rel', 'zoom-width:'+w+'px; zoom-height:'+h+'px');// zoom-position:inner;zoom-fade:true;
	});
	
	$(".ad-thumb").click(function(){
	
		var index = $(this).prevAll().length;				
		var pic_name = $(this).attr('id');
		$(".chosen").removeClass('chosen');
		$(this).addClass('chosen');
		
		$(".MagicZoom:not(.faded)").addClass('faded');
		zoomer = $(".MagicZoom:eq("+index+")");
		zoomer.removeClass('faded');	
		
		/*
		zoomer = $(".jqzoom:eq("+index+")");		
			
		var tmpId = encode(zoomer.attr("href"), true);
		var largImg = zoomer.next('img');
		
		largImg.ready(function(){
			var large_w = $(this).width();
			var large_h = $(this).height();	
			
			
		});
		
			
			
			var epsilon = 20;
			
			// Don't Zoom It If the large Image Is not biger by epsilon
			if(large_w <= w + epsilon)
			{
				//alert(large_w + ':' + w);
				zoomer.attr('title', GLOBALS.TXT_NO_ZOOM).click(function(){return false;}).css("cursor", "auto");
				return;
			}
			//zoomer.imagezoom({ zoom_width: w, zoom_height: h, offset_x: 2, offset_y: 0 })
			
			//alert(w + ' ' + h);
			zoomer.jqzoom({
				zoomWidth: w,
				zoomHeight: h,
				position : 'right',
				yOffset : 0,
				xOffset : 10,
				title: false,
				zoomType:'reverse'
			});		
		});		
		*/
		
	});

	$(".no-image").hover(
		function(){$(this).css('font-size','18px');},
		function(){$(this).css('font-size','0px');}
	);
		
}




function addToFavorites(listing_id){
	
	//alert("adding to favorites");
	$.getJSON("/ajax/main/add-to-favorites", {listing_id: listing_id}, function(json){
		if(json.success){
			
			var jTitle = $('#content-inside .v-listing-name span:first');
			var posTitle = jTitle.position();
			
			$("#add-to-favorites").replaceWith($("#favorited-message"));
			$("#favorited-message").removeClass("hidden").fadeOut(800, function(){
				$(this).next().css('position','absolute').
				css({
					"top": posTitle.top + 'px',
					"left": (posTitle.left+jTitle.width()) + 'px'
				});
//				animate({
//					"top": posTitle.top + 'px',
//					"left": (posTitle.left+jTitle.width()) + 'px'
//					//"top": posTitle.top + 'px',
//					//"left": (posTitle.left+jTitle.width()) + 'px'
//				}, "slow");
			});
			
			
			
			
		}else{
			jAlert(json.message);
		}
	});
}
