jQuery.noConflict();

jQuery(document).ready(function() {

	// Estoy a la escucha de cambios en el tamanno de la ventana
	jQuery(window).resize(posicionar);

	var numElementos = jQuery('.paginacion').children().size();
	var x = jQuery('.paginacion .pagina:first').width();
	var y = jQuery('.paginacion .pagina:last').width();
	jQuery('.paginacion').css('width', numElementos*15+62+'px');
	
	// Asigno la imagen de fondo
	jQuery("body").css("background-image", "url('http://estaticos.chilevision.cl/home/templates/toleranciacero_201005/images/bg.jpg')");
	
	
	// Posiciono la imagen de fondo
	posicionar();	
	

});


// Flash
function deliverCHV(content){
	document.write(content);	
}

function comentarioTwitter(){
	  twttr.anywhere(function (T) {

    T("#tbox").tweetBox({
      height: 105,
      width: 290,
      defaultContent: "#tolerancia0",
	  label: "",
	  counter:true
    });

  });
}
function twitter(){
	new TWTR.Widget({
	  version: 2,
	  type: 'search',
	  search: 'tolerancia0',
	  interval: 9000,
	  title: 'COMENTA NUESTRO PROGRAMA A TRAVÉS DE TWITTER',
	  subject: '',
	  width: 290,
	  height: 255,
	  theme: {
		shell: {
		  background: '#67D4F5',
		  color: '#ffffff'
		},
		tweets: {
		  background: '#171A21',
		  color: '#fff',
		  links: '#fff'
		}
	  },
	  features: {
		scrollbar: true,
		loop: true,
		live: true,
		hashtags: true,
		timestamp: true,
		avatars: true,
		toptweets: true,
		behavior: 'default'
	  }
	}).render().start();
}

// Carruseles 
function carouselH1_initCallback(carousel) {
	// Botones para saltar directamente
	jQuery('#containerH1 .jump a').bind('click', function() {
		anchor = ((jQuery.jcarousel.intval(jQuery(this).text()) - 1)*1) + 1;
		carousel.scroll(anchor);
		return false;
	});
	// Boton para avanzar
	jQuery('#carouselH1-next').bind('click', function() {
		carousel.next();
		return false;
	});
	// Boton para retroceder
	jQuery('#carouselH1-prev').bind('click', function() {
		carousel.prev();
		return false;
	});
};
/**
 * Callback cuando un elemento se ve en primera posicion
 *
 */
function carouselH1_itemFirstInCallback(carousel, objeto, index, state) {
	
	enlace = Math.ceil((index - 1) / 1) + 1;

	// Estilo del anterior seleccionado
	jQuery('.jump .H1_' + jQuery('#carouselH1').jcarousel.last_jump1).removeClass('activo');
	jQuery('.jump .H1_' + jQuery('#carouselH1').jcarousel.last_jump1).addClass('inactivo');

	// Modifico estilo del elemento jump
	jQuery('.jump .H1_' + enlace).removeClass('inactivo');
	jQuery('.jump .H1_' + enlace).addClass('activo');

	jQuery('#carouselH1').jcarousel.last_jump1 = enlace;
}
function initScrollH1(){
	jQuery('#carouselH1').jcarousel({
		// Configuracion del carrusel
		scroll:1,
		// CallBacks
		initCallback: carouselH1_initCallback,
		itemFirstInCallback: {
			onAfterAnimation: carouselH1_itemFirstInCallback
		},

		// No contruimos botones anterior / siguiente
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
	jQuery('#carouselH1').jcarousel.last_jump1 = 1;
}



// Estoy a la escucha de cambios en el tamanno de la ventana

function posicionar(){
	// Leo la posicion del contenedor
	var posicion = jQuery("#contenedor").offset();

	// Calculo la posicion que le corresponde a la imagen de fondo
	// posicion = posicion left del contenedor - ancho de la parte izquierda del fondo
	var bgposicion = Math.ceil(posicion.left) - 342;
	jQuery("body").css("background-position", bgposicion + "px 0px");
	jQuery("#pie").css("background-position", bgposicion + "px 0px");
}
function MM_jumpMenu(targ,selObj,restore){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}





