//Some intial variables. Do not touch.

var tt = 0;
var bb = 0;
var img_total = 0;
var gallery_1_path = "0";
var gal_prefix = "0";
var ran1 = 0;
var ran2 = 0;
var ran3 = 0;
var ran4 = 0;
var ran5 = 0;
var ran6 = 0;
var ran7 = 0;
var ran8 = 0;
var yyy = 1;


//The Random home page images function

function homepage() {
		for (xxx = 1; xxx < 6; yyy++){
			var randomnumber=Math.floor(Math.random()*8) + 1;
			var randomtemp = window["ran" + xxx];
			if (randomnumber != ran1 && randomnumber != ran2 && randomnumber != ran3 && randomnumber != ran4 && randomnumber != ran5){
			window["ran" + xxx] = randomnumber;
			xxx = xxx +1;
			} else {
				xxx = xxx;
			}
		}
	var rightphotoholder = document.getElementById('myGallery');
	var rightphotoholderdiv = rightphotoholder.appendChild(document.createElement('div'));
	rightphotoholderdiv.setAttribute('id', 'homephoto_smalldiv');
	
	for (zzz = 2; zzz < 6; zzz++) {
	var rightphototemp = rightphotoholderdiv.appendChild(document.createElement('img'));
	var hhh = window['ran' + zzz];
	rightphototemp.setAttribute('src', 'images/homeimages/home_' + hhh + '_sm.jpg');
	rightphototemp.setAttribute('class', 'rightphoto');
	rightphototemp.setAttribute('id', 'rightphoto' + zzz);
	var rightphoto2fade = new Fx.Style('rightphoto' + zzz, 'opacity', {duration: 1000, wait:false}).start(0,.9999);
	}
	
	rightphototemp.setAttribute('height', 132);
	rightphototemp.setAttribute('width', 200);
	
	
	var dominantphotoholder = document.getElementById('myGallery');
	var dominantphoto = dominantphotoholder.appendChild(document.createElement('img'));
	dominantphoto.setAttribute('src', 'images/homeimages/home_' + ran1 + '.jpg');
	dominantphoto.setAttribute('id', 'homephoto');
	var homefade = new Fx.Style('homephoto', 'opacity', {duration: 1000, wait:false}).start(0,1);
}



//Remove gallery function. To remove the current objects on the page to make room for the new gallery

function clearpage() {
		var galdiv = document.getElementById('myGallery');
		galdiv.parentNode.removeChild(galdiv);
		var infodiv = document.getElementById('myInfoContainer');
		infodiv.parentNode.removeChild(infodiv);
}



//Choose Gallery Function. Creates the proper variables depending on which link was pressed. 


function choosegallery(galleryname){
	gal_prefix = galleryname
	gallery_1_path = eval(galleryname + "1_path");
	img_total = eval(galleryname + "total");
	makejoegallery();
}


//This function creates the gallery itself. 


function makejoegallery(){
	var galdiv = document.createElement('div'); 
	galdiv.id = 'myGallery';
	var scr = document.getElementById('aftergal'); 
	scr.parentNode.insertBefore(galdiv, scr);
	var infodiv = document.createElement('div');
	infodiv.id = 'myInfoContainer'; 
	infodiv.setAttribute('class', 'myInfoContainer'); 
	var scr4 = document.getElementById('afterinfo');
	scr4.parentNode.insertBefore(infodiv, scr4);
	for (tt=1; tt <= img_total; tt++){
		var current_title = window[gal_prefix + tt + '_title'];
		var current_date = window[gal_prefix + tt + '_date'];
		var current_filename = window[gal_prefix + tt + '_filename'];
		
		var current_element = document.createElement('div');
		current_element.setAttribute('class', 'imageElement');
		
		var current_h3 = current_element.appendChild(document.createElement('h3'));
		current_h3.appendChild(document.createTextNode(current_title)); 
		
		var current_p = current_element.appendChild(document.createElement('p'));
		current_p.appendChild(document.createTextNode(current_date));
		
		var current_a = current_element.appendChild(document.createElement('a'));
		current_a.setAttribute('class', 'open');
		current_a.setAttribute('title', 'open image');
		current_a.setAttribute('href', 'images/' + gallery_1_path + current_filename + '.jpg');
		
		var current_img = current_element.appendChild(document.createElement('img'));
		current_img.setAttribute('class', 'full');
		current_img.setAttribute('src', 'images/' + gallery_1_path + current_filename + '_gal.jpg');
		
		var current_imgthumb = current_element.appendChild(document.createElement('img'));
		current_imgthumb.setAttribute('class', 'thumbnail');
		current_imgthumb.setAttribute('src', 'images/' + gallery_1_path + current_filename + '_thumb.jpg');
		
		var scr2 = document.getElementById('myGallery');
		scr2.appendChild(current_element, scr2);
	};
};


//This function activates the gallery on the page. 



function startGallery() {
var myGallery = new gallery($('myGallery'), {
timed: false,
textShowCarousel: 'THUMBS',
defaultTransition: "fadeslideleft"
});
}



//The Slider effect for the Photojournalism sublinks, plus the adding of the actual link actions for all buttons on the page, plus the fade in effect for the home page.

 

window.addEvent('domready', function() {
	//-vertical
 
 
var mySlide = new Fx.Slide('sublinks').hide();
document.getElementById('sublinks').style.visibility = "visible";

$('slidein').addEvent('click', function(e){
	e = new Event(e);
	mySlide.slideIn();
	e.stop();
});

$('contact_').addEvent('click', function(e){
	e = new Event(e);
	mySlide.slideOut();
	clearpage();
	choosegallery('contact_');
	startGallery();
	e.stop();
});

$('fineart_').addEvent('click', function(e){
	e = new Event(e);
	mySlide.slideOut();
	clearpage();
	choosegallery('fineart_');
	startGallery();
	e.stop();
});

$('lifestyle_').addEvent('click', function(e){
	e = new Event(e);
	mySlide.slideOut();
	clearpage();
	choosegallery('lifestyle_');
	startGallery();
	e.stop();
});

$('nudes_').addEvent('click', function(e){
	e = new Event(e);
	mySlide.slideOut();
	clearpage();
	choosegallery('nudes_');
	startGallery();
	e.stop();
});

$('berharp_').addEvent('click', function(e){
	e = new Event(e);
	clearpage();
	choosegallery('berharp_');
	startGallery();
	e.stop();
});

$('dod_').addEvent('click', function(e){
	e = new Event(e);
	clearpage();
	choosegallery('dod_');
	startGallery();
	e.stop();
});

$('drnc_').addEvent('click', function(e){
	e = new Event(e);
	clearpage();
	choosegallery('drnc_');
	startGallery();
	e.stop();
});

$('mexico_').addEvent('click', function(e){
	e = new Event(e);
	clearpage();
	choosegallery('mexico_');
	startGallery();
	e.stop();
});
 
 
 

});

