if(typeof console=="undefined"||typeof console.log=="undefined")var console={log:function(){}};var com_base=0;var comment_submitted=0;var mouse_on_login=0;var keys=new Array;$(function(){if($("div.comment_row").length<=2)$(".toggle-show").hide();else $(".toggle-show").fadeIn();if(logged==false){$("textarea.comment_text").attr('disabled','disabled');$(".comment-focus").text('Login per commentare');}
var last_comment=$('.comment_row:last');var slast_comment=$(".comment_row:last").prev();var comment_text_h=$(".comment_text").height();if($("div.comment_row").length>2){$(slast_comment).insertBefore($('.comment_row:first'));$(last_comment).insertAfter($(slast_comment));}
$(".comment_row").each(function(index){if(index<2){com_base+=$(this).outerHeight();}else{return false;}});console.log(com_base);$(".comment-focus").live('click',function(){if(logged==true){$(".comment_text").focus();$(".comment_text").select();$(window).scrollTop($("textarea.comment_text").offset().top);}else{setTimeout(function(){$("#login_li a").trigger('click');$(window).scrollTop($("#login_li").offset().top);},100);}});$(".comment_text").live('click',function(){if($(this).val()=='commenta...')$(this).select();});$("textarea.comment_text").live('keypress, keydown, keyup',function(e){var nchars=$(this).text().length;if($(this).scrollTop()>0){$(this).height($(this).scrollTop()+$(this).height());}
if(e.keyCode==13&&!e.shiftKey){if($.trim($(this).val())!=""){$(this).closest('form').find('.submit').click();}}});if($("#mode_view span").length==0)$("#mode_view").remove();$(".numcomments").html($(".comment_row").length);if(com_base>2)com_base=com_base-2;$("#list_comments").height(com_base);keys=$("#elencokey_1").val();if(keys!=undefined)keys.split(',');else keys=new Array;if(keys.length==1)$(".bigger_box .header_box").hide();$("#block_comments").insertBefore($("#pgallery"));$("#toggleslide .toggle-show").click(function(){if($("#list_comments").height()==com_base){var last_comment=$('.comment_row:first').next();var slast_comment=$(".comment_row:first");var toHeight=$("#list_comments").css('height','auto').height();$("#list_comments").css('height',com_base);$("#list_comments").css('overflow','auto').animate({height:toHeight});$(slast_comment).insertAfter($(".comment_row:last"));$(last_comment).insertAfter($(".comment_row:last"));$(this).text('- Nascondi');}else{$("#list_comments").css('overflow','hidden').animate({height:com_base});$(this).text('+ Mostra tutti');var last_comment=$('.comment_row:last');var slast_comment=$(".comment_row:last").prev();$(slast_comment).insertBefore($('.comment_row:first'));$(last_comment).insertAfter($(slast_comment));}});$("#addcomment .submit").click(function(){if(comment_submitted==0){comment_submitted=1;var data=$(this).closest('form').serialize();console.log(data);preloader('show');$.post('/portale/ajax/addcomment',data,function(ret){var base=$("#list_comments").height();$("#list_comments").css('height',base);var toHeight1=$("#list_comments").css('height','auto').height();$("#list_comments").css('height',base);$("#list_comments").append(ret.html);if($("#list_comments .comment_row").length<=2){com_base=$(".comment_row:first").outerHeight()+$(".comment_row:first").next().outerHeight();$("#list_comments").height(com_base);}else{if($("#list_comments").height()==com_base){var me=$(".comment_row:last");$(".comment_row:first").insertAfter($(".comment_row:last"));$(me).insertAfter($(".comment_row:first"));new_height=$(".comment_row:first").outerHeight()+$(".comment_row:first").next().outerHeight();com_base=new_height;}}
preloader('hide');$(".comment_text").val('commenta...').select();$("textarea.comment_text").height(17);comment_submitted=0;if($("div.comment_row").length<=2)$(".toggle-show").hide();else $(".toggle-show").fadeIn();},'json');}});});$(function(){$(".my_captcha").live('renew',function(e){if($(this).attr('data-original')==undefined){$(this).attr('data-original',$(this).attr('src'));}
$(this).attr('src',$(this).attr('data-original')+"?rnd="+e.timeStamp);});$(".new_code").live('click',function(){$(".my_captcha").trigger('renew');});});var current_index=0;var selected_index=0;var timeout=5000;var keys=new Array();var timer=1;var masonry_me=0;var selected_link=null;function createCookie(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString();}
else var expires="";document.cookie=name+"="+value+expires+"; path=/";}
function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);}
return null;}
function preloader(opt){if(opt=="show"){if($('body').find('.timmy_loader').length==0){$("<div></div>").appendTo('body')
.hide()
.addClass('timmy_loader')
.append('<img src="/img/portale/loader.gif" alt="" />')
.fadeIn('fast');}}else{$(".timmy_loader").fadeOut('fast',function(){$(this).remove()});}}
$(document).ready(function(){var stato_menu=readCookie("menu");if(stato_menu!=null&&stato_menu=="chiuso"){$("#menu_overlay").hide();$("#menu_categorie").addClass("menu_plus");}else{$("#menu_categorie").addClass("menu_minus active");}});$(document).ready(function(){$("#search_value").autocomplete({minLength:3,delay:0,search:function(event,ui){$("#search_value").css('background-image','url(/img/portale/loader.gif)');},close:function(event,ui){$("#search_value").css('background-image','none');},open:function(event,ui){$("#search_value").css('background-image','none');},source:function(request,response){$.getJSON("/portale/ajax/search",request,function(data,status,xhr){if(data.length==0){$("#search_value").css('background-image','none');}
response(data);});},select:function(event,ui){selected_link=ui.item.link;location.href=selected_link;},change:function(event,ui){selected_link=ui.item.link;}});$("#main_search").submit(function(){if(selected_link!=null)location.href=selected_link;return false;});$("#search_value").click(function(){if($(this).attr('value')=="cerca nel sito...")$(this).attr('value','');});});function show_results(data){if($("#results").css('display')=="none"){$("#results").fadeIn();}
$("#results").html(data.length+" risultati trovati");}
function mostra(id){$('.small_overlay').hide();$('#'+id).fadeIn();}
function header_player(gal_id)
{var string_keys=$("#elencokey_"+gal_id).attr('value');keys=string_keys.split(",");if(keys.length==1)$(".bigger_box .header_box").hide();next_load(gal_id);}
function myIndexOf(array,value){for(i=0;i<array.length;i++)
if(array[i]==value)return i;}
function switch_timer(gal_id,start){if(keys.length>1){if(timer){if(start==null)
{var prossimo=selected_index.replace('immagine_','');prossimo=myIndexOf(keys,prossimo);if(prossimo==(keys.length-1))prossimo=0;else prossimo++;}else prossimo=start;switch_img(gal_id,prossimo);setTimeout("switch_timer("+gal_id+")",timeout);}}}
function switch_img(gal_id,id){$('#'+selected_index).fadeOut('slow');$('#immagine_'+keys[id]).fadeIn('slow');$('#header_paging_'+gal_id+' li').removeClass('selected');$("#select_"+gal_id+"_"+id).addClass('selected');selected_index='immagine_'+keys[id];$('.header_descrizioni').hide();if($('#descrizione_'+keys[id]).text().length>1)
$('#descrizione_'+keys[id]).show();}
function next_load(gal_id){var immagine="<img src='gallery/"+keys[current_index]+"/830/443/80/3/content/"+keys[current_index]+".jpg' class='header_immagine' id='immagine_"+keys[current_index]+"'>";$("#header_player_"+gal_id).append(immagine);if(current_index==0){$('.header_descrizioni').hide();if($('#descrizione_'+keys[current_index]).text().length>1)
$('#descrizione_'+keys[current_index]).show();}
$('.header_immagine').load(function(){if(current_index==0)
{$('#header_paging_'+gal_id).append("<li class=\"selected\" id='select_"+gal_id+"_"+current_index+"'><a href='#content' onclick='switch_img("+gal_id+","+current_index+"); timer=0;'>"+(current_index+1)+"</a></li>");}else{$('#header_paging_'+gal_id).append("<li id='select_"+gal_id+"_"+current_index+"'><a href='#content' onclick='switch_img("+gal_id+","+current_index+"); timer=0;'>"+(current_index+1)+"</a></li>");}
if(current_index<(keys.length-1)){current_index++;next_load(1);}else{setTimeout("switch_timer("+gal_id+")",timeout);}});$("#header_loading_"+gal_id).css('display','none');$("#header_player_"+gal_id+" img:first-child").css('display','block');selected_index=$("#header_player_"+gal_id+" img:first-child").attr('id');}
function check_area(e,element){var mousex=e.pageX;var mousey=e.pageY;var top=$(element).offset().top;var left=$(element).offset().left;var width=$(element).width();var height=$(element).height();if(mousex<left||mousex>width+left||mousey<top||mousey>top+height){$(element).fadeOut();mouse_on_login=0;$('#login_li').removeClass('selected');}}
$(window).load(function()
{$("#menu_categorie").click(function(){$("#menu_overlay").slideToggle(function(){if($("#menu_overlay").is(":visible")){createCookie("menu","aperto",10);$("#menu_categorie").removeClass("menu_plus");$("#menu_categorie").addClass("menu_minus active");}else{createCookie("menu","chiuso",10);$("#menu_categorie").removeClass("menu_minus active");$("#menu_categorie").addClass("menu_plus");}});});if(masonry_me){$('#contents').css('visibility','visible').masonry({columnWidth:5,resizeable:true});preloader('hide');}
$("#login").mouseover(function(e){mouse_on_login=1;});$('#registrazione_submit').click(function(){var scelta=$("#registrazione_cliente input[name='tipo']:checked").val();if(scelta==0)location.href='/portale/register';if(scelta==1)location.href='/portale/registeruser';if(scelta==2)location.href='/portale/registergroup';});});$(window).bind('scroll',function()
{});$(window).bind('resize',function()
{});function IsNumeric(n){return!isNaN(parseFloat(n))&&isFinite(n);}
$(function(){if(window.location.hash=="#!usercp"){$("#user_panel").fadeIn(300);}});$(function(){$(".tipme").live('mouseenter',function(e){console.log("in");if($(this).attr('data-tip-id')==undefined){$(this).attr('data-tip-title',$(this).attr('title'));$(this).removeAttr('title');$(this).attr('data-tip-id','tip_'+e.timeStamp);}
if($('body').find('#'+$(this).attr('data-tip-id')).length==0){$("<div></div>").addClass('timmytip')
.html('<span class="arrow_tooltip"></span>'+$(this).attr('data-tip-title'))
.css('display','none')
.css('z-index','1999')
.css('position','absolute')
.css('left',$(this).offset().left)
.css('top',$(this).offset().top-25)
.attr('id',$(this).attr('data-tip-id'))
.appendTo('body')
.fadeIn(300);}else{$('#'+$(this).attr('data-tip-id')).html('<span class="arrow_tooltip"></span>'+$(this).attr('data-tip-title')).fadeIn(150);}});$(".tipme").live('mouseleave',function(){console.log("out");$('#'+$(this).attr('data-tip-id')).fadeOut(150);});});$(function(){$(".num_comments").each(function(){if($(this).html()=='0')$(this).remove();});});
