$(document).ready(function()
{
	var menu_selected;//almacena el menu item seleccionado
	var contact_selected;//almacena el contact item seleccionado
	
	//---------------funcion pirobox gallery--------------------------
	$().piroBox({
      my_speed: 300, //animation speed
      bg_alpha: 0.6, //background opacity
      radius: 2, //caption rounded corner
      scrollImage : false, // true == image follows the page _|_ false == image remains in the same open position
                           // in some cases of very large images or long description could be useful.
      slideShow : 'false', // true == slideshow on, false == slideshow off
      slideSpeed : 3, //slideshow
      pirobox_next : 'piro_next', // Nav buttons -> piro_next == inside piroBox , piro_next_out == outside piroBox
      pirobox_prev : 'piro_prev', // Nav buttons -> piro_prev == inside piroBox , piro_prev_out == outside piroBox
      close_all : '.piro_close' // add class .piro_overlay(with comma)if you want overlay click close piroBox
      });
	//---------------funcion fancybox------------------------------------------------- 
	$("a.reel_video").fancybox({'width':636,'height':459,'overlayOpacity':0.7,'overlayColor':'#000000','padding':5,'titleShow':'false'});
	$("a.video_popup").fancybox({'width':700,'height':430,'overlayOpacity':0.7,'overlayColor':'#000000','padding':5,'titleShow':'false'});
	//----------------------------------------------------------------------------- 
	//bottom top bar pimp
	$("<div class='transparent'></div>").appendTo("#top_bar");//fondo transp del top bar
	$("<div id='top_bar_container'></div>").appendTo("#top_bar");//container del menu y logo del top bar para centrarlos
	$('#logo,#menu').appendTo('#top_bar_container');//se insertan el elogo y menu dentro del top bar container
	$("<div class='transparent'></div>").appendTo("#bottom_bar");//fondo transp del bottom bar
	$("<div class='btnTransp'></div>").appendTo("#contact_menu li");//fondo transp del menu contactos
	$("<div class='clear'></div>").appendTo("#top_bar");//clear divs
	//$("<div class='clear'></div>").appendTo("#bottom_bar");//clear divs
	
	//video section pimp
	$("<div class='vidbtnbkgnd'></div>").appendTo("#videos_section ul li");//fondo de los botones del video menu					
	$("#videos_section ul li").hover(
										function(){$(this).children('div').css('background','#336600')},
										function(){$(this).children('div').css('background','#000000')}
										);							
	
	//funcion ppal del menu
	$("#menu li a").click(function(event)
	{
		event.preventDefault();//evita el comportamiento por defecto en el link
		if(menu_selected!=null){menu_selected.css("color","#ffffff");}
		$(this).css("color","#63bf00");
		menu_selected=$(this);
		var num=$("#menu li a").index($(this));
		$("#content_container").animate({left:1200*num*-1},"normal");
		//alert(hu);
	});
	
	//animando la galeria de imagenes y videos
	cont_height=550;//altura del contenedor
	gal_height=$("#gallery_section ul").height();//altura de la galeria de fotos que se va a mover
	vid_height=$("#videos_section ul").height();//altura de la galeria de videos que se va a mover
	g_move_counter=0;//contador de movimiento de fotos
	v_move_counter=0;//contador de movimiento de videos
	
	$("#adg").click(function(event)
	{
		if(g_move_counter+cont_height<gal_height)
		{
			$("#gallery_section ul").animate({bottom:'+='+cont_height},"normal");
			g_move_counter+=cont_height;
		}else{}
	});
	
	$("#aug").click(function(event)
	{
		if(g_move_counter-cont_height>=0)
		{
			$("#gallery_section ul").animate({bottom:'-='+cont_height},"normal");
			g_move_counter-=cont_height;
		}else{}
	});
	
	$("#adv").click(function(event)
	{
		if(v_move_counter+cont_height<vid_height)
		{
			$("#videos_section ul").animate({bottom:'+='+cont_height},"normal");
			v_move_counter+=cont_height;
		}else{}
	});
	
	$("#auv").click(function(event)
	{
		if(v_move_counter-cont_height>=0)
		{
			$("#videos_section ul").animate({bottom:'-='+cont_height},"normal");
			v_move_counter-=cont_height;
		}else{}
	});
	//contact
	contact_selected=$("#contact_menu li:first");
	contact_selected.css({"background":"#336600","border":"1px solid #63bf00"});
	$("#contact_menu li").click(function()
	{
		if(contact_selected!=null){contact_selected.css({"background":"#000000","border":"1px solid #333333"});};
		$(this).css({"background":"#336600","border":"1px solid #63bf00"});
		contact_selected=$(this);
		var numc=$("#contact_menu li").index($(this));
		$("#contact_slider").animate({top:448*numc*-1},"fast");
	});
	
	$(".submit_btn").click(function()
	{
		var btn_name=$(this).attr('name');
		var destinatario;
		if(btn_name=='nelson'){destinatario='scripts/mail_for_nelson.php';}
		else if(btn_name=='craig'){destinatario='scripts/mail_for_craig.php';}
		else if(btn_name=='info'){destinatario='scripts/mail_for_info.php'};
		var name=$("input[name=name]").val();
		var email=$("input[name=email]").val();
		var subject=$("input[name=subject]").val();
		var message=$("textarea[name=message]").val();
		var dataString='name='+name+'&email='+email+'&subject='+subject+'&message='+message;
		//alert(dataString);
		$.ajax(
		{type:"POST",url:destinatario,data:dataString,
			success:function()
			{
				$("#contact_display").html("<div id='success_msg'></div>");
				$("#success_msg").html("<h2>Contact mail sent!</h2>").append("<p>We will be in touch soon.</p><p>Please refresh the page</p>").hide().fadeIn("normal");
			}
		});
		return false;
	});
	
});

	


