jQuery.noConflict();


function inicializarPresentacion(options){

	var retorno= new Array();
	jQuery('#slider').append("<div id='"+options.baseName +"'></div>");	

	var i=1;
	
	
	
	for (i=1;i<=options.numeroSlides;i++){
		contador="";
		if(i<=9){
			contador="00"+i;
		}
		if(i>9 && i<=99){
			contador="0"+i;
		}
	
		retorno.push(options.linkBase + options.baseName +"." + contador + ".jpg");
		jQuery('#'+ options.baseName).append(
			"<a title='"+options.title + " - "+ i + " de "+ options.numeroSlides + "' href='" + options.linkBase + options.baseName +"." + contador + ".jpg'" + "rel='" + options.baseName + "'>.</a>"
		);
	
	}	
	

	
	jQuery('#'+options.baseName+' a').fancybox({	cyclic:true,
													overlayOpacity:0.8550,
													overlayColor:'#000'
												})
	jQuery("#" + options.idLauncher + "").click(function(){
		jQuery.fancybox.showActivity();
		var i=0;
		jQuery.imgpreload(retorno,{
			
			
			
			each: function()
			{
				i++;
				//console.log(i);
				if(i==5){
					jQuery.fancybox.hideActivity();
					jQuery(jQuery("#" + options.baseName + " a")[0]).trigger('click');
					//console.log("bien!");
				}
				// this = dom image object
				// callback executes when each image loads
			},
			all: function()
			{

			}
		});
		
		
		return false;
	});
	return retorno;
}

var carousel_mover;
jQuery(document).ready(function($) {	

	$.validationEngineLanguage.newLang();		
		if ($("#contacto")){
			$("#contacto").validationEngine({promptPosition:"centerRight"});
		}
		
		if ($("#miniForm")){
			$("#miniForm").validationEngine();
		}
		

	$("h4.tituloPost").click(function(){
		if ($(this).hasClass("active")) {
			$(this).removeClass('active');
			$(this).next().hide();
			//jQuery(this).next().show();
		}else{
			$(this).addClass('active');
			//jQuery(this).next().hide();
			$(this).next().show();
		}
	});
	
	$(".formHideShow #nombre").click(function(){
		$('#hideForm').slideDown();
		$('#alternate').attr('id', 'comment2');
		
	})


	
	$('#goServices')
		.click(function(){
		if( $('#servicesList').is(':hidden') ){
			$('#servicesList').fadeIn();
		}
	});
	
	
	$('#servicesList').hover(null,function(){ setTimeout(function(){ $('#servicesList').fadeOut() }, 1*1000); });
	
	
	/*if ($("#carousel-wrapper")) {		
		new Carousel('carousel-wrapper', $$('#carousel-content .slide'), $$('a.carousel-control', 'a.carousel-jumper'), {duration:1, auto:true, frequency:6, visibleSlides:1, circular:true});
	}*/
	
	var cTime;
	var cSegs = 3500;
	var numSlide = $('#carousel-content .slide').length;
	var cShow = 0;
	carousel_mover = function(){
		
		var top = cShow*180;
				
		var move_top = ( (numSlide*180) <= top ) ? '0' : '-'+top;
		
		$('#carousel-content').animate({ marginTop: move_top });
		cTime = setTimeout(function(){ carousel_mover() },cSegs);
		cShow++;
		if( move_top == '0' ){ cShow = 0; }
	};
	
	carousel_mover();

	var presentacion1={	numeroSlides:32, 
						linkBase:'presentaciones/empresa/presentacion-idea-uno.html_files/',
						baseName:'presentacion-idea-uno',
						idLauncher:'nuestra-empresa',
						title: 'Presentación Empresa'
	}

	var presentacion2={	numeroSlides:51, 
						linkBase:'presentaciones/moviles/presentacion-web-moviles.html_files/',
						baseName:'presentacion-web-moviles',
						idLauncher:'desarrollo-movil',
						title: 'Desarrollos Móviles'
	}

	inicializarPresentacion(presentacion1);
	inicializarPresentacion(presentacion2);

	// Otros
	var presentacion11={	numeroSlides:32, 
						linkBase:'presentaciones/empresa/presentacion-idea-uno.html_files/',
						baseName:'presentacion-idea-uno',
						idLauncher:'nuestra-empresa-2',
						title: 'Presentación Empresa'
	}

	var presentacion21={	numeroSlides:51, 
						linkBase:'presentaciones/moviles/presentacion-web-moviles.html_files/',
						baseName:'presentacion-web-moviles',
						idLauncher:'desarrollo-movil-2',
						title: 'Desarrollos Móviles'
	}

	inicializarPresentacion(presentacion11);
	inicializarPresentacion(presentacion21);
	
});
