// JavaScript Document
var next_pos;
var next_id_obj;
var next_type;
$(document).ready(function() {
	
	
	
	
	/* show and load img */
	$("img[rel='expand']").click(function(){
//		$('#vote_bug').togglePopup();
		
		showImg($(this).attr('pos'), $(this).attr('id_obj'), $(this).attr('type'));
	});

	$('img.this_img').live('click', function() {
		showImg(next_pos, next_id_obj, next_type);
	});
	//	showImg(next_pos, next_id_obj, next_type);

});


// Get the next 
function getPosition(pos)
{
	return (parseInt(pos)+1);
}

function showImg(pos, id_obj, typethis)
{
	getPositionXY(); 
	
	$('.simple_overlay:hidden').fadeIn();
	
	$("img[rel='expand']").siblings('.estateoffer_photo_ship').hide();
	$("img[rel='expand']:[pos='"+pos+"']").siblings('.estateoffer_photo_ship').show();
	$.ajax({
		url: "/photo/"+typethis+"/"+id_obj+"/"+pos+"/",
		cache: false,
		type: "POST",
		data: "pos="+pos,
		beforeSend: function(){
			$('.simple_overlay #preload').show();
			$('.simple_overlay_main_foto').append('<div class="preloaded"></div>');
		},
		success: function (data) {
			$('.simple_overlay #preload').hide();
			$('.simple_overlay_main_foto').hide().fadeIn();
			$('.simple_overlay_main_foto').html(data);
		}
	});	
	
	/* Get next img src */

	next_pos = getPosition(pos);
	if( $("img[rel='expand']:[pos='"+next_pos+"']").attr('id_obj') == undefined || $("img[rel='expand']:[pos='"+next_pos+"']").attr('type') == undefined ) next_pos = 1;
	next_id_obj = $("img[rel='expand']:[pos='"+next_pos+"']").attr('id_obj');
	next_type = $("img[rel='expand']:[pos='"+next_pos+"']").attr('type');
	
	
	/* close */
	$('.simple_overlay #close').click(function(){
		$('.simple_overlay_main_foto').slideUp();
		$(this).parent('div').fadeOut();
	});

}

