/* My web code (victor) */


if(window.ixedit){ixedit.deployed = true};
	if(window.jQuery){jQuery(function(){
		(function(){ var target = jQuery('div#content'); target.prepend('<div id="start"></div><div id="arrows"><ul><li id="arleft"><a rel="" id="anchor2" class="anchorLink2">navegar a la izquierda</a></li><li id="arright"><a rel="" id="anchor3" class="anchorLink3">navegar hacia la derecha</a></li></ul></div>'); })();
	})};
	
	/* ------ Code generated by IxEdit (ixedit.com). ------ 
	if(window.ixedit){ixedit.deployed = true};
	if(window.jQuery){jQuery(function(){
		(function(){ setTimeout(function(){var target = jQuery('div#alerta'); target.fadeOut(500)}, 5000); })();
	})};*/

$(function() {
  $.nyroModalSettings({
	processHandler: function(settings) {
	  var from = settings.from;
	  if (from && from.href && from.href.indexOf('http://www.youtube.com/watch?v=') == 0) {
		$.nyroModalSettings({
		  type: 'swf',
		  height: 355,
		  width: 425,
		  url: from.href.replace(new RegExp("watch\\?v=", "i"), 'v/')
		});
	  }
	}
  });
});


function buscar_indice(delante){
			/*alert('post1: '+ $('#post-1').offset().left);
			alert('post2: '+ $('#post-2').offset().left);
			alert('post3: '+ $('#post-3').offset().left);
			alert('post4: '+ $('#post-4').offset().left);
			alert('post5: '+ $('#post-5').offset().left);
			alert('post6: '+ $('#post-6').offset().left);
			alert('post7: '+ $('#post-7').offset().left);
			alert('post8: '+ $('#post-8').offset().left);
			alert('post9: '+ $('#post-9').offset().left);
			alert('post10: '+ $('#post-10').offset().left);
			alert('post11: '+ $('#post-11').offset().left);
			alert('about: '+ $('#about').offset().left);

	/*lultim ha de ser el footer position*/
		var margen = 20;		
			
		cadena = new Array (0, $('#post-2').offset().left - margen, $('#post-3').offset().left - margen,$('#post-4').offset().left - margen,$('#post-5').offset().left - margen,$('#post-6').offset().left - margen,$('#post-7').offset().left - margen,$('#post-8').offset().left - margen,$('#post-9').offset().left - margen,$('#post-10').offset().left - margen,$('#post-11').offset().left - margen,$('#about').offset().left - margen);
		var donde = $('#start').offset().left; 
		
		var elements = cadena.length;
		
		if (donde == 0 && delante == true)
			return(cadena[1]);
		
		if (donde == 0 && delante == false)
			return(0);
			
		for(i=0;i<elements;i++){
			
			if(cadena[i]>donde)
			{	
				if (delante == true)
					return cadena[i];
				else		
					return cadena[i-1];	
			}
			else if(cadena[i] == donde)
			{
				if (delante == true)	
					return cadena[i+1];
				else{		
					return cadena[i-1];				
				}
			}

}
return 0
}




/*******

	***	Anchor Slider by Cedric Dugas   ***
	*** Http://www.position-absolute.com ***
	
	Never have an anchor jumping your content, slide it.

	Don't forget to put an id to your anchor !
	You can use and modify this script for any project you want, but please leave this comment as credit.
	
*****/



$(document).ready(function() {
	$("a.anchorLink").anchorAnimate()	
	$("a.anchorLink2").anchorAnimate2()	
	$("a.anchorLink3").anchorAnimate3()		
});

jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 3100
	}, settings);	
	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			
			var destination = $(elementClick).offset().left;
			$("html:not(:animated),body:not(:animated)").animate({ scrollLeft: destination - 100}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}

jQuery.fn.anchorAnimate3 = function(settings) {

 	settings = jQuery.extend({
		speed : 1100
	}, settings);	
	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()

			var dondeVoy = buscar_indice(true); 
			$("html:not(:animated),body:not(:animated)").animate({ scrollLeft: dondeVoy}, settings.speed, function() {
				//window.location.hash = elementClick
			});
			
		  	return false;
		})
	})
}


jQuery.fn.anchorAnimate2 = function(settings) {

 	settings = jQuery.extend({
		speed : 1100
	}, settings);	
	
	return this.each(function(){
	var caller = this
	$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			
			
			var dondeVoy = buscar_indice(false); 
			$("html:not(:animated),body:not(:animated)").animate({ scrollLeft: dondeVoy}, settings.speed, function() {
				//window.location.hash = elementClick
			});
			
			
			
		  	return false;
		})
	})
}


