// newsfeed.js
// requires functions: changeOpac, opacity, WriteByID
// requires hTester DIV

var fadeInTime = 500;
var fadeOutTime = 500;
var growTime = 250;
var changingImage = false;
function change_img(target,src,width,height) {
	if (changingImage == false) {
		changingImage = true;
		WriteByID('hTester',null,'<img src="'+src+'" />');
		opacity(target, 100, 0, fadeOutTime);
		setTimeout("prep_height('"+target+"','"+src+"','"+width+"','"+height+"')",fadeOutTime);
		for (i=0; i<gal_images.length; i++) {
			if (src == gal_images[i]['src']) {
				if (i >= gal_images.length - 1) {
					curGalImg = gal_images.length - 1;
				} else {
					curGalImg = i;	
				}
			}
		}
		
	}
}

function change_gal_img() {
	if (changingImage == false) {
		
		if (curGalImg >= gal_images.length - 1) {
			curGalImg = 0;
		} else {
			curGalImg++;	
		}
		src = gal_images[curGalImg]['src'];
		width = gal_images[curGalImg]['width'];
		height = gal_images[curGalImg]['height'];
		target = 'mainImg';
		changingImage = true;
		WriteByID('hTester',null,'<img src="'+src+'" />');
		opacity(target, 100, 0, fadeOutTime);
		setTimeout("prep_height('"+target+"','"+src+"','"+width+"','"+height+"')",fadeOutTime);
	}
}

function prep_height(target,src,width,height) {
	var holder = target+"Div";
	var ht = 20;
	if (document.getElementById(holder).style.height) {
		ht = document.getElementById(holder).style.height.replace("px","");
	}
	wd = document.getElementById(holder).style.width.replace("px","");
	growY(holder, ht, height, growTime);		
	setTimeout("display_img('"+target+"','"+src+"','"+width+"','"+height+"')",growTime);
}

function display_img(target,src,width,height) {
	changeOpac(0, target);
	document.getElementById(target).src = src;
	document.getElementById(target).height = height;
	document.getElementById(target).width = width;
	opacity(target, 0, 100, fadeInTime);
	changingImage = false;
}

function growY(id, start, end, millisec) {

	//speed for each frame
	var speed = Math.round(millisec / Math.abs(parseInt(end) - parseInt(start)) * 100)/100;
	var timer = 0;	
	if (start > end) {
		for (i = parseInt(start); i >= parseInt(end); i--) {
			setTimeout("growByID(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else {
		for (i = parseInt(start); i <= parseInt(end); i++) {
			setTimeout("growByID(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}
function growByID(h,id) {
	document.getElementById(id).style.height = h+"px";
}
