var img_path="";
var small_size=80;



var img_path="";

	function set_margin_b(p_num){
		//alert(document.getElementById('small_pic_table'+p_num).clientHeight);
	}
	
	function makeRequest_X(p_link,p_fid){
		var tmp_size=get_screen_size();		
		var topX=(tmp_size[0]/2)-(70/2);
		var topY=(tmp_size[1]/2)-(15/2)+f_scrollTop()-20;
		
		setStyle(document.getElementById('load'),"left:"+topX+"px;top:"+topY+"px;visibility:visible;")
		
		if(p_fid!=-1)
			remove_photo(p_fid);
		makeRequest(p_link);
	}
	
	
	function set_pic_size(p_path){
		//alert("here");
		img_path=p_path;	
	
	}

	function f_scrollTop() {
		return f_filterResults (
			window.pageYOffset ? window.pageYOffset : 0,
			document.documentElement ? document.documentElement.scrollTop : 0,
			document.body ? document.body.scrollTop : 0
		);
	}
	
	function f_filterResults(n_win, n_docel, n_body) {
		var n_result = n_win ? n_win : 0;
		if (n_docel && (!n_result || (n_result > n_docel)))
			n_result = n_docel;
		return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
	}

	
	function get_screen_size(){				
		var size=new Array(630,460);
		
		if (parseInt(navigator.appVersion)>3) 
 			if (navigator.appName=="Netscape") {
  				size[0] = window.innerWidth;
  				size[1] = window.innerHeight;
 			}
 		if (navigator.appName.indexOf("Microsoft")!=-1) {
  			size[0] = document.body.offsetWidth;
  			size[1] = document.body.offsetHeight;
 		}
		
		return size;
	
	}
	
	function add_photo(p_width,p_height,p_nazov,p_imgsrc,p_id,p_gid,p_way,p_linky){	
		//alert();
		
		var tmp_size=get_screen_size();		
		var topX=(tmp_size[0]/2)-(p_width/2);
		var topY=(tmp_size[1]/2)-(p_height/2)+f_scrollTop()-20;
		var tmp_nazov=p_nazov;
		
		
		var photo_div= document.createElement('div');
		photo_div.setAttribute('id',p_id);
		photo_div.setAttribute('className','big_photo');
		photo_div.setAttribute('class','big_photo');
		setStyle(photo_div,"top:"+topY+"px;left:"+topX+"px;width:"+(parseInt(p_width)+6)+"px");
		
		
		
		linka_l="<a id=\"linka_l\" href=\"javascript:makeRequest_X('photo_list.php?fid="+p_id+"&gid="+p_gid+"&way=1','"+p_id+"');\">prev</a>|";
		linka_p="<a id=\"linka_r\" href=\"javascript:makeRequest_X('photo_list.php?fid="+p_id+"&gid="+p_gid+"&way=2','"+p_id+"');\">next</a>";
		
		if(p_linky==1||p_linky==0){
			linka_p="";	
		}
		
		if(p_linky==2||p_linky==0){
			linka_l="";	
		}
				
		photo_div.innerHTML="<table style=\"table-layout:fixed;\"><tbody><tr><td style=\"width:96%; overflow:hidden;\"><cite><b>Caption:&nbsp;</b>"+tmp_nazov+"</cite></td><td><a href=\"javascript:remove_photo("+p_id+")\" >X</a></td></tr><tr><td colspan=\"2\"><img src=\""+p_imgsrc+p_id+".jpg\"  /></td></tr></tbody></table>"+linka_l+linka_p;

		obsah.appendChild(photo_div);
		//document.getElementById('obsah').removeChild(photo_div);
		return 0;
	}
	
	var httpRequest="";
	
	function makeRequest(url) {						        
		//alert("here");
        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/xml');
                // See note below about this line
            }
        } 
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } 
                catch (e) {
                           try {
                                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                               } 
                             catch (e) {}
                          }
                                       }

        if (!httpRequest) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        httpRequest.onreadystatechange = function() { ajax_f(httpRequest); };
        httpRequest.open('GET', url, true);
        httpRequest.send('');		

    }

	function ajax_f(httpRequest) {
		//ajaxovica
		//alert(httpRequest.readyState);
        if (httpRequest.readyState == 4) {
			
            if (httpRequest.status == 200) {
				if(httpRequest.responseXML.getElementsByTagName('err')[0].firstChild.data=='0'){
					var fid=httpRequest.responseXML.getElementsByTagName('fid')[0].firstChild.data;
					var gid=httpRequest.responseXML.getElementsByTagName('gid')[0].firstChild.data;
					var caption=httpRequest.responseXML.getElementsByTagName('caption')[0].firstChild.data;
					var width=httpRequest.responseXML.getElementsByTagName('width')[0].firstChild.data;
					var height=httpRequest.responseXML.getElementsByTagName('height')[0].firstChild.data;
					var linky=httpRequest.responseXML.getElementsByTagName('linky')[0].firstChild.data;
					setStyle(document.getElementById('load'),"visibility:hidden;");
					add_photo(width,height,caption,img_path,fid,gid,0,linky);
					
//					alert(fid+":"+gid+":"+caption+":"+width+":"+height+":"+linky);
					
					
				}
			}
		}
	}
	
	function setStyle( object, styleText ) {
		if( object.style.setAttribute ) {
			object.style.setAttribute("cssText", styleText ); } 
		else { 
			object.setAttribute("style", styleText ); 
		}
	}
	
	
	
	
	function remove_photo(p_id){		
		var t_div=document.getElementById(p_id);
		obsah.removeChild(t_div);
	}


