var position = 0;

function showBg(sPath, sId)
{
	oTd = document.getElementById(sId);
	if(oTd)
	{
		//alert(oTd.style.backgroundImage);
		oTd.style.backgroundImage = 'url("'+sPath+'")';
	}
}

	inpDropText = function(input, text) {
		if (input.value == text) input.value = '';
	}
	

function preview()
{
	oDiv = document.getElementById('sliderContainer');
	if(oDiv)
	{
//		alert(position);
		if(-(intval(oDiv.style.left)-40-646) <= intval(oDiv.style.width))
		{
			if(position >= 0 && position <=1)
			{count = 606}else{count = 566}
			step = -20;
			window.setTimeout('changePosition('+intval(oDiv.style.left)+', '+(intval(oDiv.style.left)-count)+','+step+', '+10+')', 10);
//				tmp = intval(oDiv.style.left)-1;
//				oDiv.style.left = tmp+'px';
			position--;
		}
	}
}

function next()
{
	oDiv = document.getElementById('sliderContainer');
	if(oDiv)
	{
//		alert(position);
		if(intval(oDiv.style.left) < 0)
		{
			if(position <=0 && position >=-1)
			{count = 606}else{count=566}
			window.setTimeout('changePosition('+intval(oDiv.style.left)+', '+(intval(oDiv.style.left)+count)+','+20+', '+10+')', 10);
//				tmp = intval(oDiv.style.left)+1;
//				oDiv.style.left = tmp+'px';
			position++;
		}
	}
}

function changePosition(start, finish, step, time)
{
//	alert('start='+start+'; finish='+finish+'; step='+step);
	obj = document.getElementById('sliderContainer');

	oPrev = document.getElementById('previewButton');
	if(oPrev){oPrev.style.display = 'none';}

	
	oNext = document.getElementById('nextButton');
	if(oNext){oNext.style.display = 'none';}
	
	
//	alert('start='+start+'; finish='+finish+'; step='+step+'; left='+intval(obj.style.left));
	if(obj)
	{
		if(step > 0)
		{
			if(intval(obj.style.left)+step <= finish)
			{
				obj.style.left = intval(obj.style.left)+step+'px';
				window.setTimeout('changePosition('+start+','+finish+','+step+','+time+')',time);
				
			}else{
				obj.style.left = finish+'px';
				if(intval(obj.style.left) <= 0)
				{
					if(oNext){oNext.style.display = 'block';}
				}
				if(oPrev){oPrev.style.display = 'block';}
				clearInterval();
			}
		}else{
				
			if(intval(obj.style.left)+step >= finish)
			{
				
				obj.style.left = intval(obj.style.left)+step+'px';
				window.setTimeout('changePosition('+start+','+finish+','+step+','+time+')',time);
			}else{
				obj.style.left = finish+'px';
				if(oNext){oNext.style.display = 'block';}
				
				if(intval(obj.style.left)-646 >= (-intval(obj.style.width)) )
				{
					if(oPrev){oPrev.style.display = 'block';}
				}
				clearInterval();
			}
		}
		
	}
}

function intval (mixed_var, base) {
    // Get the integer value of a variable using the optional base for the conversion  
    // 
    // version: 1107.2516
    // discuss at: http://phpjs.org/functions/intval    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: stensi
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Matteo
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)    // +   bugfixed by: Rafał Kukawski (http://kukawski.pl)
    // *     example 1: intval('Kevin van Zonneveld');
    // *     returns 1: 0
    // *     example 2: intval(4.2);
    // *     returns 2: 4    // *     example 3: intval(42, 8);
    // *     returns 3: 42
    // *     example 4: intval('09');
    // *     returns 4: 9
    // *     example 5: intval('1e', 16);    // *     returns 5: 30
    var tmp;
 
    var type = typeof(mixed_var);
     if (type === 'boolean') {
        return +mixed_var;
    } else if (type === 'string') {
        tmp = parseInt(mixed_var, base || 10);
        return (isNaN(tmp) || !isFinite(tmp)) ? 0 : tmp;    } else if (type === 'number' && isFinite(mixed_var)) {
        return mixed_var | 0;
    } else {
        return 0;
    }
}
