// Guy Herschell Architects Index Slideshow Scripting Slideshow Version 15.02 - centered images
// SpaceofCreation 2011. wwww.spaceofcreation.co.nz
// Tested X platform on all browsers as working on 18 May 2011

// get picture names from directory 
var numberofslides133=17
var numberofslides132=13
var numberofslides117=14
var numberofslides101=15

var total_slides = numberofslides133+numberofslides132+numberofslides117+numberofslides101
var lights=true		// toggle lights on or off
var pauseflag=false // toggle slide pause on or off
var project_url = ""
var n133= new Array()
var n132= new Array()
var n117= new Array()
var n101= new Array()
var picture= new Array()

n101[0]="images/97B0.jpg"
n101[1]="images/97B2.jpg"
n101[2]="images/100B10.jpg"
n101[3]="images/100B11.jpg"
n101[4]="images/100B12.jpg"
n101[5]="images/101B0.jpg"
n101[6]="images/101B1.jpg"
n101[7]="images/101B7.jpg"
n101[8]="images/101B8.jpg"
n101[9]="images/101B9.jpg"
n101[10]="images/102B2.jpg"
n101[11]="images/102B3.jpg"
n101[12]="images/110B0.jpg"
n101[13]="images/110B1.jpg"
n101[14]="images/110B2.jpg"

for (var i=0; i<numberofslides133; i++){n133[i]="images/133B"+i+".jpg"}
for (var i=0; i<numberofslides132; i++){n132[i]="images/132B"+i+".jpg"}
for (var i=0; i<numberofslides117; i++){n117[i]="images/117B"+i+".jpg"}
//omitted curently for user specified.
//for (var i=0; i<numberofslides101; i++){n101[i]="images/101B"+i+".jpg"}
var picture = n133.concat(n132,n117,n101)

// width and height for quick script alterations 
var max_width = 1200  
var max_height= 600
var slideshow_width=max_width
var slideshow_height=max_height
var align_left = 0
var align_top = 0
var pause=2.75

// math operation varaibles for quick script alterations
var x_slices=1
var content=""
var counter=0
var cliptop=0
var clipbottom=0
var i_clipright=1
var width_slice
var step=10
var fadestrength=0
var text_fadestrength=fadestrength
var fadestrength_step=slideshow_width/2200
pause=pause*1000

// initial fade variables
var startfadeval=35
var fadeflag=false

// write containers 
content="<table cellpadding=0 cellspacing=0 border=0 align ='center' width="+slideshow_width+"><tr><td width="+slideshow_width+" height="+slideshow_height+"><a href="+project_url+"></a></td></tr><tr></table>"
document.write("<div id='togglemain' class='slide_style' align ='center' style='position:relative;width:"+slideshow_width+"px;height:"+(slideshow_height)+"px; filter:alpha(opacity=100) visibility: visible'>")
document.write("<div id='whole' style='position:absolute;top:0px;left:0px;width:"+slideshow_width+"px;height:"+(slideshow_height)+"px;filter:alpha(opacity=100);'>"+content+"</div>")
for (i=0;i<=x_slices;i++) {
document.write("<div id='s"+i+"' style='position:absolute;top:0px;left:0px;width:"+slideshow_width+"px;height:"+(slideshow_height)+"px;filter:alpha(opacity=100);'>"+content+"</div>")
}
document.write("</div>")

// write pictures to window as they load
document.write("<div id='start_overlay' class ='loadingol' style='filter:alpha(opacity=35); opacity: .35;'>")
var imgpreload=new Array();
for (iii=0;iii<=picture.length-1;iii++) {
	imgpreload[iii] = new Image();
	imgpreload[iii].src = picture[iii];
 	var img_content="<img src='"+picture[iii]+"' class ='indeximg' id ='w"+iii+"' style='filter:alpha(opacity=35); opacity: 0.35;' width='117' height='117'>"	
	document.write (img_content)
	}
document.write ("</div>")

// close document and initiate on page load.
document.close()
window.onload=initiate

// fadeout images for slide show.
function fade_out() { 
	if (startfadeval > 0) {
    var starts=document.getElementById('start_overlay').style
		//internet explorer
		if (document.all) {
		var startfilter=start_overlay
		startfilter.filters.alpha.opacity=Math.round(startfadeval)
		}
		//gecko based
		else {
			
		starts.opacity=(startfadeval/100)
		}
	startfadeval=startfadeval-1
    var startfade=setTimeout("fade_out()",1)
	}
	else {
		document.getElementById('start_overlay').style.visibility ="hidden"
		startfade=clearTimeout(startfade)
		fadeflag = true	
	}	
doslide()
}

// toggle slide pause for slide show
function pause_slides(){ 
	if (pauseflag == false){ 
	pauseflag = true; 
	var pause_content ="<span class='namestyle'>Pause</span>"
	document.getElementById("pausestatus").innerHTML = pause_content
	}
	else { pauseflag = false;
	var pause_content ="<span class='namestyle_highlight'>Pause</span>"
	document.getElementById("pausestatus").innerHTML = pause_content
	doslide()
	}
}

// turn all lights off for slide show
function lightsonoff(){
	if (lights==true) { 
		document.getElementById("topbanner").style.visibility="hidden";
		document.getElementById("topline").style.visibility="hidden";
		document.getElementById("bottomline").style.visibility="hidden";
		document.getElementById("quotewindow").style.visibility="hidden";
// 		Temporarily turn of logos removed.
//		document.getElementById("nzia").style.visibility="hidden";
//		document.getElementById("nzrab").style.visibility="hidden";
		document.getElementById("addlinea").style.visibility="hidden";
		document.getElementById("addlineb").style.visibility="hidden";
		document.getElementById("loading").style.opacity=0;
		var lights_content ="<span class='namestyle'>Lights</span>"
		document.getElementById("lightstatus").innerHTML = lights_content
		lights = false
	}	
	else {	
		document.getElementById("topbanner").style.visibility="visible";
		document.getElementById("topline").style.visibility="visible";
		document.getElementById("bottomline").style.visibility="visible";
		document.getElementById("quotewindow").style.visibility="visible";
// 		Temporarily turn of logos removed.
//		document.getElementById("nzia").style.visibility="visible";
//		document.getElementById("nzrab").style.visibility="visible";
		document.getElementById("addlinea").style.visibility="visible";
		document.getElementById("addlineb").style.visibility="visible";
		document.getElementById("loading").style.opacity=1;
		var lights_content ="<span class='namestyle_highlight'>Lights</span>"
		document.getElementById("lightstatus").innerHTML = lights_content
		lights = true
	}
}

// switchoff loading giff
function loading(){
	document.getElementById("loading").style.visibility = "visible";
}

// switchoff loading giff
function finishedloading(){
    document.getElementById("loading").style.visibility = "hidden";

}

// initiate math functions, fade out thumbs and doslide
function initiate() {
// load overlay?
	if (do_what=="email"){ 
	do_info("email")
	}
	else {}
// initiate math fucntions
	width_slice=Math.ceil(slideshow_width/x_slices)
	clipbottom=(slideshow_height)
	finishedloading()
	fade_out()
}


// peform fade in IE and Firefox. X platform.
function sliceimage() {
	clipleft=-width_slice
	clipright=0
    if (i_clipright<=width_slice) {
        for (i=0;i<=x_slices;i++) {
        var thiss=eval("document.getElementById('s"+i+"').style")
     	var text_op=document.getElementById("indexquote").style
		var under_lay = document.getElementById("whole").style
		thiss.clip ="rect("+cliptop+"px "+clipright+"px "+clipbottom+"px "+clipleft+"px)"
        clipleft+=width_slice
        clipright=clipleft+i_clipright
		//internet explorer
		if (document.all) {
		var thisfilter=eval('s'+i)
		thisfilter.filters.alpha.opacity=Math.round(fadestrength)
			//	fade underlay as new slide fades in	
			var ie_fade = 100-fadestrength
			whole.filters.alpha.opacity=Math.round(ie_fade)
		}
		else {
		thiss.opacity=(fadestrength/100)
 		text_op.opacity=(text_fadestrength/100)
			var ff_fade = 1-(Math.round(fadestrength)/100)
			under_lay.opacity=(ff_fade)
		}
		fadestrength+=fadestrength_step
		text_fadestrength+=fadestrength_step
		}
    i_clipright=i_clipright+step
    var timer=setTimeout("sliceimage()",1)
	}
   	else {
	    finishedloading()
		fadestrength=0
		document.getElementById("whole").style.top = align_top+'px'
		document.getElementById("whole").innerHTML=content
		var timer=setTimeout("doslide()",pause)
		}
}

// new table and picture information
function getcontent() {
	content="<table cellpadding=0 cellspacing=0 border=0 align ='center' width="+slideshow_width+">"
	content+="<tr><td width="+slideshow_width+" height="+slideshow_height+"><a href="+project_url+"><img src='"+picture[counter]+"' border=0 width="+slideshow_width+" height="+slideshow_height+"></a></td></tr><tr>"
	content+="</table>"
	for (i=0;i<=x_slices;i++) {
		document.getElementById("s"+i).style.top = align_top+'px'
	}
}

// change picture
function doslide() {
	if (pauseflag==false && fadeflag == true ){
		i_clipright=0
		clipleft=0
		clipright=0
		for (i=0;i<=x_slices;i++) {
       		var thiss=eval("document.getElementById('s"+i+"').style")
    		thiss.clip ="rect("+cliptop+"px "+clipright+"px "+clipbottom+"px "+clipleft+"px)"
		}
	randomize()
	getcontent()
		for (i=0;i<=x_slices;i++) {
        var thisinners=eval("document.getElementById('s"+i+"')")
        thisinners.innerHTML=content 
		loading()
    	}
	sliceimage()
	}
else {}
}

// select random picture from the array to be faded into the slideshow
function randomize(){
	var random_counter
	random_counter=Math.floor(Math.random()*picture.length)
	if (random_counter==counter) {randomize()
	}
	counter=random_counter
	get_url()
	qcounter++
	if (qcounter>3){
		qcounter=0
		text_fadestrength=0
		ran_quote()
		}
}

// get url link for picture
function get_url(){
	var get_slide = picture[counter];
	var ax = get_slide.charAt(8);		
	var ay = get_slide.charAt(9);		
	var xy = "1"+ax+ay;					
	     if (xy=="133"){ project_url="pages/133.html"}
	else if (xy=="132"){ project_url="pages/132.html"}
	else if (xy=="117"){ project_url="pages/117.html"}
	else if (xy=="110"){ project_url="pages/110.html"}
	else if (xy=="102"){ project_url="pages/102.html"}
	else if (xy=="101"){ project_url="pages/101.html"}
	else if (xy=="100"){ project_url="pages/100.html"}
	else {project_url="pages/100.html"}
	get_isize()
}

// get image size
function get_isize() {
	var element_id = imgpreload[counter];
	var image_y = element_id.height;
	var	image_x = element_id.width;
	var display_y = 0
	var aspect = image_x / max_width
		if ( image_x > max_width){
			display_y = image_y / aspect;
			slideshow_width = max_width; 
			slideshow_height = display_y
		}
		else {
			slideshow_width =  image_x;
			slideshow_height = image_y;
		}
	align_top = max_height - slideshow_height
		if (slideshow_height == max_height){ 
			align_top = 0
		}
		else{
			var tempa= max_height - slideshow_height
			align_top = tempa/2
//			align left = Math.floor(tempa/2)
		}
}

// end of script 
