// JS Common

/* funzioni generali */

function removeClass(classe, el) {
  var re = new RegExp("(\\b|^)" + classe + "(\\b|$)", "gi");
  if (re.test(el.className)) {
        el.className = el.className.replace(re, '');
        return true;
  }
  return false;
}

function replaceClass(classe, classe2, el) {
  var re = new RegExp("(\\b|^)" + classe + "(\\b|$)", "gi");
  if (re.test(el.className)) {
        el.className = el.className.replace(re, classe2);
        return true;
  }
  return false;
}

/* dichiarazione delle variabili */

/* globali */
var allNewsContainer, allSingleNews, totNews, hTot, stepH, prevBtn, nextBtn, handler, totViewTime, allNewsContainerFx, fxDuration, canChange;

/* inizializzazione pagina */

function moveToPrev(){
	var tempMT = parseInt(allNewsContainer.style.marginTop);
	if(tempMT < 0){
		allNewsContainer.style.marginTop = (tempMT+stepH) + 'px';
	} else {
		allNewsContainer.style.marginTop = (-hTot + stepH)  + 'px';
	}
}

function prevNews(){
	if(canChange){
		canChange = false;
		allNewsContainer.fade('out');
		moveToPrev.delay(fxDuration);
		(function(){allNewsContainer.fade('in'); canChange = true;}).delay(fxDuration);
	}
}	

function moveToNext(){
	var tempMT = parseInt(allNewsContainer.style.marginTop);
	if(tempMT > (-hTot + stepH)){
		allNewsContainer.style.marginTop = (tempMT-stepH) + 'px';
	} else {
		allNewsContainer.style.marginTop = 0 + 'px';
	}
}

function nextNews(){
	if(canChange){
		canChange = false;
		allNewsContainer.fade('out');
		moveToNext.delay(fxDuration);
		(function(){allNewsContainer.fade('in'); canChange = true;}).delay(fxDuration);
	}
}

/* gestione submit form in floatbox */
function confPage(){
	fb.end();
	var delHand = setTimeout(function(){document.location.href = 'confirm.html'},1000);
}

/* imposta il target blank per i links con l'attributo rel pari ad "external" */
function setExtLinks(){
	var allLinksInPage = $$('a');
	allLinksInPage.each(function(a){if(a.rel){if(a.rel == 'external'){a.target = '_blank';}}});
}

/* toglie il focus dai links */
function blurAllLinks(){
	var allLinksInPage = $$('a');
	allLinksInPage.each(function(a){
								 	a.onfocus = function(){a.blur()};
								 });
}
