// Copyright (C) 2006 Tundra Club/Hearing Voices
// Permission granted to use code provided this
// and any other copyright messages are retained.
// Hearing Voices http://www.hearingvoices.com


//////////////////////
// Blows thru series of imgs, stops @ 1st;
// blows, stops @ 2nd; etc.

// pre-load images; set "i<=" # of images
// image-names (and paths) the same except for numer at end;
// e.g. img/image1.jpg, img/image2.jpg...

// starts script after page-load
function imgBlo(imgblo_dir, imgblo_file, imgblo_ext, imgblo_start, imgblo_num, imgblo_speed, imgblo_pause, imgblo_loop) {
	ib_dir = imgblo_dir;
	ib_file = imgblo_file; 
	ib_ext = imgblo_ext; 
	ib_start = imgblo_start;
	ib_num = imgblo_num;
	ib_speed = imgblo_speed;
	ib_pause = imgblo_pause;
	ib_loop = imgblo_loop;
	
	ib_count = -1;
	ib_imgnum = ib_arrnum = imgblo_num;
	
	if (document.images)  {
		pic = new Array();
		for (var i=1; i<=ib_num; i++) {
			pic[i] = new Image();
			// images-dir/images-names (w/o number) & images-extension.
			pic[i].src = ib_dir + '/' + ib_file + i + '.' + ib_ext; 
		}
	}
	
	setTimeout('startImgBlo()', ib_start)	
}

//skip thru all imgs, pause @ 1st, skip thru all, pause @ 2nd, etc.
function startImgBlo() {
	if (document.images)  {
		if (ib_arrnum > ib_num) ib_arrnum = 1;
    	if (ib_imgnum != ib_arrnum) { 
    		t = ib_speed; // t=  skip speed
    		document.images["BlowImg"].src = pic[ib_arrnum].src;
			ib_arrnum++;
    		ImgGo = setTimeout('startImgBlo()', t);
    	} 	else {
        		t = ib_pause; // t= pause duration
				ib_imgnum++;
	       		ib_arrnum++;
        		if (ib_arrnum > ib_num) ib_arrnum = 1;
        		if (ib_imgnum > ib_num) {
        			ib_imgnum = 1;
        			ib_count++;
        		}      		
				document.images["BlowImg"].src = pic[ib_arrnum].src;
				ib_arrnum++;
	   			if (ib_count < ib_loop) {
	   				ImgGo = setTimeout('startImgBlo()', t);
        		}	else {
	   					clearTimeout(ImgGo);
	   				}
    		}
    }  
}

// In body tag: onLoad='imgBlo();' to start upon page load, or
// In body tag: onLoad='startImgBlo();' to wait, then start.
// In img tag: src="image-path/image-name1.gif" name="BlowImg" 
////////////////////// 


//////////////////////
// Replace image, no pre-load; Requires jQuery


function imgClick(ic_text, ic_dir, ic_file, ic_ext, ic_num, ic_load) {
		
	imgload = new Image();
	imgload.src = ic_dir + '/' + ic_load;

	clicker = '<div><span class="ic_link">' + ic_text;
	clicker += '&raquo;</strong></span>';	
	$('#imgclick').append(clicker);	
	
	/* Add link events/behaviors to images and nav-text */
	$('#imgclick img:eq(0), #imgclick .ic_link').css({'cursor' : 'pointer', 'color' : '#369'});
	$('#imgclick img:eq(0), #imgclick .ic_link').mouseover(function(){window.status='Click for next image.';return true;});
	$('#imgclick img:eq(0), #imgclick .ic_link').mouseout(function(){window.status='';return true;});

	var a = 1;	
	$('#imgclick img:eq(0), #imgclick .ic_link').bind('click', function() {
		a++;
		if(a > ic_num) a = 1;
		$('#imgclick img:eq(0)').attr('src', imgload.src);
		$('#imgclick img:eq(0)').attr('src', ic_dir + '/' + ic_file + a + '.' + ic_ext);
	});
}

function imgClick2(ic_text, ic_dir, ic_file, ic_ext, ic_num) {
	
	$('#imgclick2').append(clicker);	
		
	/* Add link events/behaviors to images and nav-text */
	$('#imgclick2 img:eq(0), #imgclick2 .ic_link').css({'cursor' : 'pointer', 'color' : '#369'});
	$('#imgclick2 img:eq(0), #imgclick2 .ic_link').mouseover(function(){window.status='Click for next image.';return true;});
	$('#imgclick2 img:eq(0), #imgclick2 .ic_link').mouseout(function(){window.status='';return true;});

	var b = 1;
	$('#imgclick2 img:eq(0), #imgclick2 .ic_link').bind('click', function() {
		b++;
		if(b > ic_num) b = 1;
		$('#imgclick2 img:eq(0)').attr('src', imgload.src);
		$('#imgclick2 img:eq(0)').attr('src', ic_dir + '/' + ic_file + b + '.' + ic_ext);
	});
}
////////////////////// 
