var a_images_slideshow = new Array()
var a_images = new Array()
var a_links = new Array()
var image_opacity = 1
var last_call
var slideshow_continue = true
var last_cycle_call
var global_image_index = 0
var global_bg_target
var global_image_target
var fadeIn = 1
var fadeOut = 0

if (navigator.appName.indexOf("Microsoft")!=-1) 
{ 
	var browser = 'IE'
}
else 
{ 
	var browser = 'MZ' 
}

a_images_slideshow[0] = '/car_images/ss/ebookpic.jpg';
a_images[0] = new Image(293, 258 )
a_images[0].src = '/car_images/ss/ebookpic.jpg'
a_images[0].alt = 'audi a6 offer '
a_images[0].title = 'audi a6 offer '

a_links[0] = new Array();
a_links[0]['path'] = 'http://www.ccsnews.co.nz/contents.aspx'
a_links[0]['target'] = '_blank'


function set_opacity(object,opacity)
{
	if (object.filters)
	{
		object.filters.alpha.opacity = opacity
	}
	else if (object.style.MozOpacity)
	{
		object.style.MozOpacity = opacity/100
	}
	else if (object.style.opacity)
	{
		object.style.opacity = opacity/100
	}
	else if (object.style.Opacity)
	{
		object.style.Opacity = opacity/100
	}
	else if (object.style.KhtmlOpacity)
	{
		object.style.KhtmlOpacity = opacity/100
	
	}
	
}

function fade_in()
{
	
	set_opacity(global_image_target,image_opacity)
	
	if (fadeIn != 1)
	{
		setTimeout( "fade_in()", 70 )
	}
	else if ( image_opacity < 100 )
	{
		
		image_opacity = image_opacity + 3
		last_call = setTimeout( "fade_in()", 70 )
	}
	else
	{
		setTimeout( "global_bg_target.src = global_image_target.src", 100 )

		image_opacity =  100
		fadeIn = 0;
		fadeOut = 1
		
	}
	
}

function fade_out()
{
	set_opacity(global_image_target,image_opacity)
	
	if (fadeOut != 1)
	{
		setTimeout( "fade_out()", 50 )
	
	}
	else if ( image_opacity > 25 )
	{
		
		image_opacity = image_opacity - 3
		
		last_call = setTimeout( "fade_out()", 50 )
	}
	else
	{
		image_opacity = 25	
		fadeIn = 1
		fadeOut = 0
		global_image_target.src = a_images_slideshow[global_image_index]
		fade_in()
	}
	
}

function extinguish()
{
	image_opacity = 1
	fadeIn = 1

	if ( last_call != '' )
	{
		clearTimeout( last_call )
	}

	if ( browser == 'IE' )
	{
		global_image_target.filters.alpha.opacity = 1
	}
	else
	{
		global_image_target.style.MozOpacity= 1/100
	}

}

function clear_last_call()
{
	if ( last_call != '' )
	{
		clearTimeout( last_call )
	}
}

function image_next()
{
	if( !bool_pause_slideshow )
	{	

		if ( image_opacity > 0 && image_opacity < 100 )
		{
		
			setTimeout( "image_next()", 500 )
		}
		else
		{
			global_image_index++


			if ( global_image_index >= a_images_slideshow.length )
			{
				global_image_index = 0	
			}
		
			clear_last_call()
			//fade_out()
			extinguish()
			setTimeout( "global_image_target.src = a_images_slideshow[global_image_index];global_image_target.alt = a_images[global_image_index].alt;global_image_target.title = a_images[global_image_index].title", 50 )
			setTimeout( "fade_in()", 100 )
		}
	}

}

var bool_pause_slideshow = false

function pause_slideshow()
{

	bool_pause_slideshow = true
	slideshow_continue = false

	if ( last_cycle_call != '' )
		clearTimeout( last_cycle_call )

}

function restart_slideshow()
{

	bool_pause_slideshow = false
	slideshow_continue = true
	last_cycle_call = setTimeout( "cyle_thru_images()", 2.5*1000 ) 
}

function cyle_thru_images()
{
	
	image_next();


	if ( slideshow_continue )
	{
		last_cycle_call = setTimeout( "cyle_thru_images()", 5*1000 ) 
	}	
}

function start_slideshow()
{

	global_bg_target = document.image_bg

	global_image_target = document.image_fg
	extinguish()
	global_image_target.src = a_images_slideshow[global_image_index]
	fade_in()

	if ( a_images_slideshow.length > 1 )
	{
		setTimeout( "cyle_thru_images()", 4*1000 ) 
	}

}

function launch()
{
	if ( a_links[global_image_index]['path'] != '' )
	{
		if ( a_links[global_image_index]['target'] == '_blank' )
		{
			window.open( a_links[global_image_index]['path'], '_blank' )
		}
		else
		{
			window.location = a_links[global_image_index]['path']
		}
	}
}
