$(document).ready(function(){
		
	$('#top_link').click(function () { 
	  window.scrollTo(0,0);
	  return false;
	});
	
	$('#nav li').hover(function(){
	  $(this).find('div').show();
	  $(this).find('.nav_img').addClass('over');
	},function(){
	  $(this).find('div').hide();
	  $(this).find('.nav_img').removeClass('over');
	});
	
	if ($.browser.safari) {
		$('textarea').css('resize', 'none');
		$('input.text').css('resize', 'none');
	}
	
	$('#btn-newsletter-subscription').click(function(){
		sendBulletinSubscriptionForm();
	});
	$('.caja_destacados:last').addClass("no_margin");
	
	$('#btn-contact-form').click(function(){
		sendForm($(this).parents('form:first').attr('id'));
	});
	

});
function sendBulletinSubscriptionForm(){
	if(checkFormFields('form_newsletter',1,0,'#868686','#FFF')){
		$('#form_newsletter').addAjaxLoader();
		var vars = $('#form_newsletter').serializeForm();
		$.ajax({
			   async: true,
			   type: "POST",
			   url: "_ajax.php",
			   data: "opc=sendBulletinSubscriptionForm&"+vars,
			   success: function(data){
					$.ajax({
						   async: true,
						   type: "POST",
						   url: "_ajax.php",
						   data: "opc=translate&word="+(parseInt(data)==1?"newsletter_registration_successfull":"existent_account"),
						   success: function(message){
								showAlertMessage(message,parseInt(data)==1?"info":"error");
								$('#form_newsletter').removeAjaxLoader();
								$('#form_newsletter').clearForm();
						   }
					 });
					
			   }
		 });
	}
}

function referencesSlide(index,data){
	if( $('#references_slide').length == 0)return;
	index = index == undefined||index==''?0:index;
	data = data == undefined||data==''?0:data;
	var showReferenceLogo = function(index,data){
		 if(data!=''){
			  if(index==0){
				  $('.gray_box_bottom').removeClass('hidden');
			  }
			  var logos = new Array(); 
			  logos = data.split(",");
			  var img = document.createElement("IMG");
			  img.onload = function(){
				  
				  $(this).fadeTo("fast",0);
				  $(this).css({position:'absolute',left:0,top:0});
				  if($('#references_slide img').length==0){
					  $('#references_slide').append($(img));
					  $('#references_slide').find('img:first').fadeTo("slow",1,function(){
						  if(logos.length > 1){
							  setTimeout("referencesSlide("+(index < logos.length-1?(index + 1):0)+",'"+data+"')",6000);
						  }
					  });
				  }
				  else{
					  $('#references_slide').append($(img));
					  
					  $('#references_slide').find('img:first').fadeTo("slow",0,function(){
						  $(this).remove();
					  });
					  $('#references_slide').find('img:last').fadeTo("slow",1,function(){
						  if(logos.length>1){
							  setTimeout("referencesSlide("+(index < logos.length-1?(index + 1):0)+",'"+data+"')",6000);
						  }
					  });
					  
				  }
			  };
			  img.src = 'images/references/'+logos[index];
		  }
	};
	if(data==''){
		$.ajax({
			   async: true,
			   type: "POST",
			   url: "_ajax.php",
			   data: "opc=getReferencesLogos",
			   success: function(data){
			   		showReferenceLogo.apply(this,[0,data]);
			   }
		 });
	}
	else{
		showReferenceLogo.apply(this,[index,data]);
	}
}

