// disable right-click
var message = "Function Disabled!";

function clickIE4() {
	if (event.button == 2) {
//		alert(message);
		return false;
	}
}

function clickNS4(e) {
	if (document.layers || document.getElementById && !document.all) {
		if (e.which == 2 || e.which == 3) {
//			alert(message);
			return false;
		}
	}
}

if (document.layers) {
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS4;
}
else if (document.all && !document.getElementById) {
	document.onmousedown=clickIE4;
}
//document.oncontextmenu = new Function("alert(message);return false")
document.oncontextmenu = new Function("return false")

var Application = {
  authenticityToken: function() {
    return $('authenticity-token').content;
  },

  authenticityTokenParameter: function(){
   return 'authenticity_token=' + encodeURIComponent(Application.authenticityToken());
  }
}

function deleteAllLinksTitles() {
	$$('a.lightview').each(function(link) {
		link.title = '';
		link.setAttribute("onclick", "alert('hello');");
//		link.onclick = 'new Ajax.Request(this.href, { evalScripts: true, method: get, parameters: Application.authenticityTokenParameter() });'
	});
}

function movePlane() {
	var plane = document.getElementById('flying-plane');
	if (plane.style.left == '') plane.style.left = '-400px';
	plane.style.left = (parseFloat(plane.style.left) + 1) + 'px';
	if (parseFloat(plane.style.left) > 1167) plane.style.left = '-400px';
}

function moveZeppelin() {
	var zeppelin = document.getElementById('flying-zeppelin');
	if (zeppelin.style.right == '') zeppelin.style.right = '-153px';
	zeppelin.style.right = (parseFloat(zeppelin.style.right) + 1) + 'px';
	if (parseFloat(zeppelin.style.right) > 1167) zeppelin.style.right = '-153px';
}

Event.observe(window, 'load', function(){
	if (document.getElementById('flying-plane')) {
		setInterval("movePlane()", 50);
		setInterval("moveZeppelin()", 150);
	}

	if (document.getElementById('news-1')) {
		setInterval("slidePon();", 10000);
	}
	
    Event.addBehavior({

	});
	
//	deleteAllLinksTitles(); // generating invalidauthenticitytoken errors
//	trap();
});

// NEWS

var nb_news = 3;
var current_news = 1;
var news_duration = 1.0;

function slidePon() {
	Effect.SlideUp('news-'+current_news, { duration: 3.0 });
	current_news += 1;
	if (current_news-1 == nb_news) {
		current_news = 1;
		setTimeout("Effect.Appear('news-"+current_news+"', { duration: 1.0 });", 3000);
		setTimeout("$('news-2').show(); $('news-3').show();", 3100);
	}
}

// PREPUBS

var current_page = 1;

function gotoPage(directory_name, page_num)
{
	current_page = page_num;
	document.getElementById('prepub-picture').src = "/prepublications/"+directory_name+"/" + current_page + ".jpg";
	document.getElementById('current-page').innerHTML = current_page;
}

function gotoPreviousPage(directory_name, last_page)
{
	previous_page = current_page - 1;
	if (previous_page == 0)
	{
		alert('Vous etes a la première planche.');
	}
	else
	{
		current_page = previous_page;
		document.getElementById('prepub-picture').src = "/prepublications/"+directory_name+"/" + current_page + ".jpg";
		document.getElementById('current-page').innerHTML = current_page;
	}
}

function gotoNextPage(directory_name, last_page)
{
	next_page = current_page + 1;
	if (next_page > last_page)
	{
		alert('Vous etes a la dernière planche.');
	}
	else
	{
		current_page = next_page;
		document.getElementById('prepub-picture').src = "/prepublications/"+directory_name+"/" + current_page + ".jpg";
		document.getElementById('current-page').innerHTML = current_page;
	}
}

/* Copyright on images */

function right(e) {
	var msg = "Les images sont la propriété de leurs auteurs respectifs et de BDPOLIS.";
	if (navigator.appName == 'Netscape' && e.which == 3) {
		alert(msg);
		return false;
	}
	if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
		alert(msg);
		return false;
	}
	else return true;
}

function trap() {
	if(document.images) {
		for (i=0;i<document.images.length;i++) {
			document.images[i].onmousedown = right;
			document.images[i].onmouseup = right;
		}
	}
}

function moveTo(container, element) {
	Position.prepare();
	container_y = Position.cumulativeOffset($(container))[1]
	element_y = Position.cumulativeOffset($(element))[1]
	new Effect.Scroll(container, {x:0, y:(element_y-container_y)});
	return false;
}

var scrolledBuilding = false;
function moveToBells() {
	if (!scrolledBuilding) {
		moveTo('authors-building', 'buildingScroller');
		scrolledBuilding = true;
	}
}

var current_video = 0;
function switchVideo(video_id, authenticity_token) {
	$('livideo-'+current_video).className = '';
	$('livideo-'+video_id).className = 'current';
	current_video = video_id;

	new Ajax.Request('/videos/switch/'+video_id+'?authenticity_token='+authenticity_token);
}

var current_price_filter = 'price--1--1';
function setPriceFilter(from, to) {
	$(current_price_filter).className = '';
	$('price-'+from+'-'+to).className = 'current';
	current_price_filter = 'price-'+from+'-'+to;
	
	$('price_from').value = from;
	$('price_to').value = to;
}
