// FUNZIONI CHE GESTISCONO LO SCROLLING DEI LAYER 
var speed = 5; //Velocita di scrollamento  
var fermo = false;
function fermaScrolling() {
	fermo = true;
}
function parteScrolling(direzione, qualeLayer) {
	fermo = false;
	if (qualeLayer == 'colori') {
		if (direzione == 'su') scrollaLayerColoriUp();
		if (direzione == 'giu') scrollaLayerColoriDown();
	}
	if (qualeLayer == 'cerchioni') {
		if (direzione == 'su') scrollaLayerCerchioUp();
		if (direzione == 'giu') scrollaLayerCerchioDown();
	}
	if (qualeLayer == 'interni') {
		if (direzione == 'su') scrollaLayerInterniUp();
		if (direzione == 'giu') scrollaLayerInterniDown();
	}
	if (qualeLayer == 'opt3') {
		if (direzione == 'su') scrollaLayerOpt3Up();
		if (direzione == 'giu') scrollaLayerOpt3Down();
	}
	if (qualeLayer == 'detail') {
		if (direzione == 'su') scrollaLayerDetailUp();
		if (direzione == 'giu') scrollaLayerDetailDown();
	} 
}

// FUNZIONI CHE FANNO SCROLLARE IL LAYER COLORI
function scrollaLayerColoriUp() {

	TopColoriStep2 = parseInt(document.getElementById('ccInnColori').style.top);

	if (-TopColoriStep2 < (document.getElementById('ccInnColori').offsetHeight - document.getElementById('ccContColori').offsetHeight)) {
		document.getElementById('ccInnColori').style.top = TopColoriStep2 - 1 + "px";
		if (!fermo){
			setTimeout('scrollaLayerColoriUp()', speed);
		}
	} else return false;
}

function scrollaLayerColoriDown() {

	var top = parseInt(document.getElementById('ccInnColori').style.top);

	if (top < 0) {
		document.getElementById('ccInnColori').style.top = top + 1 + "px";
		if (!fermo){
			setTimeout('scrollaLayerColoriDown()', speed);
		}
	} else return false;
}

// FUNZIONI CHE FANNO SCROLLARE IL LAYER CERCHIONI
function scrollaLayerCerchioUp() {

	TopCerchioniStep2 = parseInt(document.getElementById('ccInnCerchioni').style.top);

	if (-TopCerchioniStep2 < (document.getElementById('ccInnCerchioni').offsetHeight - document.getElementById('ccContCerchioni').offsetHeight)) {
		document.getElementById('ccInnCerchioni').style.top = TopCerchioniStep2 - 1 + "px";
		if (!fermo){
			setTimeout('scrollaLayerCerchioUp()', speed);
		}
	} else return false;
}

function scrollaLayerCerchioDown() {

	var top = parseInt(document.getElementById('ccInnCerchioni').style.top);
	if (top < 0) {
		document.getElementById('ccInnCerchioni').style.top = top + 1 + "px";
		if (!fermo){
			setTimeout('scrollaLayerCerchioDown()', speed);
		}
	} else return false;
}

// FUNZIONI CHE FANNO SCROLLARE IL LAYER INTERNI
function scrollaLayerInterniUp() {

	TopInterniStep2 = parseInt(document.getElementById('ccInnInterni').style.top);

	if (-TopInterniStep2 < (document.getElementById('ccInnInterni').offsetHeight - document.getElementById('ccContInterni').offsetHeight)) {
		document.getElementById('ccInnInterni').style.top = TopInterniStep2 - 1 + "px";
		if (!fermo){
			setTimeout('scrollaLayerInterniUp()', speed);
		}
	} else return false;
}

function scrollaLayerInterniDown() {

	var top = parseInt(document.getElementById('ccInnInterni').style.top);
	if (top < 0) {
		document.getElementById('ccInnInterni').style.top = top + 1 + "px";
		if (!fermo){
			setTimeout('scrollaLayerInterniDown()', speed);
		}
	} else return false;
}

// FUNZIONI CHE FANNO SCROLLARE IL LAYER OPTIONALS NELLO STEP 3
function scrollaLayerOpt3Up() {

	TopOptStep3 = parseInt(document.getElementById('ccInnOpt3').style.top);

	if (-TopOptStep3 < (document.getElementById('ccInnOpt3').offsetHeight - document.getElementById('ccContOpt3').offsetHeight - 1)) {
		document.getElementById('ccInnOpt3').style.top = TopOptStep3 - 3 + "px";
		if (!fermo){
			setTimeout('scrollaLayerOpt3Up()', speed);
		}
	} else return false;
}

function scrollaLayerOpt3Down() {

	var top = parseInt(document.getElementById('ccInnOpt3').style.top);
	if (top < 0) {
		document.getElementById('ccInnOpt3').style.top = top + 3 + "px";
		if (!fermo){
			setTimeout('scrollaLayerOpt3Down()', speed);
		}
	} else return false;
}
// FUNZIONI CHE FANNO SCROLLARE IL LAYER DETAILS
function scrollaLayerDetailUp() {

	TopDetailLay = parseInt(document.getElementById('detailInt').style.top);

	if (-TopDetailLay < (document.getElementById('detailInt').offsetHeight - document.getElementById('detailCont').offsetHeight - 1)) {
		document.getElementById('detailInt').style.top = TopDetailLay - 1 + "px";
		if (!fermo){
			setTimeout('scrollaLayerDetailUp()', speed);
		}
	} else return false;
}

function scrollaLayerDetailDown() {

	var top = parseInt(document.getElementById('detailInt').style.top);
	if (top < 0) {
		document.getElementById('detailInt').style.top = top + 1 + "px";
		if (!fermo){
			setTimeout('scrollaLayerDetailDown()', speed);
		}
	} else return false;
}


function convertApici(stArgo) {
	if(stArgo==null || stArgo=="") return stArgo;
	var patternA = /\"/g;
	var patternB = /\'/g;
	stArgo = stArgo.replace(patternA,'\"');
	stArgo = stArgo.replace(patternB,'\'');
	return stArgo;
}

/*
function convertApici(stArgo) {
	if(stArgo==null || stArgo=="") return stArgo;
	var patternA = /\"/g;
	var patternB = /\'/g;
	stArgo = stArgo.replace(patternA,'&quot;');
	stArgo = stArgo.replace(patternB,'&acute;');
	return stArgo;
}
*/

// ------------------ FIAT EXSTENSION ---------------------------------------------------------------------- //

function doNothing() {return;}

function mouseOverBC(code){
	for (i = 0; i < MvsBCList.length; i++) {
		if (MvsBCList[i].code == code) {
			document.getElementById('ncolore').innerHTML = convertApici(MvsBCList[i].desc);
			//alert('over - setting color: '+code);
			setFlashColor(code);
			break;
		}
	}
}

function mouseOutBC(code){
	document.getElementById('ncolore').innerHTML = convertApici(Vehicle.MvsBodyColor.desc);
	//alert('out - setting color: '+Vehicle.MvsBodyColor.code);
	setFlashColor(Vehicle.MvsBodyColor.code);
}

function mouseOverIP(code){
	for (i = 0; i < MvsIPList.length; i++) {
		if (MvsIPList[i].code == code) {
			var descInterniTMP = MvsIPList[i].desc;
			if (descInterniTMP.length > 26) descInterniTMP = '<a title="'+descInterniTMP+'" style="color:#625e3d;cursor:default;">'+convertApici(descInterniTMP.substring(0, 25))+'...</a>';
			document.getElementById('ntessuto').innerHTML = descInterniTMP;
			MM_swapImage('interniimgbig','',MvsIPList[i].imgBig,0);
			break;
		}
	}
}

function mouseOutIP(code){
	var descInterniTMP = Vehicle.MvsInnerPreparation.desc;
	if (descInterniTMP.length > 26) descInterniTMP = '<a title="'+descInterniTMP+'" style="color:#625e3d;cursor:default;">'+convertApici(descInterniTMP.substring(0, 25))+'...</a>';
	document.getElementById('ntessuto').innerHTML = descInterniTMP;
	MM_swapImage('interniimgbig','',Vehicle.MvsInnerPreparation.imgBig,0);
}

function mouseOverRim(code){
	//debugger;
	for (i = 0; i < OptionalList.length; i++) {
		if (OptionalList[i].code == code && /*OptionalList[i].category == '-'*/ isRim(OptionalList[i]) /* J070314 */) {
			var descCerchioniTMP = OptionalList[i].desc;
			if (descCerchioniTMP.length > 26){
				descCerchioniTMP = '<a title="'+descCerchioniTMP+'" style="color:#625e3d;cursor:default;">'+convertApici(descCerchioniTMP.substring(0, 25))+'...</a>';
			}
			document.getElementById('ncerchione').innerHTML = descCerchioniTMP;
			MM_swapImage('cerchioniimgbig','',OptionalList[i].imgBig,0);
			setFlashRim(OptionalList[i].flashName.substring(0, OptionalList[i].flashName.length -4));
			break;
		}
	}
}

function mouseOutRim(code){
	var descCerchioniTMP = getCerchione().desc;
	if (descCerchioniTMP.length > 26) descCerchioniTMP = '<a style="color:#625e3d;cursor:default;" title="'+descCerchioniTMP+'">'+convertApici(descCerchioniTMP.substring(0, 25))+'...</a>';
	document.getElementById('ncerchione').innerHTML = descCerchioniTMP;
	MM_swapImage('cerchioniimgbig','',getCerchione().imgBig,0);
	setFlash("OPT");
	//setFlashRim(getCerchione().code);
}

function isRim(optional)
{	
	//debugger;
	return optional.isRim==true; //optional.categoryTitle == 'Cerchioni'||optional.categoryTitle == 'Standard';
}
