var ventana = 0;
function popUp(image,width,height) {
	var izquierdo = (screen.width - width) / 2;
	var superior = (screen.height - height) / 2;
	if(ventana){
		if(!ventana.closed) ventana.close();
	}
  	ventana = open('popup.php?image='+image,'','width='+width+',height='+height+',resizable=no,left='+ izquierdo +',top='+ superior +',scrollbars=no');
}

showing = false;

var IE = document.all?true:false

if (!IE) document.captureEvents(Event.MOUSEMOVE)

document.onmousemove = getMouseXY;

tempX = 0
tempY = 0

function getMouseXY(e) {
  if (IE) {
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {
    tempX = e.pageX
    tempY = e.pageY
  }  
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  return true
}


function showdiv(divid) {
	if (document.getElementById(divid)) {
		if (document.getElementById(divid).style.display == "none") {
			if (showing != true) {
				document.getElementById("imgbugatti").src= "media/bugattiveyron.jpg";
				document.getElementById(divid).style.top = tempY - 100;
				if ( tempX + 380 < document.body.offsetWidth ) {
					document.getElementById(divid).style.left = tempX + 30;
				} else {
					document.getElementById(divid).style.left = tempX - 400;
				}
				document.getElementById(divid).style.display = "";
				showing = true;
			}
		} else {
			document.getElementById(divid).style.display = "none";
			document.getElementById("imgbugatti").src= "";
			showing = false;
		}
	}
	return;
}

var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;

$(document).ready(function(){
	headline_count = $("div.headline").size();
	$("div.headline:eq("+current_headline+")").css('top','5px');
	if (headline_count >1) {
		headline_interval = setInterval(headline_rotate,9010);
		$('#scrollup').hover(function() {
			clearInterval(headline_interval);
			$("div.headline:eq(" + old_headline + ")").stop(false,true);
			$("div.headline:eq(" + current_headline + ")").stop(false,false);
			$("div.headline:eq(" + current_headline + ")").animate({top: 5},50,"linear");
		}, function() {
			headline_interval = setInterval(headline_rotate,9010);
			headline_rotate();
		});
	}
});

headline_rotate = function() {
	old_headline = current_headline;
	current_headline = (old_headline + 1) % headline_count; 
	$("div.headline:eq(" + old_headline + ")").animate({top: -205},9000,"linear", function() { $(this).css('top','210px'); });
	$("div.headline:eq(" + current_headline + ")").show().animate({top: 5},9000,"linear");
}