jQuery.noConflict();

jQuery(window).resize(function(){
	var alto_body = jQuery(window).height();
	var alto_contenido = 0;
	jQuery('#contenido').height(471);
/* 	
	if (jQuery.browser.msie){
		alto_body=alto_body;
		alto_contenido = alto_body-103;
		if (alto_contenido > 500)
			jQuery('#contenido').height(500);
		else
			jQuery('#contenido').height(alto_contenido);
	}else{
		alto_body=alto_body-10;
		alto_contenido = alto_body-103;
		if (alto_contenido > 488)
			jQuery('#contenido').height(488);
		else
			jQuery('#contenido').height(alto_contenido);
	} */
});	

jQuery(window).load(function(){
	var alto_body = jQuery(window).height();
	var alto_contenido = 0;
	jQuery('#contenido').height(471);
/* 	if (jQuery.browser.msie){
		jQuery('#menu ul').css('top', 4);
		jQuery('#menu ul').css('padding-left', 0);
		alto_body=alto_body;
		alto_contenido = alto_body-103;
		if (alto_contenido > 500)
			jQuery('#contenido').height(500);
		else
			jQuery('#contenido').height(alto_contenido);
	}else{
		alto_body=alto_body-10;
		alto_contenido = alto_body-103;
		if (alto_contenido > 488)
			jQuery('#contenido').height(488);
		else
			jQuery('#contenido').height(alto_contenido);
	} */
	
	var numpar = (jQuery('.item').length+jQuery('#previous_link').length+jQuery('#next_link').length);
	var parw = 0;
	totalw = jQuery('#monster_404').width()+jQuery('#monster_home').width()+jQuery('#monster_conctact').width();
	totalw = totalw + 2*jQuery('#monster_left1').width()+2*jQuery('#monster_right2').width()+2*jQuery('#monster_right3').width();
	totalw = totalw + jQuery('#next_link').width() + jQuery('#previous_link').width();
	totalw = totalw + 18*(numpar+1);
	
	for (i=0;i<numpar;i++){
		totalw += jQuery('.item').eq(i).outerWidth();
	}
	
	jQuery('#contenido2').width(parseInt(totalw));
	
	jQuery('.item').click(function(){
		jQuery('.rotulo').fadeOut('fast');
		jQuery(this).children('.rotulo').width(jQuery(this).width()-30);
		if(jQuery(this).children('.rotulo').children('.fondorotulo').length==0){
			jQuery(this).children('.rotulo').children('.nombre').before('<div class="fondorotulo"></div>');
			jQuery(this).children('.rotulo').children('.fondorotulo').css({
				'display' : 'none',
				'position': 'absolute',
				'top' : '0px',
				'left' : '0px',
				'width' : '100%',
				'height' : '90px',
				'background-color' : 'black',
				'z-index' : '-101'
			});
			jQuery(this).children('.rotulo').children('.fondorotulo').width(jQuery(this).children('img').width()-20);
		}
		
		jQuery(this).children('.rotulo').fadeIn('fast');
		jQuery(this).children('.rotulo').children('.fondorotulo').fadeTo('fast',0.6);
		
		//muevo el scroll
		var posicionContenido = jQuery(this).position().left-50;
		jQuery('#contenido').animate({scrollLeft : posicionContenido},1000);
		//y muevo el deslizador
		
		
		var posiciondeslizadorinicial = 2;
		var posiciondeslizadorfinal = jQuery('#barra').width()-2-jQuery('#deslizador').width();
		var carreradeslizador=posiciondeslizadorfinal-posiciondeslizadorinicial;
		var anchoscrollcontenido = jQuery('#contenido2').width()-jQuery('#contenido').width();
		
		var posiciondeslizador = posicionContenido/anchoscrollcontenido*carreradeslizador+posiciondeslizadorinicial;
		if (posiciondeslizador <= 2){
			posiciondeslizador = posiciondeslizadorinicial;
		}else if (posiciondeslizador >= posiciondeslizadorfinal){
			posiciondeslizador = posiciondeslizadorfinal;
		}else{
			posiciondeslizador = posiciondeslizador;
		}
		jQuery('#deslizador').animate({left : posiciondeslizador},1000);
		
	});
	
	jQuery('.item').mouseenter(function(){				
		jQuery('.rotulo').fadeOut('fast');
		jQuery(this).children('.rotulo').width(jQuery(this).width()-30);
		if(jQuery(this).children('.rotulo').children('.fondorotulo').length==0){
			jQuery(this).children('.rotulo').children('.nombre').before('<div class="fondorotulo"></div>');
			jQuery(this).children('.rotulo').children('.fondorotulo').css({
				'display' : 'none',
				'position': 'absolute',
				'top' : '0px',
				'left' : '0px',
				'width' : '100%',
				'height' : '90px',
				'background-color' : 'black',
				'z-index' : '-101'
			});
			jQuery(this).children('.rotulo').children('.fondorotulo').width(jQuery(this).children('img').width()-20);
		}
		
		jQuery(this).children('.rotulo').fadeIn('fast');
		jQuery(this).children('.rotulo').children('.fondorotulo').fadeTo('fast',0.6);
		
		//si el item contiene link, ponemos el borde de color rosa y sacamos letrerito
		if(jQuery(this).children('a').length){
			jQuery(this).children('a').children('img').css('border','2px solid #ff00ff');
			// jQuery(this).append('<div class="cartel_link">Click to go...</div>');
			// jQuery(this).children('.cartel_link').css(
					// {	
						// 'font' : '12px Tahoma, Sans-Serif',
						// 'padding' : '10px',
						// 'background-color':'black', 
						// 'color' : 'white',
						// 'position' : 'absolute',
						// 'top' : '10px',
						// 'left' : '10px',
						// 'display':'none'
					// });
			// jQuery(this).children('.cartel_link').fadeTo('fast', 0.6);
		}
		
	});	
	
	jQuery('.item').mouseout(function(){
		//si el item contiene link, ponemos el borde original verde y sacamos letrerito
		if(jQuery(this).children('a').length){
			jQuery(this).children('a').children('img').css('border','2px solid #00ff33');
			// jQuery(this).children('.cartel_link').fadeOut('fast');
			// jQuery(this).children('.cartel_link').detach();
		}
	});
	
	
	
	jQuery('#next_link').hover(				
		function(){				
			jQuery('#next_link').children('a').children('img').attr('src', 'http://amazinghorrorsurfing.com/wordpress/wp-content/themes/MonsterTheme/img/more_hover.gif' );
		},
		function(){				
			jQuery('#next_link').children('a').children('img').attr('src', 'http://amazinghorrorsurfing.com/wordpress/wp-content/themes/MonsterTheme/img/more.gif' );
		}	
	);

	jQuery('#previous_link').hover(
		function(){				
			jQuery('#previous_link').children('a').children('img').attr('src', 'http://amazinghorrorsurfing.com/wordpress/wp-content/themes/MonsterTheme/img/back_hover.gif' );
		},
		function(){				
			jQuery('#previous_link').children('a').children('img').attr('src', 'http://amazinghorrorsurfing.com/wordpress/wp-content/themes/MonsterTheme/img/back.gif' );
		}
	);	
	
	/*
	jQuery('.item').mouseout(function(){
		jQuery(this).children('.rotulo').fadeOut('fast');
	});*/	
	
	//if(jQuery('#monster_home').length){
		//jQuery('#monster_home').fadeIn(5000);
	//}
	//if(jQuery('#monster_contact').length){
	//	jQuery('#monster_contact').fadeIn(5000);
	//}
	jQuery('#mail_ok').show(500);
	
	//elimino las p de los post
	jQuery('.item').children('p').children('img').unwrap();
	jQuery('.item').children('p').children('object').unwrap();
	jQuery('.item').children('p').children('a').unwrap();
	jQuery('#telon').fadeOut(1000);
	
	//Hago links en ventana nueva para aquellos que esten en items
	jQuery('.item').children('a').attr('target', '_blank');

	
	
	//funcionamiento del deslizante
	jQuery('#contenido').css({
		'overflow' : 'hidden' // change to hidden for JS users
	});
  
  
	jQuery('#deslizador').mousedown(function (event) {
	jQuery(this)
	  .data('down', true) // a flag indicating the mouse is down
	  .data('x', event.clientX) // the current mouse down X coord
	  .data('scrollLeft', this.scrollLeft) // the current scroll position
	  .data('inileft', jQuery(this).position().left);
	// return false to avoid selecting text and dragging links within the scroll window
	//alert(jQuery(this).data('x'));
	return false;
	}).mouseup(function (event) {
	// on mouse up, cancel the 'down' flag
	jQuery(this).data('down', false);
	}).mousemove(function (event) {
		// if the mouse is down - start the drag effect
		if (jQuery(this).data('down') == true) {
		  // this.scrollLeft is the scrollbar caused by the overflowing content
		  // the new position is: original scroll position + original mouse down X - new X
		  // I'd like to see if anyone can give an example of how to speed up the scroll.
		  
		  //alert(event.clientX);
			var posiciondeslizador = jQuery(this).data('inileft')+event.clientX-jQuery(this).data('x');
			var posiciondeslizadorinicial = 2;
			var posiciondeslizadorfinal = jQuery('#barra').width()-2-jQuery('#deslizador').width();
			var carreradeslizador=posiciondeslizadorfinal-posiciondeslizadorinicial;
			
			if (posiciondeslizador <= 2){
				posiciondeslizador = posiciondeslizadorinicial;
			}else if (posiciondeslizador >= posiciondeslizadorfinal){
				posiciondeslizador = posiciondeslizadorfinal;
			}else{
				posiciondeslizador = posiciondeslizador;
			}
			var anchoscrollcontenido = jQuery('#contenido2').width()-jQuery('#contenido').width();
			var posicionContenido = (posiciondeslizador-posiciondeslizadorinicial)/carreradeslizador*anchoscrollcontenido;
			jQuery(this).css('left', posiciondeslizador);
			
		  //(jQuery(this).left() + jQuery(this).data('x') - event.clientX);
		}
	});
	
	
	jQuery('*').mousewheel(function (event, delta) {
		// now attaching the mouse wheel plugin and scroll by the 'delta' which is the
		// movement of the wheel - so we multiple by an arbitrary number.
		//jQuery('#contenido').scrollLeft(jQuery('#contenido').scrollLeft()-delta * 30);
				//muevo el scroll
		var posicionContenido = jQuery('#contenido').scrollLeft()-delta * 30;
		jQuery('#contenido').scrollLeft(posicionContenido);
		//y muevo el deslizador
		
		
		var posiciondeslizadorinicial = 2;
		var posiciondeslizadorfinal = jQuery('#barra').width()-2-jQuery('#deslizador').width();
		var carreradeslizador=posiciondeslizadorfinal-posiciondeslizadorinicial;
		var anchoscrollcontenido = jQuery('#contenido2').width()-jQuery('#contenido').width();
		
		var posiciondeslizador = posicionContenido/anchoscrollcontenido*carreradeslizador+posiciondeslizadorinicial;
		if (posiciondeslizador <= 2){
			posiciondeslizador = posiciondeslizadorinicial;
		}else if (posiciondeslizador >= posiciondeslizadorfinal){
			posiciondeslizador = posiciondeslizadorfinal;
		}else{
			posiciondeslizador = posiciondeslizador;
		}
		jQuery('#deslizador').css('left', posiciondeslizador);
		
		
	});
	
	
	jQuery('*').mousemove(function (event) {
	if (jQuery('#deslizador').data('down') == true){
		// this.scrollLeft is the scrollbar caused by the overflowing content
	  // the new position is: original scroll position + original mouse down X - new X
	  // I'd like to see if anyone can give an example of how to speed up the scroll.
	  
	  //alert(event.clientX);
		var posiciondeslizador = jQuery('#deslizador').data('inileft')+event.clientX-jQuery('#deslizador').data('x');
		var posiciondeslizadorinicial = 2;
		var posiciondeslizadorfinal = jQuery('#barra').width()-2-jQuery('#deslizador').width();
		var carreradeslizador=posiciondeslizadorfinal-posiciondeslizadorinicial;
		
		if (posiciondeslizador <= 2){
			posiciondeslizador = posiciondeslizadorinicial;
		}else if (posiciondeslizador >= posiciondeslizadorfinal){
			posiciondeslizador = posiciondeslizadorfinal;
		}else{
			posiciondeslizador = posiciondeslizador;
		}
		var anchoscrollcontenido = jQuery('#contenido2').width()-jQuery('#contenido').width();
		var posicionContenido = (posiciondeslizador-posiciondeslizadorinicial)/carreradeslizador*anchoscrollcontenido;
		jQuery('#deslizador').css('left', posiciondeslizador);
		jQuery('#contenido').scrollLeft(posicionContenido);
	}
	});

	jQuery('*').mouseup(function (event) {
		jQuery('#deslizador').data('down', false);
	});
	
/* 	jQuery('#barra').click(function(){
		var posiciondeslizador = jQuery('#deslizador').position().left+150;
		var posiciondeslizadorinicial = 2;
		var posiciondeslizadorfinal = jQuery('#barra').width()-2-jQuery('#deslizador').width();
		var carreradeslizador=posiciondeslizadorfinal-posiciondeslizadorinicial;
		
		if (posiciondeslizador <= 2){
			posiciondeslizador = posiciondeslizadorinicial;
		}else if (posiciondeslizador >= posiciondeslizadorfinal){
			posiciondeslizador = posiciondeslizadorfinal;
		}else{
			posiciondeslizador = posiciondeslizador;
		}
		var anchoscrollcontenido = jQuery('#contenido2').width()-jQuery('#contenido').width();
		var posicionContenido = (posiciondeslizador-posiciondeslizadorinicial)/carreradeslizador*anchoscrollcontenido;
		jQuery('#deslizador').animate({left : posiciondeslizador},400);
		jQuery('#contenido').scrollLeft(posicionContenido);
	}); */
	
	
});	



function parpadeos(){
	if(jQuery('#monster_home').length){
		jQuery('#monster_home').fadeTo(1500, 0.7);
		jQuery('#monster_home').fadeTo(500, 1);
	}else if(jQuery('#monster_contact').length){
		jQuery('#monster_contact').fadeTo(1500, 0.7);
		jQuery('#monster_contact').fadeTo(500, 1);
	}else if(jQuery('#monster_404').length){
		jQuery('#monster_404').fadeTo(1500, 0.7);
		jQuery('#monster_404').fadeTo(500, 1);
	}
}
setInterval("parpadeos()", 2000);



