/* ########################## INIZIO DOCUMENT READY ########################## */
$(document).ready(function(){
if($(".fotostory-img-container p").length){
var fotoHeight = $(".txt-fotoracconto img").height();
var divHeight = $(".fotostory-img-container").height();
$(".fotostory-img-container").height(divHeight + 20);
$(".fotostory-img-container").width($(".fotostory-img-container img").width() + 30);
$(".num-fotoracconto").css({"top" : fotoHeight + 20 + "px"});
//$(".fotostory-img-container p").css({"top" : fotoHeight - 40 + "px"});
}
// CONTROLLO NUMERI COMMENTI
controlloNumeroCommenti();
//VISUALIZZO DIV NUM COMMENTI
if( $('#form-commenti').length != 0 ){
var numComm = $('#lista-commenti li').size();
$('.n-commenti').text("Commenti("+numComm+")");
$('.n-commenti').show();
}
if( $('#carosello-fotoraconto').length != 0 ){
jQuery('#carosello-foto').jcarousel({
scroll:1
});
}
// CONTROLLO LARGHEZZA DIDA IN BASE ALLA LARGHEZZA DELLA IMG
if( $('.box-articolo').length != 0 ){
var widthBox = $('.pic-articolo img').width();
$('.pic-articolo').css('width',widthBox+'px');
};
// GESTIONE PRINT
$('.bt-stampa').click(function() {
window.print();
});
// GESTIONE INVIA AD UN AMICO
$('.bt-amico').click(function() {
// 1. Verifico che non sia stato creato giˆ un oggetto
// 2. Se stato creato faccio il load e sostituisco l'html dell'oggetto stesso.
// 3. Se non stato creato, lo creo e lo appendo in coda al body.
if ($("#tellafriend_popup").html()==null) {
$("body").append("
");
}
$("#tellafriend_popup").load("/ssi/shared/tellafriend_form.shtml", function(){
$('#tellafriend_popup').css({
position: 'absolute',
display: 'none',
//top = $(window).scrollTop()+'px',
top: getPageScroll()[1] + (getPageHeight() / 10),
left: '385px',
background: '#fff'
});
var urlPage = window.location.href;
$("#linkUrl").val(urlPage);
$("#tellafriend_popup .close_taf").click(function() {
$("#tellafriend_popup").fadeOut(200);
});
$("#tellafriend_popup").fadeIn(200);
initAjaxForms();
});
return false;
});
function initAjaxForms() {
$("form.ajax").each(function() {
ajaxifySingleForm(this);
});
}
// AJAX forms
function ajaxifySingleForm(form, callback) {
callback = callback || function(){ };
$(form).validate({
wrapper: "strong",
submitHandler: function(form){
$(form).ajaxSubmit({
target: $(form).parent(),
success: function() {
initAjaxForms();
callback.call();
}
});
}
});
}
// cf *********************************************Inizio gestione commenti utente
resetFormCommenti();
$("#form-commenti").submit(function(){
var txtError = "";
var htmlError = "";
var regExpEmail= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
if (($("#dlt-nickname").val() == "") || ($("#dlt-nickname").val() == "nome") ){
txtError += "Inserire il nome";
}
if (($("#dlt-email").val() == "") || ($("#dlt-email").val() == "email") ){
if (txtError.length > 0){txtError += ", ";}
txtError += "Inserire l'email";
}else{
if(!regExpEmail.test($('#dlt-email').val())){
if (txtError.length > 0){txtError += ", ";}
txtError += "Email non valida";
}
}
if ($("#dlt-testo").val() == ""){
if (txtError.length > 0){txtError += ", ";}
txtError += "Inserire il testo";
}
if (txtError.length > 0){
htmlError = ""+ txtError + "";
$("#dlt-messaggio").html(htmlError);
return false;
}
var ACTION_URL = "/commenti/insert.action";
var currentUrl="" + window.location;
var url = ACTION_URL + "?commento.nickname="+$("#dlt-nickname").val();
url+="&commento.testo=" + escape($( "#dlt-testo").val());
url+="&commento.email=" + $("#dlt-email").val();
url+="&commento.idDocumento="+ $("#dlt-idDoc").val();
url+="&commento.contesto=" + $("#dlt-contesto").val();
url+="&commento.titoloDoc=" + escape($("#dlt-titoloDoc").val());
url+="&pathImg=" + $("#dlt-pathImg").val();
url+="&maxIndex="+ $("#dlt-maxIndex").val();
url+="&commento.sezione=" + $("#dlt-sezione").val();
url+="&commento.sottosezione="+$("#dlt-sottosezione").val();
url+="&commento.path=" + escape(currentUrl);
$.ajax({
type: "GET",
url: url,
error: function(data){
txtError = "Ci scusiamo, non è stato possibile registrare il tuo commento. Riprova più tardi";
htmlError = ""+ txtError + "";
$("#dlt-messaggio").html(htmlError);
},
success: function(data){
if (data.length > 0){
$("#dlt-listaCommenti").html("");
$("#dlt-listaCommenti").html(data);
controlloNumeroCommenti();
resetFormCommenti();
}else{
txtError = "Ci scusiamo, non è stato possibile registrare il tuo commento. Riprova più tardi";
htmlError = ""+ txtError + "";
$("#dlt-messaggio").html(htmlError);
$("#dlt-nickname").val("nome");
$("#dlt-email").val("email");
$("#dlt-testo").val("");
}
}
});
return false;
});
// cf ********************************************* Fine gestione commenti utente
//gestione carosello fotogallery
if($(".box-gallery").length > 0){
$("#wrap-carousel-fotogallery").jcarousel({
scroll: 6
});
if(location.href.indexOf("_") > 0){
var urlNum = location.href.split("_");
var numFotoUrl = urlNum[1].split(".");
//var totThumb = $("#wrap-carousel-fotogallery ul li").length;
//var modResult = totThumb % numFotoUrl[0];
if(numFotoUrl[0] > 6){
$(".jcarousel-next-horizontal").click();
setTimeout(function(){
if(numFotoUrl[0] > 12){
$(".jcarousel-next-horizontal").click();
setTimeout(function(){
if(numFotoUrl[0] > 18){
$(".jcarousel-next-horizontal").click();
setTimeout(function(){
if(numFotoUrl[0] > 24){
$(".jcarousel-next-horizontal").click();
setTimeout(function(){
if(numFotoUrl[0] > 30){
$(".jcarousel-next-horizontal").click();
setTimeout(function(){
if(numFotoUrl[0] > 36){
$(".jcarousel-next-horizontal").click();
setTimeout(function(){
if(numFotoUrl[0] > 42){
$(".jcarousel-next-horizontal").click();
}
}, 50);
}
}, 50);
}
}, 50);
}
}, 50);
}
}, 50);
}
}, 50);
}
}
if($("#body-oroscopo").length > 0){
$("#wrap-carousel-fotogallery li a").each(function(){
var a = $(this).attr("href");
var c = a.replace("oroscopo/", "");
var urlDaDividere = location.href.split("/");
var urlDaRimuovere = (urlDaDividere[0] + "//" + urlDaDividere[1] + urlDaDividere[2]);
var b = location.href.replace(urlDaRimuovere, "");
if(b == c){
$(this).addClass("img-selected");
}
});
} else if($("#body-cucina").length > 0){
$("#wrap-carousel-fotogallery li a").each(function(){
var a = $(this).attr("href");
var c = a.replace("cucina/", "");
var urlDaDividere = location.href.split("/");
var urlDaRimuovere = (urlDaDividere[0] + "//" + urlDaDividere[1] + urlDaDividere[2]);
var b = location.href.replace(urlDaRimuovere, "");
if(b == c){
$(this).addClass("img-selected");
}
});
} else {
$("#wrap-carousel-fotogallery li a").each(function(){
var a = $(this).attr("href");
var urlDaDividere = location.href.split("/");
var urlDaRimuovere = (urlDaDividere[0] + "//" + urlDaDividere[1] + urlDaDividere[2]);
var b = location.href.replace(urlDaRimuovere, "");
if(a == b){
$(this).addClass("img-selected");
}
});
}
if(!$('#wrap-carousel-fotogallery li a').hasClass("img-selected")){
$('#wrap-carousel-fotogallery li:first a').addClass("img-selected");
}
}//fine controllo carosello fotogallery
if($("#commenti").length > 0){
$("#link-dilatua").show();
var numComm = $('#lista-commenti li').size();
$("#link-dilatua a span").text(numComm);
}
// gestione mouseover frecce fotoracconto
if($(".txt-fotoracconto").length > 0){
if(location.href.indexOf("_") > 0){
$(".txt-fotoracconto img").mouseover(function(){
$(".next-black, .prev-black").fadeIn("slow", "linear");
}).mouseout(function(){
$(".next-black, .prev-black").fadeOut("slow", "linear");
});
} else {
$(".prev-black").hide();
$(".next-black").show();
}
}//fine gestione mouseover frecce fotoracconto
});
/* ########################## FINE DOCUMENT READY ########################## */
/*____________________GESTIONE POPUP TELLEAFRIEND_________________*/
function getPageScroll() {
var xScroll, yScroll;
if (self.pageYOffset) {
yScroll = self.pageYOffset;
xScroll = self.pageXOffset;
} else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
yScroll = document.documentElement.scrollTop;
xScroll = document.documentElement.scrollLeft;
} else if (document.body) {// all other Explorers
yScroll = document.body.scrollTop;
xScroll = document.body.scrollLeft;
}
return new Array(xScroll,yScroll)
}
function getPageHeight() {
var windowHeight
if (self.innerHeight) { // all except Explorer
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowHeight = document.body.clientHeight;
}
return windowHeight
}
function getPageScroll() {
var xScroll, yScroll;
if (self.pageYOffset) {
yScroll = self.pageYOffset;
xScroll = self.pageXOffset;
} else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
yScroll = document.documentElement.scrollTop;
xScroll = document.documentElement.scrollLeft;
} else if (document.body) {// all other Explorers
yScroll = document.body.scrollTop;
xScroll = document.body.scrollLeft;
}
return new Array(xScroll,yScroll)
}
function getPageHeight() {
var windowHeight
if (self.innerHeight) { // all except Explorer
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowHeight = document.body.clientHeight;
}
return windowHeight
}
$(window).load(function(){
// CONTROLLO ALTEZZE BOTTONI DI NAVIGAZIONE GALLERY
if( $('#carosello-gallery').length != 0 ){
if ($('.img-text-center').length != 0){
var heightButton = $('.img-text-center').height();
$('.bt-prev-gallery').css('top',(heightButton/2));
$('.bt-next-gallery').css('top',(heightButton/2));
} else {
if ($('.img-gallery-center').length != 0){
var heightButton = $('.box-gallery .img-gallery-center img').height();
$('.img-gallery-center').css('height',heightButton);
} else {
var heightButton = $('.box-gallery .img-gallery-left img').height();
}
var heightTitoli = $('.box-gallery .contenitore-titoli').height();
$('.bt-prev-gallery').css('top',(heightButton/2)+heightTitoli).css('display','block');
$('.bt-next-gallery').css('top',(heightButton/2)+heightTitoli).css('display','block');;
}
};
if( $('.box-articolo').length != 0 ){
var widthBox = $('.pic-articolo img').width();
$('.pic-articolo').css('width',widthBox+'px');
};
});
// ************************************************ Form gestione commenti utente
function MaxCaratteri(Object, MaxLen){
if (Object.value.length > MaxLen){
Object.value = Object.value.substring(0,MaxLen);
}
}
function controlloNumeroCommenti(){
if( $('#lista-commenti li').size() > 3 ){
$('#lista-commenti li:eq(0), #lista-commenti li:eq(1), #lista-commenti li:eq(2)').show();
$('#commenti-successivi').show();
} else {
$('#lista-commenti li').show();
$('#commenti-successivi').hide();
}
$('#commenti-successivi').click(function() {
$('#lista-commenti li').show();
$(this).hide();
});
}
function resetFormCommenti() {
$("#dlt-messaggio").html("");
$("#dlt-nickname").val("nome");
$("#dlt-email").val("email");
$("#dlt-testo").val("");
}
$(window).load(function(){
// VISUALIZZO firma delle gallery
$('.autore-articolo').css('display','block');
});