function swap(image){
	var tmp = image.src.split(".");
	if(tmp.length == 3){
		image.src = tmp[0]+'.'+tmp[1]+'_over.'+tmp[2];
	} else {
		image.src = tmp[0]+'.'+tmp[1]+'.'+tmp[2]+'_over.'+tmp[3];
	}
}
function swap_back(image){
	var tmp = image.src.split("_over");
	image.src = tmp[0]+tmp[1];
}

function Gallery() {

	this.arrImages = Array();
	this.arrExtras = Array();
	this.currentImg = 1;
	this.noImages = 0;
	this.strMainImage = 'main_image';
	this.strTitle = 'image_title';
	this.strDesc = 'image_desc';
	
	this.registerImage = function( objImage, intImageNo ) {
	
		if( typeof( objImage ) != "object" ) objImage = document.getElementById(objImage);
		this.arrImages[intImageNo] = objImage;
		this.noImages++;
	
	}
	
	this.registerExtra = function( intImage, objExtra, objLink, intExtra ) {
	
		if( typeof( this.arrExtras[intImage] ) == "undefined") {
			this.arrExtras[intImage] = Array();
		}
		if( typeof( objExtra ) != "object" ) objExtra = document.getElementById(objExtra);
		
		this.arrExtras[intImage][intExtra] = Array();
		this.arrExtras[intImage][intExtra]['img'] = objExtra;
		this.arrExtras[intImage][intExtra]['link'] = objLink;
		
	}

	this.switchGallery = function( intImageNo ) {
		
		
		// get image elements		
		objMainImg = document.getElementById(this.strMainImage);
		objNewImage = this.arrImages[intImageNo];
	
		// split new url with original filename on the end
		var arrTmp = objNewImage.src.split("\/s_");
	
		// change file to large copy
		arrTmp[arrTmp.length-1] = "l_"+arrTmp[arrTmp.length-1];
	
		// join source back together
		strTmp = arrTmp.join("/");

		// switch image
		objMainImg.src = strTmp;
		this.currentImg = intImageNo;
		
		// change title and desc
		document.getElementById(this.strTitle).innerHTML = objNewImage.title;
		document.getElementById(this.strDesc).innerHTML = objNewImage.alt;
		
		// get container
		objDiv = document.getElementById("thumbs");
		
		objDiv.innerHTML = '';
		
		// change side thumbnails
		intExtras = 0;
		for( x in this.arrExtras[intImageNo] ) {
			if( isNaN(parseInt(x)) ) continue;
			//objDiv.removeChild(document.getElementById("thumbs_"+x));
			
			objLink = this.arrExtras[intImageNo][x]['link'];
			objImg = this.arrExtras[intImageNo][x]['img'];
			
			objLink.appendChild(objImg);
			
			if( objTarget = document.getElementById("thumbs_"+x ) ) {
			
				objDiv.replaceChild(objLink, objTarget);
			
			} else {
				//objBr = document.createElement("br");
				//objDiv.appendChild(objBr);
				objDiv.appendChild(objLink);
			}
			intExtras++;
		}


	}
	
	this.switchExtra = function( intImageNo, intExtraNo ) {
	
		// get image elements		
		objMainImg = document.getElementById(this.strMainImage);
		objNewImage = this.arrExtras[intImageNo][intExtraNo]['img'];
	
		// split new url with original filename on the end
		var arrTmp = objNewImage.src.split("\/t_");
	
		// change file to large copy
		arrTmp[arrTmp.length-1] = "l_"+arrTmp[arrTmp.length-1];
	
		// join source back together
		strTmp = arrTmp.join("/");

		// switch image
		objMainImg.src = strTmp;
		this.currentImg = intImageNo;
	
	}

	this.prevImage = function() {

		if( this.currentImg == 1 ) { 
			this.currentImg = this.noImages;
		} else {
			this.currentImg--;
		}
		
		this.switchGallery( this.currentImg, true );

	}

	this.nextImage = function() {

		if( this.currentImg == this.noImages ) {
			this.currentImg = 1;
		} else {
			this.currentImg++;
		}
		
		this.switchGallery( this.currentImg, true );

	}

}

objGallery = new Gallery();

jQuery(document).ready(function() {
	jQuery(".quote").fadeOut("fast");
	jQuery(".quote").fadeIn("fast");
	jQuery(".quote").fadeOut("fast");
	jQuery(".quote").fadeIn("fast");
})
