
var timeout = 20;
var RightTime,LeftTime,TopTime,BottomTime;

function stopMovement() {
	clearTimeout(LeftTime);
	clearTimeout(RightTime);
	clearTimeout(TopTime);
	clearTimeout(BottomTime);
	timeout=20;
}

function moveGalleryLeft(count) {

    step = 2;

    var table = document.getElementById('GalleryTable');

    var str = table.style.margin;
    var reg = /0px 0px 0px (-*[\d]+)px/;

    var margin = str.match(reg);

    var intmargin = eval(margin[1]);


    if (Math.abs(intmargin)/step > 1) {
        intmargin = intmargin + step;
        table.style.margin = '0px 0px 0px ' + intmargin + 'px';
    }
    else {
         jump = count * step - 145;
         table.style.margin = '0px 0px 0px -' + jump + 'px';
    }

	action = "moveGalleryLeft("+count+")";
	LeftTime = setTimeout(action,timeout);

    return false;

}


function moveGalleryRight(count) {

    step = 2;

    var table = document.getElementById('GalleryTable');

    var str = table.style.margin;
    var reg = /0px 0px 0px (-*[\d]+)px/;

    var margin = str.match(reg);
    var intmargin = eval(margin[1]) - step;

    if (Math.abs(intmargin)/step < count) {
        table.style.margin = '0px 0px 0px ' + intmargin + 'px';
    }
    else {
        table.style.margin = '0px 0px 0px -145px';
    }

	action = "moveGalleryRight("+count+")";
	RightTime = setTimeout(action,timeout);

    return false;

}


function activateItem(item, swatch, name, desc) {

	document.getElementById('AboutHeader').innerHTML = name;
	document.getElementById('AboutDiv').innerHTML = desc;
	document.getElementById('AboutDiv').style.margin = '1px 0px 0px 1px';

	var gallery = document.getElementById('fImg').getElementsByTagName('img');

	for ( var i = 0; i < gallery.length; i++ ) {
		gallery[i].style.display = 'none';
	}

	document.getElementById(item).style.display = 'block';


	var swatches = document.getElementById('fSwatch').getElementsByTagName('div');

	for ( var i = 0; i < swatches.length; i++ ) {
		swatches[i].style.display = 'none';
	}

	document.getElementById(swatch).style.display = 'block';

	return false;
}


function moveThumbsDown(count) {

	step = 132;

	var table = document.getElementById('ThumbTable');

	var str = table.style.margin;
	var reg = /(-*[\d]+)px 0px 0px -1px/;

	var margin = str.match(reg);
	var intmargin = eval(margin[1]) - step;

	if (Math.abs(intmargin)/step < count) {
		table.style.margin = intmargin + 'px 0px 0px -1px';
		document.getElementById('arrow_left').className = "arrow_active";
		if (Math.abs(intmargin)/step == count) {
			document.getElementById('arrow_right').className = "arrow_inactive";
		}
	}


	return false;
}


function moveThumbsUp(count) {

	step = 132;

	var table = document.getElementById('ThumbTable');

	var str = table.style.margin;
	var reg = /(-*[\d]+)px 0px 0px -1px/;

	var margin = str.match(reg);

	var intmargin = eval(margin[1]);

	if (intmargin < 1) {
		intmargin = intmargin + step;
		table.style.margin = intmargin + 'px 0px 0px -1px';
		document.getElementById('arrow_right').className = "arrow_active";
		if (Math.abs(intmargin)/step == 0) {
			document.getElementById('arrow_left').className = "arrow_inactive";
		}
	}

	return false;
}



function moveAboutUp() {

	step = 2;

	var block = document.getElementById('AboutDiv');

	var str = block.style.margin;
	var reg = /(\-*[\d]+)px 0px 0px 1px/;

	var margin = str.match(reg);

	var intmargin = eval(margin[1]);

	var CurrentPosition = parseInt(document.getElementById('CurrentPosition').value,10);

	if (CurrentPosition > 0) {

		intmargin = intmargin + step;
		block.style.margin = intmargin + 'px 0px 0px 1px';

		document.getElementById('arrow_down').className = "arrow_active";

		CurrentPosition--;

		if (CurrentPosition == 0) {
			document.getElementById('arrow_up').className = "arrow_inactive";
		}

		document.getElementById('CurrentPosition').value = CurrentPosition;

	}

	action = "moveAboutUp()";
	BottomTime = setTimeout(action,timeout);
	
	return false;
}


function moveAboutDown(sumbols, linesumbols) {

	var strlen = document.getElementById("AboutDiv").innerHTML.length;

	var count = Math.ceil(((strlen - sumbols) / (linesumbols * 2)*12))

	var step = 2;

	var block = document.getElementById('AboutDiv');

	var str = block.style.margin;

	var reg = /(\-*[\d]+)px 0px 0px 1px/;

	var margin = str.match(reg);

	var intmargin = eval(margin[1]);

	var CurrentPosition = parseInt(document.getElementById('CurrentPosition').value,10);

	if (CurrentPosition < count) {

		intmargin = intmargin - step;
		block.style.margin = intmargin + 'px 0px 0px 1px';

		document.getElementById('arrow_up').className = "arrow_active";

		CurrentPosition++;

		if (CurrentPosition == count) {
			document.getElementById('arrow_down').className = "arrow_inactive";
		}

		document.getElementById('CurrentPosition').value = CurrentPosition;

	}

	action = "moveAboutDown("+sumbols+","+linesumbols+")";
	BottomTime = setTimeout(action,timeout);
	
	return false;
}

// Store INFO

function moveStoreInfoUp(count) {

	step = 25;

	var block = document.getElementById('StoreInfoDiv');

	var str = block.style.margin;
	var reg = /(\-*[\d]+)px 0px 0px 1px/;

	var margin = str.match(reg);

	var intmargin = eval(margin[1]);

	var CurrentPosition = parseInt(document.getElementById('CurrentPositionStore').value,10);

	if (CurrentPosition > 0) {

		intmargin = intmargin + step;
		block.style.margin = intmargin + 'px 0px 0px 1px';

		document.getElementById('arrow_down_st').className = "arrow_active";

		CurrentPosition--;

		if (CurrentPosition == 0) {
			document.getElementById('arrow_up_st').className = "arrow_inactive";
		}

		document.getElementById('CurrentPositionStore').value = CurrentPosition;

	}


	return false;
}

function moveStoreInfoDown(count) {

	step = 25;

	var block = document.getElementById('StoreInfoDiv');

	var str = block.style.margin;
	var reg = /(\-*[\d]+)px 0px 0px 1px/;

	var margin = str.match(reg);

	var intmargin = eval(margin[1]);

	var CurrentPosition = parseInt(document.getElementById('CurrentPositionStore').value,10);

	if (CurrentPosition < count) {

		intmargin = intmargin - step;
		block.style.margin = intmargin + 'px 0px 0px 1px';

		document.getElementById('arrow_up_st').className = "arrow_active";

		CurrentPosition++;

		if (CurrentPosition == count) {
			document.getElementById('arrow_down_st').className = "arrow_inactive";
		}

		document.getElementById('CurrentPositionStore').value = CurrentPosition;

	}


	return false;
}

// Store MAP

function moveStoreMapUp(count) {

	step = 25;

	var block = document.getElementById('StoreMapDiv');

	var str = block.style.margin;
	var reg = /(\-*[\d]+)px 0px 0px 1px/;

	var margin = str.match(reg);

	var intmargin = eval(margin[1]);

	var CurrentPosition = parseInt(document.getElementById('CurrentPositionMap').value,10);

	if (CurrentPosition > 0) {

		intmargin = intmargin + step;
		block.style.margin = intmargin + 'px 0px 0px 1px';

		document.getElementById('arrow_down_map').className = "arrow_active";

		CurrentPosition--;

		if (CurrentPosition == 0) {
			document.getElementById('arrow_up_map').className = "arrow_inactive";
		}

		document.getElementById('CurrentPositionMap').value = CurrentPosition;

	}


	return false;
}

function moveStoreMapDown(count) {

	step = 25;

	var block = document.getElementById('StoreMapDiv');

	var str = block.style.margin;
	var reg = /(\-*[\d]+)px 0px 0px 1px/;

	var margin = str.match(reg);

	var intmargin = eval(margin[1]);

	var CurrentPosition = parseInt(document.getElementById('CurrentPositionMap').value,10);

	if (CurrentPosition < count) {

		intmargin = intmargin - step;
		block.style.margin = intmargin + 'px 0px 0px 1px';

		document.getElementById('arrow_up_map').className = "arrow_active";

		CurrentPosition++;

		if (CurrentPosition == count) {
			document.getElementById('arrow_down_map').className = "arrow_inactive";
		}

		document.getElementById('CurrentPositionMap').value = CurrentPosition;

	}


	return false;
}

