var currPage = 1;
function setPage( pageNumber ) {
	var scrollTime = 800;
	var scrollContainer = $('#offer_cont');
	
	var pagingArray = $('#paging a');
	$( pagingArray[ pageNumber ] ).addClass( 'active' );
	
	$( pagingArray[ currPage ] ).removeClass( 'active' );
	currPage = pageNumber;
	
	
	
	$( scrollContainer ).animate({ 
        marginTop: ( pageNumber-1 )*( -1 )*$('.offer_item').height()
	}, scrollTime );
}
function previousPage() {
	var movePage = currPage - 1;
	if ( movePage < 1  ) {
		movePage = $('#offer_cont .offer_item').length;
	}
	
	setPage( movePage );
}
function nextPage() {
	var movePage = currPage + 1;
	
	if ( movePage > $('#offer_cont .offer_item').length ) {
		movePage = 1;
	} 
	setPage( movePage );
}
var activeAd = false;
function changeAd( number ) {
	$('.p_heads').show( 500 );
	if (activeAd != number) {
		if ( activeAd ) {
			$('#p_content_'+activeAd ).hide( 500 );
			$('#p_head_'+activeAd ).removeClass( 'active' );
		}
		$('#p_all').hide( 500 );
		$('#p_head_'+number ).addClass( 'active' );
		$('#p_content_'+number ).show( 500 );
		activeAd = number;
	}
}
function fadeAd( number ) {
	$('#m'+number+' img').fadeTo( 300, 1 );
}
function fadeAdBack( number ) {
	$('#m'+number+' img').fadeTo( 300, 0.5 );
}
var activeColor = 1;
function changeColor( number, color, img ) {

	$('#color_image').attr( 'src', img);
	$('#c_code').html( color );
	$('#colors span').removeClass('active');
	$('#box_'+number).attr('class', 'active');
	
}

function number_format( number, decimals, dec_point, thousands_sep ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // *     example 1: number_format(1234.5678, 2, '.', '');
    // *     returns 1: 1234.57     
 
    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "." : dec_point;
    var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}

function popup(URL, h, w)
	{
		var Left = (screen.width - w) / 2;
		var Top  = (screen.height - h) / 2;
		 
		 window.open(URL, '', "width="+ w +",height="+ h +",left="+ Left +",top="+ Top +",scrollbars=1");
	}



function checkvals(formname)
{
	empty = false;
	
	for (i=0; i<fields.length; i++)
	{
		if (document.getElementById('form_'+fields[i]).value == "")
		{
			empty = true;
			document.getElementById('label_'+fields[i]).className = 'error';
		}
		else
		{
			document.getElementById('label_'+fields[i]).className = '';
		}
	}
	
	for (i=0; i<inputs.length; i++)
	{
		if (document.getElementById('form_'+inputs[i]).checked != true)
		{
			empty = true;
			document.getElementById('label_'+inputs[i]).className = 'error';
		}
		else
		{
			document.getElementById('label_'+inputs[i]).className = '';
		}
	}
	
	
	if (empty) setTimeout('clearVals()', 1000);
	else formname.submit();
}


function clearVals()
{
	return; // kad nedingtu raudoni
	
	for (i=0; i<fields.length; i++)
	{
		if (document.getElementById('form_'+fields[i]).value == "")
		{
			document.getElementById('label_'+fields[i]).className = '';
		}
	}
	
	for (i=0; i<inputs.length; i++)
	{
		if (document.getElementById('form_'+inputs[i]).checked != true)
		{
			document.getElementById('label_'+inputs[i]).className = '';
		}
	}
}

