// Main image filenames
var items = new Array(20)
items[0] = 'gallery17.jpg';
items[1] = 'gallery2.jpg';
items[2] = 'gallery5.jpg';
items[3] = 'gallery28.jpg';
items[4] = 'gallery7.jpg';
items[5] = 'gallery19.jpg';
items[6] = 'gallery10.jpg';
items[7] = 'gallery26.jpg';
items[8] = 'gallery9.jpg';
items[9] = 'gallery30.jpg';
items[10] = 'gallery1.jpg';
items[11] = 'gallery29.jpg';
items[12] = 'gallery23.jpg';
items[13] = 'gallery25.jpg';
items[14] = 'gallery20.jpg';
items[15] = 'gallery31.jpg';
items[16] = 'gallery6.jpg';
items[17] = 'gallery11.jpg';
items[18] = 'gallery24.jpg';
items[19] = 'gallery16.jpg';
items[20] = 'gallery14.jpg';

// Main image rollover
var items_o = new Array(20)
items_o[0] = 'gallery17c.jpg';
items_o[1] = 'gallery2c.jpg';
items_o[2] = 'gallery5c.jpg';
items_o[3] = 'gallery28c.jpg';
items_o[4] = 'gallery7c.jpg';
items_o[5] = 'gallery19c.jpg';
items_o[6] = 'gallery10c.jpg';
items_o[7] = 'gallery26c.jpg';
items_o[8] = 'gallery9c.jpg';
items_o[9] = 'gallery30c.jpg';
items_o[10] = 'gallery1c.jpg';
items_o[11] = 'gallery29c.jpg';
items_o[12] = 'gallery23c.jpg';
items_o[13] = 'gallery25c.jpg';
items_o[14] = 'gallery20c.jpg';
items_o[15] = 'gallery31c.jpg';
items_o[16] = 'gallery6c.jpg';
items_o[17] = 'gallery11c.jpg';
items_o[18] = 'gallery24c.jpg';
items_o[19] = 'gallery16c.jpg';
items_o[20] = 'gallery14c.jpg';

// Caption for main images
var items_name = new Array(20)
items_name[0] = 'Mama Bella';	// 17
items_name[1] = 'Mama Bella';	// 2
items_name[2] = 'Mama Bella';	// 5
items_name[3] = 'Bella Body [customized]';	// 28
items_name[4] = 'Mama Bella';	// 7
items_name[5] = 'Mama Bella';	// 19
items_name[6] = 'Bella Body [customized]';	// 10
items_name[7] = 'Mama Bella';	// 26
items_name[8] = 'Bella Body';	// 9
items_name[9] = 'Bella Bowl';	// 30
items_name[10] = 'Mama Bella';	// 1
items_name[11] = 'Mama Bella';	// 29
items_name[12] = 'Bella Body';	// 23
items_name[13] = 'Bella Body [customized]';	// 25
items_name[14] = 'Mama Bella';	// 20
items_name[15] = 'Bella Body';	// 31
items_name[16] = 'Bella Body [customized]';	// 6
items_name[17] = 'Bella Bowl';	// 11
items_name[18] = 'Mama Bella';	// 24
items_name[19] = 'Mama Bella';	// 16
items_name[20] = 'Mama Bella';	// 14

// URLs for types
// Use: items_pg['<Style defined in caption>'] = '<URL Extension for sculptures.php>';
// Ex. sculptures.php#Mama Bella
var items_pg = new Array(4)
items_pg['Mama Bella'] = 'store_sculptures_mamab.html';
items_pg['Bella Body'] = 'store_sculptures_bbody.html';
items_pg['Bella Body [customized]'] = 'store_sculptures_bbody.html';
items_pg['Bella Bowl'] = 'store_sculptures_bbowl.html';

// Finish defining globals
var main_pre = new Array();
var ovr_pre = new Array();
var curr = 0;


// Preload all our images
function preload() {

	// Set correct thumbnail
	thumb(0);

	// Scroll through each main image and load it
	for (var c=0; c<items.length; c++) {
		main_pre[c] = new Image();
		main_pre[c].src = 'gallery/' + items[c];
	}

	// Scroll through each rollover and load it
	for (var c=0; c<items_o.length; c++) {
		ovr_pre[c] = new Image();
		ovr_pre[c].src = 'gallery/' + items_o[c];
	}
}

// Changes to our rollover image
function roll_on() {
	document.getElementById('mainimg').src = 'gallery/' + items_o[curr];
}

// Changes back to our main image
function roll_off() {
	document.getElementById('mainimg').src = 'gallery/' + items[curr];
}

// Used to move forward and back
function nav(dir) {
	if(dir == 'prev') {
		if(curr <= 0)
		curr = items.length-1;
		else
			curr--;
			gallimg(curr);
		}
		if(dir == 'next') {
			if(curr >= items.length-1)
			curr = 0;
			else
				curr++;
				gallimg(curr);
			}
		}

		// Used to change main image
		function gallimg(img) {

			// Update main image
			document.getElementById('maintxt').innerHTML = items_name[img];
			document.getElementById('sculp').href = items_pg[items_name[img]];

			// IE Image fades (to be completed).

			document.getElementById('mainimg').style.filter="blendTrans(duration=1)";
			if (document.getElementById('mainimg').filters && document.getElementById('mainimg').filters[0]){
				document.getElementById('mainimg').filters.blendTrans(duration=1).Apply();
				document.getElementById('mainimg').filters[0].Play();
			}
			document.getElementById('mainimg').src= 'gallery/' + items[img];
			curr = img;

			// Update thumbnail
			thumb(img);
		}


		// Activate the correct thumbnail
		function thumb(img) {
			for(i=0; i<items.length; i++) {
				if(i == img)
				document.getElementById("img_" + i).className+=' active';
				else
					document.getElementById("img_" + i).className
                        =document.getElementById("img_" + i).className.replace(' active', '')
				}
			}

			function ovr(img) {
				document.getElementById(img).className+=' active';
			}

			function out(img) {
				document.getElementById(img).className=document.getElementById(img).className.replace(' active', '')
			}

Behaviour.register({
    'a.thumb' : function(element){
        element.onmouseup = function(){
            var img = this.getElementsByTagName('img');
            var index = img[0].id.replace("img_", "");
            gallimg(index);
            return false;
        };
    },
    'img.thumb' : function(element){
        element.onmouseout = function(){
            this.className += " over";
        };
    },
    'img.thumb' : function(element){
        element.onmouseover = function(){
            this.className = this.className.replace(" over", "");
        };
    }
});

Behaviour.addLoadEvent(preload);
