$(document).ready( function()
{
	$("#index_post a").click(function () 
	{
		$.scrollTo("#div_hazanas",800);
	})
	$("#heroes_button").overlay(
	{
		target:".overlay_heroes",
		mask:{color:'#000',opacity:0.9},
		closeOnClick:false,
		top:230
	});
	$(".hazanas_gallery_item").live("click", function()
	{
		$(this).overlay(
		{
			target:".overlay_design",
			mask:{color:'#000',opacity:0.9},
			load: true
		});
	});
	
	hazanas_gallery_display();
	xajax.call( 'twitter_call', { mode:'asynchronous'} ); //---- CALL ASYNC FUNCTION
});
var $gallery_page_ID			= 0;
var $gallery_item_count		= 1;
var $gallery_array				= [];

function scroll_to($scroll_div)
{
	$.scrollTo($scroll_div,800);
}

function hazanas_display_item($item_ID)
{
	var $item_array		= eval('('+xajax_gallery_item_display($item_ID)+')');

	var $gallery				= "";
	var $gallery_count		= -1;
	if ($item_array[0].gallery != null) 
			$gallery_count = $item_array[0].gallery.length;
	if ($item_array[0].field3 == "Web")
	{
		var $html		= '	<div id="display_gallery_item">'+
		'							<div class="gallery_webtype_left float_left">'+
		'								<img src="./userContent/'+$item_array[0].thumbnail+'" width="230" height="200" />'+
		'							</div>'+			
		'							<div class="gallery_webtype_right float_left">'+
		'								<h2>'+$item_array[0].field1+'</h2>'+
		'								<h3><b>Cliente: </b>'+$item_array[0].field2+'</h3>'+
		'								<h3>'+$item_array[0].field3+'</h3>'+
		'								<p>'+$item_array[0].field4+'</p>'+
		'								<small><b>Tecnolog&iacute;a</b> '+$item_array[0].field5+'</small>'+
		'								<a href="http://'+$item_array[0].field6+'" target="_blank">Visitar Sitio ></a>'+
		'							<div>'+
		'						<div>';
	}
	else
	{
		var $html		= '	<div id="display_gallery_item">'+
		'							<div class="gallery_designtype_left float_left">'+
		'								<h2>'+$item_array[0].field1+'</h2>'+
		'								<h3><b>Cliente: </b>'+$item_array[0].field2+'</h3>'+
		'								<h3>'+$item_array[0].field3+'</h3>'+
		'							</div>'+			
		'							<div class="gallery_designtype_right float_left">';
		$html 	+= '				<img src="./userContent/'+$item_array[0].gallery+'" width="600" height="385" />';
		$html += 	'			<div>'+
						'		<div>';
	}
	$(".overlay_design_text").html($html);
}


function hazanas_gallery_display()
{
	//---- INGRESO DE PRODUCTOS ACA EN UN ARRAY
	$gallery_array						= [];
	var $gallery_json_array		= eval('('+xajax_gallery_json_array($gallery_page_ID)+')');
	$gallery_item_count				= $gallery_json_array.rowcount;
	$gallery_array						= $gallery_json_array;			
	
	
	var $result							= "";
	setTimeout("hazanas_gallery_display_timeout("+0+")",300 );
}

function hazanas_gallery_display_timeout($i)
{
	var		$current_ID		= $gallery_array[$i].field0;
	$html		= 	'<div class="hazanas_gallery_item" id="gallery_item'+$i+'" >'+
							'	<img src="./userContent/'+$gallery_array[$i].thumbnail+'" width="230" height="200" alt="'+$gallery_array[$i].thumbnail+'"/>'+
							'	<div class="hazanas_gallery_item_detail">'+
							'		<div class="hazanas_gallery_item_detail_item"><b>'+$gallery_array[$i].field1+'</b></div>'+
							'		<div class="hazanas_gallery_item_detail_item">'+$gallery_array[$i].field2+'</div>'+
							'		<div class="hazanas_gallery_item_detail_item">'+$gallery_array[$i].field3+'</div>'+
							'	</div>'+
							'</div>';
	$("#hazanas_gallery_container").append($html)
	$("#gallery_item"+$i).fadeIn();
	$("#gallery_item"+$i).bind('click',function (){
		hazanas_display_item($current_ID);
	});
	
	if ($i < ($gallery_item_count - 1))
	{
		$i++;		
		setTimeout("hazanas_gallery_display_timeout("+$i+")",300 );
	}
}

function hazanas_gallery_next_page($i)
{
	if ($i >= 0)
	{
		$("#gallery_item"+$i).fadeOut();
		$i--;
		setTimeout("hazanas_gallery_next_page("+$i+")",200 );
	}
	else
	{
		$("#hazanas_gallery_container").html("");
		if ($gallery_item_count == 8)
			$gallery_page_ID++
		else	
			$gallery_page_ID = 0;
		hazanas_gallery_display();
	}
}
