var ImgAct
var HC = 0
/******************************************************/
function rescaleFicha(){
	var mi_ancho = document.documentElement.offsetWidth;
	var mi_alto = document.documentElement.offsetHeight;
	/**/
	if (true){
		if (mi_ancho > 1024) {
			var anchoCostados =Math.round((mi_ancho - 986)/3)
			$('.ficha .fleft').css('width',anchoCostados+'px')
			$('.ficha .fright').css('width',anchoCostados+'px')
			
			var anchoContentBox = anchoCostados*2 + $('.ficha .fcenter').width()
			$('.contentBox').css('width',anchoContentBox+'px')
		}else{
			$('.ficha .fleft').css('width',12+'px')
			$('.ficha .fright').css('width',12+'px')
			$('.contentBox').css('width',1006+'px')
		}
	}
	/**/
	if (true){
		if (mi_alto < 535) {
			$('html').css('overflow','scroll')
		}else{
			$('html').css('overflow','hidden')
		}
	}
	/*CENTRADO VERTICAL*/
	if (true){
		var altoCent = Math.round((mi_alto - 535)/2)
		if (altoCent <0) altoCent = 0;
		$('.contentBox').css('margin-top',altoCent+'px')
	}
}
/******************************************************/
function HeaderCurrent(cur){
	var i=0; /*var cur=0;*/
	$('.headerBotonera a').each(function(){ 
		if (i==cur) $(this).addClass('current');
		if(cur==2)
		{
			HC = 1;
		}
		i++
	});
}
/******************************************************/
var end=true
function swapImagesLoc(num){
  if (!end) return;
  end = false
  //
  var $active = $('.fichaImgContIn .active');
  var $next = $('.fichaImgContIn .imgCont').eq(num);
  //
  $active.fadeOut(200);
  $active.removeClass('active');
  //
  $next.fadeIn(200, 
	 function(){
		 end = true;
		 $next.addClass('active');
		 ImgAct = num
	 }
  );
  var epi = $('img', $next).attr("alt")
  $('.fichaImgEpigrafe').html(epi)
}
/******************************************************/
$(document).ready(function(){
	/*JQ PLUGINS*/
	//$('.modal').nyroModal({ width: 570});
	$('.box_scroll').each(function(){ 
		if (!$(this ).hasClass("JSplano")){
			//SI NO ES PLANO
			$(this).jScrollPane({showArrows:false});
		}else{
			//SI ES PLANO
			if ($('.thCont', this ).length > 1){
				$(this).jScrollPane({showArrows:false});
			}
		}
	});
	//
	$('.lbox a').lightBox();
	/******************************************************/
	/*RESIZE*/
	function resizeWindow( e ) { 
		rescaleFicha() 
	};
	rescaleFicha();
	$('.contentBox').css('visibility', 'visible');
	/**/
	$(window).bind("resize", resizeWindow);
	/******************************************************/
	/*IMGFICHA*/
	var cantFot = 0;
	$('.fichaImgContIn .imgCont').each(function(){	
		cantFot++
    });	
	var cantFotTh = 0;
	$('.JSthFoto .thCont').each(function(){	
		cantFotTh++
    });	
 	//
	$('.fichaImgContIn .imgCont').hide()		
	swapImagesLoc(0)
	//						   
	$('.JSthFoto .thCont').click(function(){
		var imgIndex = $(this).parent().children().index(this);
		swapImagesLoc(imgIndex)
    });	
	$('.JSplano .thCont').click(function(){
		var imgIndex = $(this).parent().children().index(this);
		swapImagesLoc(cantFotTh + imgIndex)
    });			
	/******************************************************/
	//BLUR FOCUS & SELECTABLE
	$('a').click(function(){
		$(this).blur();  
		$(this).disableTextSelect();
	});
	$('img').each(function(){	
		$(this).blur();  
		$(this).disableTextSelect();
	});
	/******************************************************/
	var out = 0
	$('.imgCont').mouseover(function(){
		$('.fichaImgContOut .ampliar').addClass('JSvisible');
		out++
    });	
	$('.fichaImgContOut .ampliar').mouseover(function(){
		$('.fichaImgContOut .ampliar').addClass('JSvisible');
		out++
    });	
	$('.imgCont').mouseout(function(){
		out --
		if (out < 1){
			out = 0
			$('.fichaImgContOut .ampliar').removeClass('JSvisible');
		}
    });
	$('.fichaImgContOut .ampliar').mouseout(function(){
		out --
		if (out < 1){
			out = 0
			$('.fichaImgContOut .ampliar').removeClass('JSvisible');
		}
    });
	
	/*LE RESTO UNO, PORQUE SINO AUTOMÁTICAMENTE TOMA EL VIDEO Y MUESTRA MAL LA IMAGEN AL AMPLIARLA*/
	$('.fichaImgContOut .ampliar').click(function(){
		$('.fichaImgContIn a').eq(ImgAct-HC).click()
	});
	/******************************************************/
	/*BROWSER DETECTION*/
	/*
	$.browser.msie6 =($.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent));
	if( $.browser.msie6 && !/MSIE 8\.0/i.test (window.navigator.userAgent)) {
		//IE 6
	}	else if ($.browser.msie && (jQuery.browser.version > 6.9999) && (jQuery.browser.version < 7.9999) ) {
		//IE 7
	}	else if ($.browser.msie && (jQuery.browser.version > 7.9999) ){
		//IE 8
		$('.contentBoxIn').css('top','0')
	}
	*/
	/******************************************************/
});