var carousel = true;
if(!bgs) var bgs = false;
if(bgs && bgs.length < 2) {carousel = false;}
var count = 0;
var timer = null;
var preloaded = false;

var timer_fadein = null;
var timer_fadeout = null;
var fadeout_delay = null; 


function navi_image_show(obj, src)
{  
	if(src) {
		if(!now_playing) PlayFlashMovie(obj.id);
		else {if(now_playing != obj.id) {next_up = obj.id;} RewindFlashMovie(now_playing);}
		info_image_show(obj);
	}
		
} 

function navi_image_hide(obj)
{  
	if(now_playing) {RewindFlashMovie(now_playing);}
	info_image_hide();
}  


function info_image_show(obj){  
	
	var img_div = document.getElementById('info_image'); 
	if(img_div.parentNode != document.body) document.body.appendChild(img_div);
	
	var obj_el = jQuery(obj);
	var obj_cor = obj_el.offset();
	
	img_div.style.top  = (obj_cor.top - 106) + 'px';
	img_div.style.left = (obj_cor.left) + 'px'; 
	
	img_div.innerHTML = '<div class="info_fuel">' + info_imgs[obj.id]["fuel"] + '</div>';
	img_div.innerHTML += '<div class="info_model">' + info_imgs[obj.id]["model"] + '<br /><span class="type">(' + info_imgs[obj.id]["type"] + ')</span>';
	img_div.innerHTML += '<div class="info_price"><span>Hinnat alkaen</span>' + info_imgs[obj.id]["price"] + ' &euro;</div>';
	
	jQuery('#info_image').show();	
}  
  
function info_image_hide()
{  
	jQuery('#info_image').hide();
}  

function carousel_select(obj, bkg, count)
{
	document.body.style.backgroundImage = "url(" + bkg + ")";
	var others =  document.getElementsByName('carousel_dot');
	for(var i = 0; i < others.length; i++)
	{
		others[i].src="img/bt_off.png";
	}
	obj.src="img/bt_on.png";
	carousel = false;
	clearTimeout(timer);
// fader code begins	
	clearTimeout(timer_fadein);clearTimeout(timer_fadeout);clearTimeout(fadeout_delay);

}

function background_rotator()
{
	if(!count) count=0;
	document.body.style.backgroundImage = "url(" + bgs[count] + ")";
	
// fader code begins	

	if(count < bgs.length && preloaded == false)
	{
		preload_image_object = new Image();
		preload_image_object.src = bgs[count+1];
		if (count == (bgs.length - 1) ) {preloaded = true;}
	}
	
	var others =  document.getElementsByName('carousel_dot');
	for(var i = 0; i < others.length; i++)
	{
		if (i != count) {others[i].src="img/bt_off.png";}else{others[i].src="img/bt_on.png";}
	}
	if (count < bgs.length - 1) {count++;} else {count = 0;}
	if(carousel == true) timer = setTimeout('background_rotator()',10000);
}

function fadein()
{
	if(isIE()) var duration = '200' ; else var duration = '500';
	
	clearTimeout(timer_fadeout);
	jQuery('#bkg_ads').css('display', 'none');
	jQuery('#bkg_ads').fadeIn(duration);
}

function fadeout()
{
	if(isIE()) var duration = '200' ; else var duration = '500';
	
	jQuery('#bkg_ads').fadeOut(duration);
}

function dd_info(obj, model)
{
	var ttt = jQuery("#drop_down_vehicle li>a");
	for(var i = 0; i < ttt.length; i++)
	{
		if(ttt[i] != obj) jQuery(ttt[i]).removeClass('active_a');
		else jQuery(obj).addClass('active_a');
	}
	
	jQuery('#drop_down_vehicle_details').children('.dd_model h2:first').html(info_imgs["naviid_"+model]["model"]);
	if(info_imgs["naviid_"+model]["fuel"] && info_imgs["naviid_"+model]["fuel"] != "0,0") jQuery('#drop_down_vehicle_details').children('.dd_fuel p:first').html("Yhdistetty kulutus "+info_imgs["naviid_"+model]["fuel"]+" l/100km");
	else jQuery('#drop_down_vehicle_details').children('.dd_fuel p:first').html("");
	if(info_imgs["naviid_"+model]["price"] && info_imgs["naviid_"+model]["price"] != 0) jQuery('#drop_down_vehicle_details').children('.dd_price p:first').html("Hinnat alkaen "+info_imgs["naviid_"+model]["price"]+" &euro;");
	else  jQuery('#drop_down_vehicle_details').children('.dd_price p:first').html("Tulossa syksyllä 2011");
	if(info_imgs["naviid_"+model]["co2"] != 0) jQuery('#drop_down_vehicle_details').children('.dd_co2 p:first').html("CO<sub>2</sub>-päästöt "+info_imgs["naviid_"+model]["co2"]+" g/km");
	else jQuery('#drop_down_vehicle_details').children('.dd_co2 p:first').html("");
	if(info_imgs["naviid_"+model]["type"]) jQuery('#drop_down_vehicle_details').children('.dd_type h3:first').html("("+info_imgs["naviid_"+model]["type"]+")");
	else jQuery('#drop_down_vehicle_details').children('.dd_type h3:first').html("");
	var tmp = model.toLowerCase();
	jQuery('#drop_down_vehicle_details').children('.dd_image img:first').attr("src", "/img/navi_img/"+tmp+".png");
		
}

function navi_hover(obj, call)
{
	if(call == 'drive')
	{
		jQuery(obj).attr("src", "/img/bt_drive_on.png");
		jQuery("#navi_live").attr("src", "/img/bt_live_off.png");
		jQuery("#navi_navi").css("background", "url(/img/bg_header_drive.png) no-repeat scroll -120px top transparent");
		jQuery("#navi_content").html(jQuery("#navi_drive_content").html());
	}
	else
	{
		jQuery(obj).attr("src", "/img/bt_live_on.png");
		jQuery("#navi_drive").attr("src", "/img/bt_drive_off.png");
		jQuery("#navi_navi").css("background", "url(/img/bg_header_live.png) no-repeat scroll -120px top transparent");
		jQuery("#navi_content").html(jQuery("#navi_live_content").html());
	}
}

function show_spot(obj)
{
	jQuery(obj).css("z-index", 2);
	jQuery(obj).animate({
		top: "40px"
	}, 400, 'linear' );
	jQuery("#"+obj.id+" img").animate({
		width: "100%"
	}, 400, 'linear' ); 
}

function hide_spot(obj)
{
	jQuery(obj).css("z-index", 1);
	jQuery(obj).animate({
		top: "185px"
	}, 400, 'linear' );
	jQuery("#"+obj.id+" img").animate({
		width: "65%"
	}, 400, 'linear' ); 
}
