function zmniejszFotke(){
	w=document.getElementById('newWidthInput');
	h=document.getElementById('newHeightInput');
	
	function resize(id,width,height){
		id=document.getElementById(id);
		id.style.width=width+'px';
		id.style.height=height+'px';
		w.value=width;
		h.value=height;
		est_filesize=Math.round((w.value*h.value*56)/172800);
		holder=document.getElementById('fileSize');
		holder.innerHTML=est_filesize + ' kB';
	}
	
	horizontalButton=document.getElementById('horizontalButton');
	verticalButton=document.getElementById('verticalButton');
	widthRatio=document.getElementById('widthRatio');
	
	w.onchange=function () { 	
		width=w.value;
		height=Math.round(width / eval(widthRatio.value));
		resize ('zmniejszona-fotka',width,height);
	}
		h.onchange=function () {
		height=h.value;
		width=Math.round(height*eval(widthRatio.value));
		resize ('zmniejszona-fotka',width,height);
	}
	
	horizontalButton.onclick=function(){
		if(widthRatio.value=='3/4'){
			widthRatio.value='4/3';
			oldwidth=w.value;
			width=h.value;
			height=oldwidth;
			resize ('zmniejszona-fotka',width,height);
			verticalButton.style.background='white';
			horizontalButton.style.background='#f00;';
		}
	}

	verticalButton.onclick=function(){
		if(widthRatio.value=='4/3'){
			widthRatio.value='3/4';
			oldwidth=w.value;
			width=h.value;
			height=oldwidth;
			resize ('zmniejszona-fotka',width,height);
			verticalButton.style.background='#f00;';
			horizontalButton.style.background='none';
		}
	}
}
function showhide(x) {
   var object=document.getElementById(x)
   object.style.display=object.style.display=='block'?'none':'block'
}


function bookmark(){
    var title="Zmniejsz fotkę";
    var url="http://www.zmniejszfotke.pl";

    if (window.sidebar) window.sidebar.addPanel(title, url,"");

    else if( window.opera && window.print )
    {
    var mbm = document.createElement('a');
    mbm.setAttribute('rel','sidebar');
    mbm.setAttribute('href',url);
    mbm.setAttribute('title',title);
    mbm.click();
    }

    else if( document.all ) window.external.AddFavorite( url, title);

}

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}	
function getCookie(c_name) {
if (document.cookie.length>0)  {
	c_start=document.cookie.indexOf(c_name + "=");
	if (c_start!=-1) { 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
return "";
}

function preloader_off(){
	preloader=document.getElementById('preloaderHolder');
	preloader.style.display="none";
}
function preloader_on(){
	preloader=document.getElementById('preloaderHolder');
	preloader.style.display="block";
	check_upload(); 
}


function check_upload() {
	cookie=getCookie('resizing_ended');
	//preloader=document.getElementById('preloaderHolderP');
	
	if(cookie==0){
		setTimeout("check_upload()",1000);
		//preloader=

/* 		ie=(document.all)?true:false
		ns=(document.layers)?true:false
 */		
	} else {
/* 		if(ie){
			setCookie('resizing_ended',0,1);
			preloader_off();
		} else { */
			/*window.location.reload(true);*/
			window.location.href="http://www.zmniejszfotke.pl";
		
	}
}


window.onload=function () { 
 	zmniejszFotke();
	
	function resize(id,width,height){
		id=document.getElementById(id);
		id.style.width=width+'px';
		id.style.height=height+'px';
		w.value=width;
		h.value=height;
		est_filesize=Math.round((w.value*h.value*56)/172800);
		holder=document.getElementById('fileSize');
		holder.innerHTML=est_filesize + ' kB';
	}
	
	width=document.getElementById('newWidthInput').value;
	height=document.getElementById('newHeightInput').value;
	
	
	resize('zmniejszona-fotka',width,height);

}


