I have another Problem, but this seems to be a deeper html/js problem.
i have changed the code to the following:
// Insert Image
function spawnIMGBox(target,file) {
img = new Image();
img.src = file;
if(img.complete) {
if(img.width>'700') {
spawnBox(target,img.width*0.5,img.height*0.5);
} else {
spawnBox(target,img.width,img.height);
}
setIMGBox(target,file,'setImage');
} else {
setTimeout('setIMGBox("'+target+'","'+file+'","none");',10);
}
}
function setIMGBox(target,file,status) {
if(img.width!=0) {
if(status == 'none') {
spawnBox(target,img.width,img.height);
status = 'boxLoaded';
}
if(status == 'boxLoaded') {
setTimeout('setIMGBox("'+target+'","'+file+'","setImage");',325);
} else if(status == "setImage") {
if(img.complete) {
gEBI(target+'Content').innerHTML = '<img src="'+img.src+'" width="100%" id='+target+'ImageBox style="filter:alpha(opacity=0);opacity:0"/>';
boxFade(target,'img');
setName(file);
img = null;
} else {
setTimeout('setIMGBox("'+target+'","'+file+'","setImage");',200);
}
} else if(status == 'setImmediatly') {
gEBI(target+"Content").innerHTML = '<img src="'+img.src+'"/>';
setName(file);
img = null;
}
} else {
setTimeout('setIMGBox("'+target+'","'+file+'","none");',50);
}
}
so i resize the images if they are bigger that 700px to the 50% of its width.
but now my problem is, that the image is only displayed in its new size if i click twice on the preview button.
this seems to be because the code didn't analyse the picture completely.
i thought the img.complete condition is for that !?
how can i make sure that the picture is resized correctly by the first try ?
hopefully s.o. can help me.
greetz
stit
EDIT:
i got it. status has to be set as none and not setImmediately.
then the box is set first and then the image is loaded. that solves the problem.
here my code with which it works well:
// Insert Image
function spawnIMGBox(target,file) {
img = new Image();
img.src = file;
if(img.complete) {
spawnBox(target,img.width,img.height);
setIMGBox(target,file,'none');
} else {
setTimeout('setIMGBox("'+target+'","'+file+'","none");',10);
}
}
function setIMGBox(target,file,status) {
if(img.width!=0) {
if(status == 'none') {
if(img.width>'700') {
spawnBox(target,img.width*0.5,img.height*0.5);
} else {
spawnBox(target,img.width,img.height);
}
status = 'boxLoaded';
}
if(status == 'boxLoaded') {
setTimeout('setIMGBox("'+target+'","'+file+'","setImage");',325);
} else if(status == "setImage") {
if(img.complete) {
gEBI(target+'Content').innerHTML = '<img src="'+img.src+'" width="100%" id='+target+'ImageBox style="filter:alpha(opacity=0);opacity:0"/>';
boxFade(target,'img');
setName(file);
img = null;
} else {
setTimeout('setIMGBox("'+target+'","'+file+'","setImage");',200);
}
} else if(status == 'setImmediatly') {
gEBI(target+"Content").innerHTML = '<img src="'+img.src+'"/>';
setName(file);
img = null;
}
} else {
setTimeout('setIMGBox("'+target+'","'+file+'","none");',50);
}
}
EDIT2:
better solution with max-width:700px
// Insert Image
function spawnIMGBox(target,file) {
img = new Image();
img.src = file;
if(img.complete) {
spawnBox(target,img.width,img.height);
setIMGBox(target,file,'none');
} else {
setTimeout('setIMGBox("'+target+'","'+file+'","none");',10);
}
}
function setIMGBox(target,file,status) {
if(img.width!=0) {
if(status == 'none') {
if(img.width>'700') {
spawnBox(target,700,img.newheight);
} else {
spawnBox(target,img.width,img.height);
}
status = 'boxLoaded';
}
if(status == 'boxLoaded') {
setTimeout('setIMGBox("'+target+'","'+file+'","setImage");',325);
} else if(status == "setImage") {
if(img.complete) {
gEBI(target+'Content').innerHTML = '<img src="'+img.src+'" width="100%" id='+target+'ImageBox style="filter:alpha(opacity=0);opacity:0"/>';
boxFade(target,'img');
setName(file);
img = null;
} else {
setTimeout('setIMGBox("'+target+'","'+file+'","setImage");',200);
}
} else if(status == 'setImmediatly') {
gEBI(target+"Content").innerHTML = '<img src="'+img.src+'"/>';
setName(file);
img = null;
}
} else {
setTimeout('setIMGBox("'+target+'","'+file+'","none");',50);
}
}