$(document).ready(function() {

	$("#flecha_iz").hide();
	$('a.panel, area').click(function () {
		$("#flecha_iz, #flecha_de").hide();
		$('a.panel').removeClass('selected');
		$(this).addClass('selected');
		current = $(this);
		
		var num = parseInt( $(this).attr( "href" ).substr( 5 ) );
		var max = $(".panel").length;
		
		if ( num == 6 ) $("#item6 div.content").css("display", "block");
		
		$('#wrapper').scrollTo($(this).attr('href'), 800, {onAfter:function(i){
			if ( num == 1 ){
				$("#flecha_de").show();
			}else if( num == max ){
				$("#flecha_iz").show();
			}else{
				$("#flecha_iz, #flecha_de").show();
			}
			
			/*if ( num != 6 ) $("#item6 div.content").css("display", "none");*/
		} });

		
		if ( num != 6 ) $("#item6 div.content").css("display", "none");
		return false;
	});

	$('#sliderPorta').bxSlider({
		/*displaySlideQty: 8,
		moveSlideQty: 4, */
		displaySlideQty: 5,
		moveSlideQty: 3,
		width: 900,
		controls: false
	});

	$('.sliderCampanas').bxSlider({
		mode: 'vertical',
		pager: true,
		controls: false
	});

	$('#slider').bxSlider({
		mode: 'vertical',
		pager: true,
		controls: false
	});


	clickFlecha();

	//Full Caption Sliding (SOCIOS)
	$('.socios2.captionfull2').hover(function(){
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({top:'-255px'},{queue:false,duration:300});
	});

	//Full Caption Sliding (SOCIOS)
	$('.socios.captionfull2').hover(function(){
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({top:'-255px'},{queue:false,duration:300});
	});

	//Full Caption Sliding (Hidden to Visible)
	$('.equipo.captionfull').hover(function(){
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({top:'-160px'},{queue:false,duration:300});
	});


	/** Contacto **/
	$(".btn-slide").click(function(){
		$("#panel").slideToggle("slow");
		$(this).toggleClass("active"); return false;
	});

	$(".parte_equipo").click(function(){
		$("#panel").slideToggle("slow");
		$(".btn-slide").toggleClass("active"); return false;
	});

	$("#commentForm").validate({
         rules: {
            'nombre': { required: true, minlength: 1 },
            'correo': { required: true, email: true },
            'mensaje': { required: true }
         },
         messages: {
            'nombre': '',
            'correo': '',
            'mensaje': ''
         },
         debug: true,
         errorElement: 'div',
         submitHandler: function(form){
            var nombre  = $("input[name=nombre]").val();
            var correo  = $("input[name=correo]").val();
            var mensaje = $("textarea[name=mensaje]").val();

            $("#formulario").fadeOut("slow", function(){
               $("#res").html( "<img src='images/icon/ajax_loading.gif' style='width: 24px;' /> Enviando ...." );
            });

            $.ajax({
               type: "POST",
               url: "../php/add-contacto.php",
               data: "nombre=" + nombre + "&correo=" + correo + "&mensaje=" + mensaje,
               dataType: "json",
               success: function( res ){
                  $("#res").html( "<img src='images/icon/ok.png' style='width: 24px;' /> Mensaje enviado.<br><br><a href='javascript: nuevo();'>Enviar nuevo contacto</a>" );
               }
            });
         }
      });

      $("#cnombre,#ccorreo,#cmensaje").click(function(){
         $(this).attr( "value", "" );
      });

      /** Fin Contacto **/

		// Accordion Demo #2
      $('#accordion2').accordionza({
         autoPlay: false,
         //autoRestartDelay: 3000,
         slideDelay: 3000,
         slideEasing: 'easeOutCirc',
         slideSpeed: 250,
         slideTrigger: 'mouseover',
         slideWidthClosed: 100
      });

      /*campanaDet( "lacuarta" );*/
});

function clickFlecha(orientacion){
	var pos = -1;
	if ( orientacion == "iz" ) pos = -2;
	if ( orientacion == "de" ) pos = 0;

	var i = parseInt( $('a.panel.selected').attr("href").substr( 5 ) )+pos;
	$('a.panel').eq(i).trigger('click');
}

function mostrar(i){
	$(".content div.bloque").css("display", "none");
	$("#"+i).fadeIn(2000);
}

function nuevo(){
	$("#res").html("");
	$("#cnombre").attr( "value", "Nombre" );
	$("#ccorreo").attr( "value", "Correo" );
	$("#cmensaje").attr( "value", "Mensaje" );
	$("#formulario").fadeIn();
}

function visibleSlider(){
	$("#campanasDetalleTMP").hide();
	/*$("#campanasDetalle").css( "visibility", "visible" );*/
	$("#campanasDetalle").css( "display", "block" );
	$('.sliderCampanas').bxSlider({
		mode: 'vertical',
		pager: true,
		controls: false
	});
}

function campanaDet( camp ){

	$("#campanasDetalle").hide();
	$("#campanasDetalleTMP").show();
	
	$("#portafolio_thumb #sliderPorta a").each(function(){
		//alert( $(this).attr( "href" ) + " ; " + camp + " ; " + $(this).attr( "href" ).search( camp ) );
		if ( $(this).attr( "href" ).search( camp ) != -1 ){
			$(this).attr( "class", camp + "_activa" );
		}else{
			var clase = $(this).attr( "class" ).split("_");
			$(this).attr( "class", clase[0] );
		}
	});

	$.ajax({
		type: "POST",
		url: "campanasHTML/" + camp + ".html",
		dataType: "html",
		success: function( res ){
			/*$("#campanasDetalle").css( "visibility", "hidden" );*/
			
			$("#campanasDetalle").html( res );

			setTimeout( 'visibleSlider()' , 1000 );
		}
	});
}

function campanasCliente( c ){
	clickFlecha("de");
	campanaDet(c);
}

function campanasClienteActualidad( c ){
	clickFlecha("de");
	clickFlecha("de");
	clickFlecha("de");
	clickFlecha("de");
	campanaDet(c);
}
