/* --- */


/* var xmlhttp; */



function initA(){
    var xmlhttp = false;
    
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhhtp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(e2) {
            xmlhttp = false;
        }
    }
    
    if (!xmlhttp && typeof XMLHttpReqest == 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    
    if (!xmlhttp) {
        alert('XMLHttpRequest faled.');
        exit;
    }
    return xmlhttp;
}


function showPhoto(id){
    
        xmlhttp = initA();           

//     var obj = document.getElementById('500');
    if(1){
        var url = "/inc/photoa.php";
        
        var pstring = "id="+escape(id);
        xmlhttp.open("POST", url, true);
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", pstring.length);
        
        
        xmlhttp.onreadystatechange = showDiv;
        
        xmlhttp.send(pstring);
    }

}



function showDiv(){


    if(xmlhttp.readyState == 4){

        var obj = document.getElementById('500');
    	
        if(obj){
    	    document.body.removeChild(obj);
    	}
    	

    	var t=(document.body.clientWidth/2)-350+document.documentElement.scrollTop;
    	var l=(document.body.clientHeight/2)-150;
        var response = xmlhttp.responseText.split("|:|");
        var pwidth = parseInt(response[3])+40;
        var pheight = parseInt(response[4])+200;
        
        var tmp = document.createElement('DIV');                          
        tmp.id = '500';
        st=tmp.style;
    	st.position="absolute";
    	st.display="block";
    	st.background="#f9f9f3";
    	st.color="#000";
    	st.zIndex=999;
    	st.width= pwidth+'px';
        st.height= pheight+'px';
    	st.top = t+'px';
    	st.left = l+'px';
    	st.borderColor="#4C721D";
    	st.borderWidth='2px';
    	st.borderStyle="solid";
        
/*
    	t=t-(pwidth/2);
        l=l-(pheight/2);
        st.top = t+'px';
    	st.left = l+'px';
*/        
        tmp.innerHTML  = "<div style=\"width:"+(pwidth-20)+"px; margin:5px 00px 5px 00px; text-align:right; font-weight:bold; color:#4C721D; font-size:14px;\"><span style=\"cursor: pointer;\" onclick=\"document.body.removeChild(document.getElementById('500'));\">close window</span></div>";
        tmp.innerHTML += "<div style=\"width:"+response[3]+"px; margin:0px 0px 0px 20px; height:"+response[4]+"\"><img id=\"divimage\" src=\"photos/gallery/big/"+response[2]+"\"/></div>";
        tmp.innerHTML += "<div style=\"width:"+(pwidth-40)+"px; margin:10px 20px 10px 20px;\"><span style=\"font-weight:bold; color:#4C721D; font-size:14px;\">"+response[0]+"</span><br/>"+response[1]+"</div>";
        document.body.appendChild(tmp);
    }
    
}



/* --- */
function photopage(classname, id, imgfrom, imgto, imgcur) {    

    var url = '../ajax/images.php';
    var pars = 'classname='+classname+'&id='+id+'&imgfrom='+imgfrom+'&imgto='+imgto+'&imgcur='+imgcur;
    
	var myAjax = new Ajax.Request(
        url, 
        {method: 'get', parameters: pars, onFailure: reportError, onComplete: function(r){restoreimages(r)}});
       
    return false;
}

function restoreimages (r) {
    var ret=r.responseText;
    var imagesnav=$("imagesnav");
    imagesnav.innerHTML=ret;
}

function photoset (classname, id, imgcur) {    
    
    var url = '../ajax/imageplace.php';
    var pars = 'classname='+classname+'&id='+id+'&imgcur='+imgcur;
    
	var myAjax = new Ajax.Request(
        url, 
        {method: 'get', parameters: pars, onFailure: reportError, onComplete: function(r){restoreimageplace(r)}});
       
    return false;    
}

function restoreimageplace(r) {    
    var ret=r.responseText;
    var imagesnav=$("imageplace");
    imagesnav.innerHTML=ret;
}

function reportError(request) {
    alert('Sorry. There was an error.');
}

function myshow(field, id) {
    
    var reshow=1;
    if (show_desc) {
        if (show_desc==id) var reshow=0;
    }
    
    if (reshow) {
    	var posy=getPosition(field)[1];
    	var posx=getPosition(field)[0];    	
    	var div=$(id);
    	div.style.position="absolute";
    	div.style.top=eval(posy-20)+"px";
    	div.style.left=eval(posx-20)+"px";    
    	div.style.display="block";
    	show_desc=id;
    }
}

function myhide(id) {
    var div=$(id);
    div.style.display="none";
    show_desc=0;
}

function getPosition(obj) {
    var o=obj; 
    var x=0, y=0; 
    while(o) { 
        x+=o.offsetLeft; 
        y+=o.offsetTop; 
        o=o.offsetParent; 
    } 
    return [x,y]; 
}

var win;
function big_photo(f,w,h) {
    if (win) {
        win.close();        
    }
    
    win=window.open('../photo.php?f='+f, null, "width="+w+",height="+h+",toolbar=0,scrollbars=no,resizable=no");    
    return false;
}  

function viewImg(image_href){
      var xstr = 'scrollbars=no,toolbar=no,status=no,menubar=no,directories=no,location=no,resizable=yes,width=160,height=160';
      var prodWindow = window.open(image_href, 'window'+Math.round(Math.random()*1000), xstr);
      if (prodWindow) prodWindow.focus();
}

function backToSite(){
	var prodWindow = window.opener;
	if (prodWindow){
		prodWindow.focus();
		window.close();
	}
}

function housePrew(url, dir_image, image_name){
    var house_prev = document.getElementById('house');
    house_prev.innerHTML = '<a href="/view_img.php?dir_image='+dir_image+'&amp;image_name='+image_name+'" target="_blank" onclick="viewImg(this.href); return false;"><img src="'+url+dir_image+'/medium/'+image_name+'" alt="" /></a>';
}
