var k = 0;
var z = 0;

// POPUP
function pop(pagina, titolo, w, h) {
 var left = (screen.width/2)-(w/2);
 var top = (screen.height/2)-(h/2);
 var targetWin = window.open (pagina, titolo, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}

// FLASH FIX
function showFlash(flashfile, w, h) {
 document.write('<object id="flaa" classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="obj1" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0" width="'+w+'" height="'+h+'">');
 document.write(' <param name="movie"   value="'+flashfile+'">');
 document.write(' <param name="quality" value="high">');
 document.write(' <param name="wmode"   value="transparent">');
 document.write(' <param name="AllowScriptAccess" value="always">');
 document.write(' <embed src="'+flashfile+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" name="obj1" quality="High" AllowScriptAccess="always" width="'+w+'" height="'+h+'">');
 document.write('</object>');
}

// SET COOKIE
function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}
// READ COOKIE
function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
// CHECK BROWSER WIDTH AND SET COOKIE
var viewportwidth, viewportheight;
function checkWindowWidth() {
 if (typeof window.innerWidth != 'undefined')
  { viewportwidth = window.innerWidth; viewportheight = window.innerHeight }
 else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
  { viewportwidth = document.documentElement.clientWidth; viewportheight = document.documentElement.clientHeight }
 else
  { viewportwidth = document.getElementsByTagName('body')[0].clientWidth; viewportheight = document.getElementsByTagName('body')[0].clientHeight }
 SetCookie('screen_width',viewportwidth,365);
}
checkWindowWidth();


window.onload = function () {
 FullScreenBackground('#photo');
 FullScreenBackground('#fader');
}
$(window).resize(function() {
 FullScreenBackground('#photo');
 FullScreenBackground('#fader');
});
function FullScreenBackground(theItem){
var winWidth=$(window).width();
var winHeight=$(window).height();
var imageWidth=$(theItem).width();
var imageHeight=$(theItem).height();
var picHeight = imageHeight / imageWidth;
var picWidth = imageWidth / imageHeight;
if ((winHeight / winWidth) < picHeight) {
$(theItem).css("width",winWidth);
$(theItem).css("height",picHeight*winWidth);
} else {
$(theItem).css("height",winHeight);
$(theItem).css("width",picWidth*winHeight);
};
$(theItem).css("margin-left",winWidth / 2 - $(theItem).width() / 2);
$(theItem).css("margin-top",winHeight / 2 - $(theItem).height() / 2);
}

// FADE PHOTOS
var t = 500;
function fadeTop(img) {
 opa   = top.document.getElementById('fader').style.opacity;
 opaIE = top.document.getElementById('fader').style.filter;
 if(opa==1 || opa==0 || opa=='' || opaIE=='alpha(opacity=100)' || opaIE=='alpha(opacity=0)' || opaIE=='') {
  top.document.getElementById('fader').src = top.document.getElementById('photo').src;
  $('#fader').fadeIn(0);
  top.document.getElementById('photo').src = img;
  $('#fader').fadeOut(t);
  setTimeout( "top.document.getElementById('fader').src = ''", t);
 }
}

// SLIDESHOW
function slideShow(path, photo) {
 exe.location.replace('exe_slide.php?path='+path+'&photo='+photo)
}

// LIVE SEARCH
function showResult(str)
{
if (str.length==0)
  {
  document.getElementById("livesearch").innerHTML="";
  document.getElementById("livesearch").style.display="none";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    str = xmlhttp.responseText;
    document.getElementById("livesearch").innerHTML=str;
    document.getElementById("livesearch").style.display="block";
    if(str=='') document.getElementById("livesearch").style.display="none";
    }
  }
 xmlhttp.open("GET","exe_livesearch.php?c="+str,true);
 xmlhttp.send();
}
