idx = new Array('1', '2', '3', '4', '5', '6', '7', '8', '9a', '9a', '9a', '10', '11', '12');
idx2 = new Array('1', '2', '3', '4', '5', '6', '7', '8', '9a', '9b', '9c', '10', '11', '12');
picture = new Array();
picture2 = new Array();

var vNav = 0;
var vScroll = false;
var run = false;

// time delay between slides (in milliseconds)
var vTimer = 12000;

// check for ie
function isIe()
{
	
	if(navigator.appVersion.indexOf("MSIE") > -1 && navigator.userAgent.indexOf("Opera") <= -1)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

// set picture index (ie)
function navIe(p_index)
{
	document.images.img_1.style.filter = "progid:DXImageTransform.Microsoft.Fade(duration=2)";
	document.images.img_1.filters[0].apply();
	document.images.img_1.src = picture[p_index].src;
	document.images.img_1.filters[0].play();

	document.images.img_3.style.filter = "progid:DXImageTransform.Microsoft.Fade(duration=2)";
	document.images.img_3.filters[0].apply();
	document.images.img_3.src = picture2[p_index].src;
	document.images.img_3.filters[0].play();
}

// set picture index (other browsers)
function navNorm(p_index)
{
	 document.images.img_1.src = picture[p_index].src;
	 document.images.img_3.src = picture2[p_index].src;
}

// change slide (true - next, false - previous)
function nav(d)
{
	if(d == 1) // next
	{
		if(vNav == picture.length - 1)
		{
			vNav = 0;
		}
		else
		{
			vNav = vNav + 1;
		}
	}
	else // prev
	{
		if(vNav == 0)
		{
			vNav = picture.length - 1;
		}
		else
		{
			vNav = vNav - 1;
		}
	}

	if(!picture[vNav]) loadText(vNav);
	if(!picture2[vNav]) loadImage(vNav);

	if(!isIe())
	{
		navNorm(vNav);
	}
	else
	{
		navIe(vNav);
	}
}

function nextPic()
{
	nav(1);
	window.clearInterval(run);
	vScroll = false;
}

function prevPic()
{
	nav(0);
	window.clearInterval(run);
	vScroll = false;
}

// start/stop slideshow
function startstop() 
{
	if(vScroll == true) 
	{
		window.clearInterval(run);
	}
	else
	{
		run = setInterval("nav(true)", vTimer);
	}
	vScroll = !vScroll;
	
}

function loadText(p_index)
{
	picture[p_index] = new Image();
	picture[p_index].src = site_url+'/images/reason_carousel/'+idx[p_index]+'text.gif';
}

function loadImage(p_index)
{
	picture2[p_index] = new Image();
	picture2[p_index].src = site_url+'/images/reason_carousel/'+idx2[p_index]+'image.jpg';
}

// preload images
function preLoadImages()
{
	for(i = 0; i <= idx.length-1; i++)
	{
		loadText(i);
		loadImage(i);
	}
	
	startstop();
}

function slower()
{
	vTimer -= 1000;
	if(vTimer < 1000)
	{
		vTimer = 1000;
	}	
}

function faster()
{
	vTimer += 1000;
	if(vTimer > 10000)
	{
		vTimer = 10000;
	}	
}

function calcPosition()
{
	var iLeft = (window.document.body.offsetWidth/2); 
	var iTop = (window.document.body.offsetWidth/2);
	document.images.img_1.style.left= iLeft - 375;	
	document.images.img_3.style.left= iLeft - 22;	
}
