
// STORAGE FOR FLOATS
var height = new Array();
height[1]=0;
height[2]=0;
height[3]=0;
height[4]=0;
height[5]=0;
height[6]=0;
height[7]=0;
height[8]=0;
height[9]=0;
height[10]=0;
height[11]=0;
height[12]=0;
height[13]=0;
height[14]=0;
height[15]=0;
height[16]=0;
height[17]=0;
height[18]=0;
height[19]=0;
height[20]=0;
height[21]=0;
height[22]=0;
height[23]=0;
height[24]=0;

var slope = new Array();
slope[1]=0;
slope[2]=0;
slope[3]=0;
slope[4]=0;
slope[5]=0;
slope[6]=0;
slope[7]=0;
slope[8]=0;
slope[9]=0;
slope[10]=0;
slope[11]=0;
slope[12]=0;
slope[13]=0;
slope[14]=0;
slope[15]=0;
slope[16]=0;
slope[17]=0;
slope[18]=0;
slope[19]=0;
slope[20]=0;
slope[21]=0;
slope[22]=0;
slope[23]=0;
slope[24]=0;

var float = new Array();
float[0]=0.3;	//amount		// FINISH vv
float[1]=0.3;	//bump_size
float[2]=0.02;	//accuracy		// crand
float[3]=1;	//scale x
float[4]=1;	//scale y
float[5]=1;	//scale z
float[6]=0;	//rotate x  		//specular
float[7]=0;	//rotate y  		// roughness
float[8]=0;	//rotate z		// falloff
float[9]=0;	//translate x		// exponent
float[10]=0;	//translate y		// metallic
float[11]=0;	//rtranslate x		// Irid_Amount
float[12]=0;	//light location x	// thickness
float[13]=2;	//light location y
float[14]=-3;	//light location z
float[15]=0;	//turbulence amount x	// turbulence
float[16]=0;	//turbulence amount y   //light x
float[17]=0;	//turbulence amount z
float[18]=6;	//turbulence octaves
float[19]=0.5;	//turbulence octaves
float[20]=2.0;	//turbulence lambda
float[21]=1;	//frequency:		// metallic
float[22]=0.0;	//phase
float[23]=1.5;  // brick_sizeX
float[24]=1;  // brick_sizeY
float[25]=1.5;  // brick_sizeZ		// brilliance
float[26]=0.2;  // mortar size
float[27]=0.7;  // diffuse
float[28]=0.7;  // phong
float[29]=60;  // phong_size

var stop = new Array;	// Supposed to put clearIntervals into to stop animation

// FOR DRAGGING
// Position X of the little div
var divX = new Array();

// Position Y of the little div
var divY = new Array();

//FOR CALCULATING VALIES TOINPUT
var divCalc = new Array();


// Find coordinates of the Elelment
function elCoords(id) {
var obj= document.getElementById(id);
var curleft = curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} 
while (obj = obj.offsetParent);
var COORDS = new Array;
COORDS[0]=curleft;
COORDS[1]=curtop;
return COORDS;
}
}
// width and height of the element
function elParams(id)
{
var height = document.getElementById(id).clientHeight ;
var width = document.getElementById(id).clientWidth;
var out = new Array;
out[0] = width;
out[1] = height;
return out;
}




//Placing little DIVs in SLOPEMAP

// num= number of the slopeBar

function slopemap(num)
{
//placing the divs
if(num<31)
{
var DragcellPos = elCoords('dragcell');
var DragcellParam = elParams('dragcell');

var SlopemapBarPos = elCoords('slopebar'+ num);
var SlopemapBarParam = elParams('slopebar' + num);
}
else {
var DragcellPos = elCoords('dragcellmap');
var DragcellParam = elParams('dragcellmap');

var SlopemapBarPos = elCoords('slopebarmap'+ num);
var SlopemapBarParam = elParams('slopebarmap' + num);	
}

var left = DragcellPos[0]+DragcellParam[0]/2 -5; // horizontally
var top= SlopemapBarPos[1]+SlopemapBarParam[1]/2-1 ; //vertically
divX[num]=left;
divY[num]=top;

var lilDIV = document.getElementById('L'+ num);

lilDIV.style.left = (parseInt(left)) + 'px';
lilDIV.style.top = (parseInt(top)) + 'px';
lilDIV.style.position = 'absolute';
lilDIV.style.display = 'block';

//writing to input
var lilDivcoords = elCoords('L'+num)
var toinput = (lilDivcoords[1]-DragcellPos[1])/DragcellParam[1];
toinput=parseFloat(toinput.toFixed(3));
divCalc[num]=toinput; // to the array

var input = document.getElementById('E'+ num);
input.value=toinput;
}

// DRAGGING
//up
function up (num)
{ if(num<31)
{
var DragcellPos = elCoords('dragcell'); // horizontal adjust/recalculating	
var DragcellParam = elParams('dragcell');
}
else {
var DragcellPos = elCoords('dragcellmap'); // horizontal adjust/recalculating	
var DragcellParam = elParams('dragcellmap');
}
var HOR = DragcellPos[0]+DragcellParam[0]/2 -5; 
divX[num]=HOR;

var lilDIV = document.getElementById('L'+ num);
lilDIV.style.left = (parseInt(HOR)) + 'px';
lilDIV.style.position = 'absolute';


var upperlimit = DragcellPos[1];
var lowerlimit=upperlimit+DragcellParam[1];

var start=divY[num];
if(start>lowerlimit) // jumping up
{divY[num]=lowerlimit;}

if (upperlimit < start)
{
// moving the lil div without recalculation of the value

	
var step=divY[num]-1;

lilDIV.style.top = (parseInt(step)) + 'px';

// Recalculation input values
var lilDivcoords = elCoords('L'+num)
var toinput = (lilDivcoords[1]-DragcellPos[1])/DragcellParam[1];
divY[num]=step;
if (toinput >= 0)
{
toinput=parseFloat(toinput.toFixed(3));
divCalc[num]=toinput; // to the array

var input = document.getElementById('E'+ num);
input.value=toinput;
}

}
}

// listener for preventing dragging up
function moveup(num) {

var stopTR = document.getElementById('E'+num+'_trenc');
var stopTD = document.getElementById('E'+num+'_tdenc');
	
if( stopTR.addEventListener ) {
stopTR.addEventListener("mouseup", stopUP, true);
stopTD.addEventListener("mouseout", stopUP, true);
}
else {
stopTR.attachEvent("onmouseup",stopUP);
stopTD.attachEvent("onmouseout",stopUP);
}
var func= "up("+num+")";
if (num < 31) {
stop[0]=setInterval(func,70);
}
else {
stop[0]=setInterval(func,40);	
}
}

// DRAGGING DOWN

function down (num)
{
	
 if(num<31)
{
var DragcellPos = elCoords('dragcell'); // horizontal adjust/recalculating	
var DragcellParam = elParams('dragcell');
}
else {
var DragcellPos = elCoords('dragcellmap'); // horizontal adjust/recalculating	
var DragcellParam = elParams('dragcellmap');
}


var HOR = DragcellPos[0]+DragcellParam[0]/2 -5; 
divX[num]=HOR;

var lilDIV = document.getElementById('L'+ num);
lilDIV.style.left = (parseInt(HOR)) + 'px';
lilDIV.style.position = 'absolute';


var upperlimit = DragcellPos[1];
var lowerlimit=upperlimit+DragcellParam[1];
var start=divY[num];

if(start<upperlimit) // jumping up
{divY[num]=upperlimit;}

if (lowerlimit > start)
{
// moving the lil div without recalculation of the value
var step=divY[num]+1;
divY[num]=step;
lilDIV.style.top = (parseInt(step)) + 'px';

// Recalculation input values


var lilDivcoords = elCoords('L'+num)
var toinput = (lilDivcoords[1]-DragcellPos[1])/DragcellParam[1];
if (toinput <= 1)
{
toinput=parseFloat(toinput.toFixed(3));
divCalc[num]=toinput; // to the array

var input = document.getElementById('E'+ num);
input.value=toinput;
}
}
}

// listener for preventing dragging down
function movedown(num) {

var stopTR = document.getElementById('E'+num+'_trdecOFF');
var stopTD = document.getElementById('E'+num+'_tddecOFF');
	
if( stopTR.addEventListener ) {
stopTR.addEventListener("mouseup", stopDOWN, true);
stopTD.addEventListener("mouseout", stopDOWN, true);
}
else {
stopTR.attachEvent("onmouseup",stopDOWN);
stopTD.attachEvent("onmouseout",stopDOWN);
}
var func= "down("+num+")";
if(num < 31 ) {
stop[1]=setInterval(func,70);
}
else {
stop[1]=setInterval(func,40);	
}
}

//===================================================
// Encrease
function add(kind, num)
{

switch(kind)
{
case 'height':
var id='height'
var value=height[num]+0.01;
height[num]=value;
break; 

case 'slope':
var id='slope'
var value=slope[num]+0.01;
slope[num]=value;
break; 
case 'float':
var id='float'
var value=float[num]+0.01;
float[num]=value;
break; 

}
value=s=parseFloat(value.toFixed(3));
var write = document.getElementById(id+num);
write.value=value;
}

// Listener
function start_add(kind, num) {
	var listener = document.getElementById(kind+num+'_trenc');
	var listn_out = document.getElementById(kind+num+'_tdenc')
	
if( listener.addEventListener ) {
listener.addEventListener("mouseup", stop_add, true);
listn_out.addEventListener("mouseout", stop_add, true)
}
else {
listener.attachEvent("onmouseup",stop_add);
listn_out.attachEvent("onmouseout",stop_add);
}
var func= "add('"+kind+"', '"+num+"')"
stop[2]=setInterval(func,50);
}

// Decrease
function substr(kind, num)
{

switch(kind)
{
case 'height':
var id='height'
var value=height[num]-0.01;
height[num]=value;
break; 

case 'slope':
var id='slope'
var value=slope[num]-0.01;
slope[num]=value;
break;

case 'float':
var id='float'
var value=float[num]-0.01;
float[num]=value;
break; 
}
value=s=parseFloat(value.toFixed(3));
var write = document.getElementById(id+num);
write.value=value;
}

// Listener
function start_substr(kind, num) {
	var listener = document.getElementById(kind+num+'_trdec');
	var listn_out = document.getElementById(kind+num+'_tddec')
	
if( listener.addEventListener ) {
listener.addEventListener("mouseup", stop_substr, true);
listn_out.addEventListener("mouseout", stop_substr, true)
}
else {
listener.attachEvent("onmouseup",stop_substr);
listn_out.attachEvent("onmouseout",stop_substr);
}
var func= "substr('"+kind+"', '"+num+"')"
stop[3]=setInterval(func,50);
}


function newline(num)
{
var a = document.getElementById('L'+num);
a.style.display='block';
if(num < 31)
{
var b = document.getElementById('slopebar'+num);
}
else {
var b = document.getElementById('slopebarmap'+num);	
}
b.style.display='block';

}

function remove(num)
{
var a = document.getElementById('L'+num);
a.style.display='none';
var c = document.getElementById('E'+num)
c.value='';


if(num < 31)
{
var b = document.getElementById('slopebar'+num);
}
else {

var b = document.getElementById('slopebarmap'+num);
}
b.style.display='none';
}
//==================================================
//Stopage Functions
function stopUP ()	
{ clearInterval(stop[0]);}

function stopDOWN ()	
{ clearInterval(stop[1]);}

function stop_add()
{ clearInterval(stop[2]);}

function stop_substr()
{ clearInterval(stop[3]);}

/// SHOWCOLORPICKER ///////////////////////////////
function showColorPicker(id)
{document.getElementById(id).style.display = 'block';}

//REMOVE pigments
function removeAllPigments()
{
var a = document.getElementById('custom_pigment');
a.style.display='none';
var b = document.getElementById('user_pigment');
b.style.display='none';
}


// show CUSTOM pigment
function showCustomPigment()
{
removeAllPigments();
var a = document.getElementById('custom_pigment');
a.style.display='block';
}

// show USER pigment
function showUserPigment()
{
removeAllPigments();
var a = document.getElementById('user_pigment');
a.style.display='block';
}

// HIDE normals patterns
function hideNormPatterns()
{
var a = document.getElementById('custom_pattern');
a.style.display='none';
}

// show CUSTOM normal pattern pigment
function showCustomNormalPattern()
{
hideNormPatterns();
var a = document.getElementById('custom_pattern');
a.style.display='block';
}

function useFinishItem(id,id2, id3)
{
var a = document.getElementById(id);
a.style.display='block';
var b = document.getElementById(id2);
b.style.color='#BDB68D';
var d = document.getElementById(id3);
d.value='ON';
}

function hideFinishItem(id, id2, id3)
{
var b = document.getElementById(id);
b.style.display='none';	
var c = document.getElementById(id2);
c.style.color='green';
var d = document.getElementById(id3);
d.value='OFF';
}




