// JavaScript Document
var isWheel = true;

//blocchi
var titolo;
var nodo;

//wheel
if (window.addEventListener)
// MOZILLA
window.addEventListener('DOMMouseScroll', wheel, false);
// IE / OPERA
window.onmousewheel = document.onmousewheel = wheel;

function wheel(event){
	if (isWheel){
		return true;
	}else{		
		event.stopPropagation();
		event.preventDefault();
		event.cancelBubble = false;
		return false;
	}
}
function startScroll(){
	isWheel = true;
	if (nodo != ""){
		document.title = "BRAND PORTAL - "+titolo;
		//document.location.hash = nodo;
	}else{
		document.title = "BRAND PORTAL - The first integrated communications network in Italy";
		//document.location.hash = "top";
	}
	
}
function getCaseHistory(){
	var nome = $(".lavori:first").parent('.entry');
	nodo = nome;
	titolo = $(nome).attr('title');
	gotoFixed(nodo);
}
function getHisotry(){
	nodo = "#history";
	titolo = "History";
	gotoFixed(nodo);
}
function getOrganization(){
	nodo = "#organization";
	titolo = "Organization";
	gotoFixed(nodo);
}
function getCareers(){
	nodo = "#careers";
	titolo = "Careers";
	gotoFixed(nodo);
}
function getContatti(){
	nodo = "#contacts";
	titolo = "Contacts";
	gotoFixed(nodo);
}

function goOnTop(){
	nodo = "";
	titolo = "";
	$(document).scrollTo($("#header"),  {duration: (1000), queue:false , onAfter:startScroll});
}

function gotoNext(elemento){
	nodo = "";
	titolo = "";
	nodo = '#'+$(elemento).attr("href");
	titolo = $(nodo).attr("title");
	$(document).scrollTo($(nodo),  {duration: 1000, axis:"y" , onAfter:startScroll});
}

function gotoFixed(nodo){
	if($(nodo).attr("id") != undefined){
		titolo = $(nodo).attr("title");
		isWheel = false;
		$(document).scrollTo($(nodo),  {duration: 1000, axis:"y" , onAfter:startScroll});
	}
}

function loadPrevPost(post){
	$("#content div:last").load(post, function(response, status, xhr) {
		switch (status){
			case "success":
				isWheel = false;
				titolo = $(nodo).attr("title");
				$(nodo).parent().removeClass("holder");
				$(document).scrollTo($("#content div:last"),  {duration: 1000, axis:"y", onAfter:startScroll});
			break;
		}
	});
	return false;
}

function setAllLinks(){
	$("a.top").live ('click',goOnTop);
	$("a.next").live('click',function (event){
		event.preventDefault();
		gotoNext(event.currentTarget);
		return false;
	});	
}

$(document).ready(function (){
	var arBackgrounds = new Array();
	arBackgrounds.push ("fondo_01");
	arBackgrounds.push ("fondo_02");
	arBackgrounds.push ("fondo_03");
	var randValue = Math.floor(Math.random() * arBackgrounds.length);
	$(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
	$("#flumen").css("cursor","pointer");
	$("#flumen").click(
		function (){
			window.open("http://www.flumen.co.uk/","_blank");
		}
	);
	$("body").addClass(arBackgrounds[randValue]);
	setAllLinks();
});

function openPopup(url){
	window.open(url,'Brand Portal','toolbar=no, location=no,status=no,menubar=no,scrollbars=no,resizable=no');
}
