//Written By David Mackenzie, dmackenzie@ivolvestudios.com

//Varibles
var gallery = [];
var img_index = 0;
var img_total = 21;
var lImg = new Image();
lImg.src = "images/ajax-loader.gif";
var theImage = new Image();


//Gallery Array

gallery[0] = ["gallery_product/Wheel_small.jpg", "", "gallery_product/Wheel.jpg"]
gallery[1] = ["gallery_product/watch_small.jpg", "", "gallery_product/watch.jpg"]
gallery[2] = ["gallery_product/train_small.jpg", "", "gallery_product/train.jpg"]
gallery[3] = ["gallery_product/ship_2_small.jpg", "", "gallery_product/ship_2.jpg"]
gallery[4] = ["gallery_product/ship_1_small.jpg", "", "gallery_product/ship_1.jpg"]
gallery[5] = ["gallery_product/scooter_small.jpg", "", "gallery_product/scooter.jpg"]
gallery[6] = ["gallery_product/Scooter_02_small.jpg", "", "gallery_product/Scooter_02.jpg"]
gallery[7] = ["gallery_product/Motor_small.jpg", "", "gallery_product/Motor.jpg"]
gallery[8] = ["gallery_product/mainline_exploded_small.jpg", "", "gallery_product/mainline_exploded.jpg"]
gallery[9] = ["gallery_product/astra_small.jpg", "", "gallery_product/astra.jpg"]
gallery[10] = ["gallery_product/a380_small.jpg", "", "gallery_product/a380.jpg"]
gallery[11] = ["gallery_product/audi_rear_small.jpg", "", "gallery_product/audi_rear.jpg"]
gallery[12] = ["gallery_product/audi_front_small.jpg", "", "gallery_product/audi_front.jpg"]
gallery[13] = ["gallery_product/amex_small.jpg", "", "gallery_product/amex.jpg"]
gallery[14] = ["gallery_product/audi_night_small.jpg", "", "gallery_product/audi_night.jpg"]
gallery[15] = ["gallery_product/Side_Table_small.jpg", "", "gallery_product/Side_Table.jpg"]
gallery[16] = ["gallery_product/Shoe_small.jpg", "", "gallery_product/Shoe.jpg"]
gallery[17] = ["gallery_product/Phillips_small.jpg", "", "gallery_product/Phillips.jpg"]
gallery[18] = ["gallery_product/Dali_small.jpg", "", "gallery_product/Dali.jpg"]
gallery[19] = ["gallery_product/aeron_small.jpg", "", "gallery_product/aeron.jpg"]
gallery[20] = ["gallery_2010/Audi_S5_iModify-s.jpg", "", "gallery_2010/Large/Audi_S5_iModify.jpg"]
gallery[21] = ["gallery_product/ship_3_small.jpg", "", "gallery_product/ship_3.jpg"]









//Functions

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function swapImage(myImg) {
	if (myImg != null) {
		document["gallery_image"].src = theImage.src
		document.getElementById("gallery_text").innerHTML =gallery[img_index][1];
		document.getElementById("gallery_link").href =gallery[img_index][2];
		document.getElementById("gallery_link").title =gallery[img_index][1];
	}else{
		//Need this for IE7??
		document["gallery_image"].src = theImage.src
		document.getElementById("gallery_text").innerHTML =gallery[img_index][1];
		document.getElementById("gallery_link").href =gallery[img_index][2];
		document.getElementById("gallery_link").title =gallery[img_index][1];
	}
}



function next_img() {
	if (img_index < img_total) {
		img_index = img_index + 1;
		if (document.images) {
			theImage = new Image();
			theImage.onload = swapImage;
			document["gallery_image"].src = lImg.src;
			theImage.src = gallery[img_index][0];
		}
	}else {
		img_index = 0;
		if (document.images) {
			theImage = new Image();
			theImage.onload = swapImage;
			document["gallery_image"].src = lImg.src;
			theImage.src = gallery[img_index][0];
		}
	}
}

function prev_img() {
	if (img_index > 0) {
		img_index = img_index - 1;
		if (document.images) {
			theImage = new Image();
			theImage.onload = swapImage;
			document["gallery_image"].src = lImg.src;
			theImage.src = gallery[img_index][0];
		}
	}else {
		img_index = img_total;
		if (document.images) {
			theImage = new Image();
			theImage.onload = swapImage;
			document["gallery_image"].src = lImg.src;
			theImage.src = gallery[img_index][0];
		}
	}
}

function rand_img() {
	var ret_id = gup('id');
	if (ret_id != ""){
		ret_id = parseInt(ret_id);
		img_index = ret_id - 1;
		next_img();
	}else{
		img_index = Math.floor(Math.random()*11);
		next_img();
	}
}








