//Bookmark
var bookmarkurl="http://www.sottocoperta.net"
var bookmarktitle="Sottocoperta"

function addbookmark() {
if (document.all)
 window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

//Cookies
var expDays = 60;

var page = "/intro/popup.asp";
var windowprops = "width=410,height=210,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no";

function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
 var j = i + alen;
 if (document.cookie.substring(i, j) == arg)
  return getCookieVal (j);
 i = document.cookie.indexOf(" ", i) + 1;
 if (i == 0) break;
}
return null;
}

function SetCookie(name,value){
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
 ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
 ((path == null) ? "" : ("; path=" + path)) +
 ((domain == null) ? "" : ("; domain=" + domain)) +
 ((secure == true) ? "; secure" : "");
}

function DeleteCookie(name){
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp=new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(){
var count = GetCookie('count')
if(count == null) {
 SetCookie('count','1')
 return 1
}else{
 var newcount = parseInt(count) + 1;
 DeleteCookie('count')
 SetCookie('count',newcount,exp)
 return count
}
}

function getCookieVal(offset){
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
 endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function checkCount(){
var count = GetCookie('count');
if (count == null) {
 count=1;
 SetCookie('count', count, exp);
 window.open(page, "", windowprops);
}else{
 count++;
 SetCookie('count', count, exp);
}
}


/*
function clearData(){window.clipboardData.setData('text','')}
function deldat() {if(window.clipboardData){clearData();}}
setInterval("deldat()", 1000);
*/

/* MM */
function MM_swapImgRestore(){var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
function MM_preloadImages(){var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}}
function MM_findObj(n,d){var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);if(!x && d.getElementById) x=d.getElementById(n); return x;}
function MM_swapImage(){var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}}
function MM_openBrWindow(theURL,winName,features){window.open(theURL,winName,features);}

function BigImage(nome,larga,alta) {
finestra=window.open('','finestra','width='+larga+',height='+alta+',status=no,menubar=no,resizable=no,scrollbars=no');
with(finestra.document) {
open();
writeln("<HT"+"ML><HE"+"AD><SCR"+"IPT>onBlur=self.focus();function SwapImage(){empty = new Image(200,70);empty.src='vuota.gif';document.image.src=empty.src};function Chiudi(){this.close();}</SCRIPT>");
writeln("</HE"+"AD><BO"+"DY BACKGROUND="+nome+" onLoad=SwapImage();self.focus();>");
writeln("<TA"+"BLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100% HEIGHT=100%>");
writeln("<TR><TD ALIGN=center VALIGN=middle><IMG BORDER=0 NAME=image SRC=loading.gif width=200 height=70></TD></TR>");
writeln("<TR><TD ALIGN=left VALIGN=bottom><A HREF=javascript:Chiudi()><IMG BORDER=0 SRC=chiudi.gif width=37 height=10></A></TD></TR>");
writeln("</TA"+"BLE></BO"+"DY></HT"+"ML>");
close(); } }

$(document).ready(function() {
   if (window != top) top.location.href = location.href;

  checkCount();

  var is_natale=document.location.toString().search('/natale/') > 0;
  var is_halloween=document.location.toString().search('/halloween/') > 0;
  var is_module=document.location.toString().search('/moduli/') > 0;
  var is_cartoline=document.location.toString().search('/cartoline/') > 0;

  $.ajaxSetup({async: false});
  $.getScript('https://apis.google.com/js/plusone.js');

  if(!(is_module || is_cartoline || $.browser.webkit)) {
    $.getScript('/js/jquery.disable.text.select.js', function(data, textStatus){
      $('body').disableTextSelect();
    });
  }
  
  $.getScript('/js/jquery.contextmenu.js', function(data, textStatus){
    var $m=''
    $m+='<div id="sc_menu" style="display:none;background-color:white;border:1px solid black;padding:5px;">';
    //$m+='<b><a href="http://www.sottocoperta.net/natale/letterina_da_babbonatale.asp" class="ftesto_pic menu" target="_blank"><img src="http://www.sottocoperta.net/immagini/icone/mininatale.png" height="21" hspace="2" align="absmiddle" border="0" vspace="2" width="21">Letterina di Babbo Natale</a></b><br>';
    $m+='<b><a href="http://www.sottocoperta.net/calendario2012/" class="ftesto_pic menu" target="_blank"><img src="http://www.sottocoperta.net/immagini/icone/minicalendario.png" height="21" hspace="2" align="absmiddle" border="0" vspace="2" width="21">Calendario 2012</a></b><br>';
    $m+='<b><a href="http://www.sottocoperta.net/iscrizione" class="ftesto_pic menu" target="_blank"><img src="http://www.sottocoperta.net/immagini/icone/minin.png" height="21" hspace="2" align="absmiddle" border="0" vspace="2" width="21">Iscriviti alla Newsletter<font color="#ff0000"> GRATIS</font></a></b><br>';
    $m+='<b><a href="http://www.facebook.com/pages/SottocopertaNet-Viaggi-Enogastronomia-Culture/286439316508" class="ftesto_pic menu" target="_blank"><img src="http://www.sottocoperta.net/immagini/icone/minifb.png" height="21" hspace="2" align="absmiddle" border="0" vspace="2" width="21">Diventa fan su Facebook</a></b><br>';
    $m+='<b><a href="http://twitter.com/SottocopertaNet" class="ftesto_pic menu" target="_blank"><img src="http://www.sottocoperta.net/immagini/icone/minitwitter.png" height="21" hspace="2" align="absmiddle" border="0" vspace="2" width="21">Seguici su Twitter</a></b><br>';
    $m+='<b><a href="http://www.sottocoperta.net/cerca/" class="ftesto_pic menu" target="_blank"><img src="http://www.sottocoperta.net/immagini/icone/minig.png" height="21" hspace="2" align="absmiddle" border="0" vspace="2" width="21">Cerca nel sito</a></b>';
    $m+='</div>'
    $($m).appendTo('body');
    $('body').contextMenu('#sc_menu');
  });

  $.ajaxSetup({async: true});

  var h=$("#lnkHome");
  if(h!=null){
    h.mouseover(function(){MM_swapImage('imgHome','','http://www.sottocoperta.net/immagini/home2.gif',1)});
    h.mouseout(function(){MM_swapImgRestore()});
  }
  var m=$("#lnkMail");
  if(m!=null){
    m.mouseover(function(){MM_swapImage('imgMail','','http://www.sottocoperta.net/immagini/mail2.gif',1)});
    m.mouseout(function(){MM_swapImgRestore()});
  }

  $('#ifFacebook').attr('src', $('#ifFacebook').attr('src') + encodeURIComponent(location.href)); 

  if(!(is_natale || is_halloween)) {
  //  SetupXmasDecoScene();
  }
});

/* */
var xmas_lysx;
var xmas_lydx;
var xmas_deco_active=true;
function SetupXmasDecoScene() {
  $('table:first').append('<div style="width:980px;height:0px;" id="xmas_deco"></div>');
  xmas_lysx=$('<div/>', { id: 'lysx', style: 'display:none;position:absolute;z-index:1000;' }).append($('<img/>', {src: '/immagini/ly_sx.png'})).appendTo($('body'));
  xmas_lydx=$('<div/>', { id: 'lydx', style: 'display:none;position:absolute;z-index:1000;' }).append($('<img/>', {src: '/immagini/ly_dx.png'})).appendTo($('body'));
  UpdateXmasDecoScene();
};
function UpdateXmasDecoScene() {
  if(xmas_deco_active && !jQuery.browser.msie) {
    var o=$('#xmas_deco').offset();
    xmas_lysx.css({left: o.left-160, top: 0});
    xmas_lydx.css({left: o.left+940, top: 0});
    xmas_lysx.show();
    xmas_lydx.show();
  }
}
$(window).resize(function() {
  UpdateXmasDecoScene();
});
/* */


