 /* ====================================================
 Image Slide Show
==================================================== */

//*** Fader script ***
// http://brainerror.net/scripts/javascript/blendtrans/ for the fade transition

function opacityin(id, opacStart, opacEnd, millisec) { 
//speed for each frame 
var speed = Math.round(millisec / 100); 
var timer = 10; 

//determine the direction for the blending, if start and end are the same nothing happens 
if(opacStart > opacEnd) { 
 for(i = opacStart; i >= opacEnd; i--) { 
     setTimeout("changeOpacin(" + i + ",'" + id + "')",(timer * speed)); 
     timer++; 
 } 
} else if(opacStart < opacEnd) { 
 for(i = opacStart; i <= opacEnd; i++) 
 { 
     setTimeout("changeOpacin(" + i + ",'" + id + "')",(timer * speed)); 
     timer++; 
 } 
} 
} 

//change the opacity for different browsers 
function changeOpacin(opacity, id) { 
var object = document.getElementById(id).style; 
	object.filter = "alpha(opacity=" + opacity + ")"; 
	object.opacity = (opacity / 100); 
	//object.MozOpacity = (opacity / 100); 
	//object.KhtmlOpacity = (opacity / 100); 
} 


//*** DECLARE VARIABLES *** these have been removed for this website to allow for a varied size in images via css
//var imgwidth = "275";
//var imgheight = "275";
var imgclass = "rsimg";


var opimages = new Array();
opimages[0]='/gfx/cards/card005.png';
opimages[1]='/gfx/cards/card002.png';
opimages[2]='/gfx/cards/card003.png';
opimages[3]='/gfx/cards/card004.png';


var nimg = -1;
var nimgl = opimages.length-1;

//*** Image swaper ***
function imagehide() {

	//this hides the initial fade-in image to make way for the full slide-show 	
	document.getElementById("imageslide").style.display = "none";

}


function imagegallery() {

	//this part is what generates the image and calculates what image it is on and increment it by one on each loop of the image_swap() function
	if (nimg<opimages.length-1)
	{
	nimg++
	}
	else if (nimg>=opimages.length-1)
	{
	nimg = 0;
	}
	
	document.getElementById("cardsgallery").innerHTML = '<div id="slidecontainer" class="imagefade"><img src="'+opimages[nimg]+'" border="0"  class="'+imgclass+'" alt="D&amp;M Business Cards" /></div>';
	opacityin('slidecontainer', 0, 100, 500);
	setTimeout("opacityin('slidecontainer', 100, 0, 500)",4400);  
	return true;
}

//****** Image Gallery - image change *******

function image_swap()
{
	//this part has been added to show the last image in the array to start with for 5 seconds as the slideshow has a 5 second delay	
	document.getElementById("cardsgallery").innerHTML = '<div id="slidecontainer" class="imagefade"><img src="'+opimages[nimgl]+'" border="0"  id="imageslide" alt="D&amp;M Business Cards" /></div>';
	opacityin('slidecontainer', 0, 100, 500);
	setTimeout("opacityin('slidecontainer', 100, 0, 500)",4400);
	var Tout = setTimeout("imagehide()", 4800);

	//this part activates and loops the fade in/out and image change script	
	var Tinterval = setInterval("imagegallery()", 5000);
}



//****** To hide e-mail *******


function mailus() {

	top.location='mailto:sales@dmbusinesscards.co.uk';

}




function checkprice(){

	pdiv = document.getElementById("prices");
	tcfprice = pdiv.value; cfprice = tcfprice.replace(/£/gi,"");
	pdiv.value = cfprice;
	
	tempprice = tcfprice.replace(/ /gi,"");
	if(tempprice == "")
	{
		alert("Please enter a value.");
		return false;
	}
}