var myScrollArea;
var footerTimer;

window.addEvent('domready', function(){
	// scorrimento immagini con frecce
	pennyblack_addEvent_freccia_dx();
	pennyblack_addEvent_freccia_sx();

	// scrollbar con grafica personalizzata in tutti i div con overflow:auto
	
	is_styleNotes = ($$('body#stylenotes').length==0) ? false : true;
	is_girlscity = ($$('body#girlscity').length==0) ? false : true;
	is_lookbook = ($$('body#lookbook').length==0) ? false : true;
	if(is_styleNotes) {
		myScrollArea = new MooScroll({disabledOpacity:0.5});
	}else{
		if(is_girlscity) {
			myScrollArea = new MooScroll({disabledOpacity:0, selector:'#txt'});
		} else if(is_lookbook) {
			myScrollArea = new MooScroll({disabledOpacity:0, selector:'.lookbook_stylenotes_scroll'});
		} else {
			myScrollArea = new MooScroll({disabledOpacity:0});
		}
	}
	
	$('infolegali_open').addEvent('click', infolegali_open);	
	$('infolegali_close').addEvent('click', infolegali_close);
	$('datisocietari_handler_popup').addEvent('mouseover', datisocietari_open);
	$('datisocietari_div_popup').addEvent('mouseover', datisocietari_open);
	$('datisocietari_handler_popup').addEvent('mouseout', datisocietari_close);
	$('datisocietari_div_popup').addEvent('mouseout', datisocietari_close);
});


function infolegali_open() {
	/*$clear(footerTimer);*/
	footer_close();
	$('infolegali_handler_popup').addClass('jhover');
	return false;
}

function datisocietari_open() {
	$clear(footerTimer);
	infolegali_close();
	$('datisocietari_handler_popup').addClass('jhover');
	return false;
}

function footer_close() {
	$('datisocietari_handler_popup').removeClass('jhover');
}

function datisocietari_close() {
	$clear(footerTimer);
	footerTimer = footer_close.delay(1000);
}

function infolegali_close(){
	$('infolegali_handler_popup').removeClass('jhover');
}


function pennyblack_event_freccia_dx() {
	var photo = this.getParent().getPrevious().getElement('div');
	var photosNo = photo.getElements('.galleria-mini').length;
	var photoWidth = photo.getElement('div').getStyle('width').toInt();
	var photoMargin = photo.getStyle('margin-left').toInt();
	var photoMarginNew = photoMargin - photoWidth;
	var photosWidthTotal = photoWidth*photosNo;
	if(photosWidthTotal - (-photoMarginNew) > 0 ) {
		photo.setStyle('margin-left', photoMarginNew);
	} else {
		photo.setStyle('margin-left', 0);
	}
	return false;
}

function pennyblack_event_freccia_sx() {
	var photo = this.getParent().getNext().getElement('div');
	var photosNo = photo.getElements('.galleria-mini').length;
	var photoWidth = photo.getElement('div').getStyle('width').toInt();
	var photoMargin = photo.getStyle('margin-left').toInt();
	var photoMarginNew = photoMargin + photoWidth;
	var photosWidthTotal = photoWidth*photosNo;
	if(photoMarginNew <= 0 ) {
		photo.setStyle('margin-left', photoMarginNew);
	} else {
		photo.setStyle('margin-left', -(photosWidthTotal-photoWidth));
	}
	return false;
}

function pennyblack_addEvent_freccia_dx() {
	$$('.freccia-dx a').removeEvent('click', pennyblack_event_freccia_dx);
	$$('.freccia-dx a').addEvent('click', pennyblack_event_freccia_dx);
}

function pennyblack_addEvent_freccia_sx() {
	$$('.freccia-sx a').removeEvent('click', pennyblack_event_freccia_sx);
	$$('.freccia-sx a').addEvent('click', pennyblack_event_freccia_sx);
}
