function aslogan() {

      $("#slogan div").css("left","290px");
      $("#slogan div")
	.animate( { left:"0px"}, 1000 )
	.animate( { left:"0px"}, 1000 )
        .animate( { opacity: 0 }, 200)
        .animate( { opacity: 1 }, 200)
        .animate( { opacity: 0 }, 200)
        .animate( { opacity: 1 }, 200)
        .animate( {left:"-290px"}, 1000)
	.animate({ left:"-290px"}, 1000,null,aslogan);

}


function bslogan() {

      $("#slogan").css('opacity', 0);
      $("#sloganB").css('opacity', 0);

      $("#sloganB")
	.animate( { opacity: 0 }, 1500)
	.animate( { opacity: 1 }, 1000, null, function(){  $("#slogan").css('opacity', 1); } )
	.animate( { opacity: 0 }, 1000)
	.animate( { opacity: 0 }, 4000)
	.animate( { opacity: 1 }, 1000, null, function(){  $("#slogan").css('opacity', 0); } )
	.animate( { opacity: 0 }, 1000,null,bslogan);
	

}

$(document).ready( function(){
	/*
	
	$("#introTxt div:eq(0)").show("slow", function () {
        // use callee so don't have to name the function
		$(this).hide("slow", arguments.callee);
		$(this).next().show("slow", arguments.callee);
		

     });
	 */

bslogan();
	cScrollInit();

	 $('#newsy').cycle({ 
			fx: 'scrollUp' 
		});
	 
	 
	
	
	$(".red a").mouseover(function(){
		$(this)
			
			
			.animate({ backgroundColor: "#ffffff", color: "#FE0000" }, 100);
		

		
	});
	
	$(".blue a").mouseover(function(){
		$(this)
			
			.animate({ backgroundColor: "#ffffff", color: "#4352A8" }, 100);
		

		
	});
	
	$(".red a").mouseout(function(){
		$(this)
			

			.animate({ backgroundColor: "#FE0000", color: "#ffffff" }, 600);

		
	});
	
	$(".blue a").mouseout(function(){
		$(this)
			
			
			.animate({ backgroundColor: "#4352A8", color: "#ffffff" }, 600);

		
	});

	$("#submenu a").mouseover(function(){
		$(this)	
		.animate({ marginLeft: "5px" }, 100 );
	});
	$("#submenu a").mouseout(function(){
		$(this)	
		.animate({ marginLeft: "0px" }, 300 );
	});
		
});


function pobierz(nazwa) {
    if (document.cookie.length > 0) {
        startc = document.cookie.indexOf(nazwa + "=");
        if (startc != -1) {
            startc += nazwa.length + 1;
            endc = document.cookie.indexOf(";", startc);
            if (endc == -1) {
                endc = document.cookie.length;
            }
            return unescape(document.cookie.substring(startc,endc));
        }
	return false;
    }
    return false;
}

function rejestruj(nazwa, wartosc,dni) {
    var dzisiaj=new Date();
    var wygasnie=new Date();
    !dni ?dni=7 :"";
    wygasnie.setTime(dzisiaj.getTime()+1000*60*60*24*dni);
	document.cookie=nazwa+"="+escape(wartosc)+";expires="+wygasnie.toGMTString();
}

function cq (kod,zm) {

		var tmpIl = eval( "document.grupa[\"il["+kod+"]\"].value;");

		++tmpIl;

		--tmpIl;

		reszta = tmpIl%zm;

		if ((zm > 0) && (tmpIl < 999999) ) {

			eval( "document.grupa[\"il["+kod+"]\"].value = tmpIl + zm - reszta;");

		}

		else if ((zm < 0) && (tmpIl > 0)){

			if ( reszta > 0 ) { eval( "document.grupa[\"il["+kod+"]\"].value = tmpIl - reszta;"); }

			else {	eval( "document.grupa[\"il["+kod+"]\"].value = tmpIl + zm;"); }

		}

	if (document.getElementById('zzm')) {

			

			document.getElementById('zzm').className  = "bma";

		}

}



function rq (kod,zm) {

		var tmpIl = eval( "document.grupa[\"il["+kod+"]\"].value;");

		++tmpIl;

		--tmpIl;

		reszta = tmpIl%zm;

		if (!(tmpIl >= 0)) {

			alert ("Wprowadzono nie poprawna wartosc!");

			eval( "document.grupa[\"il["+kod+"]\"].value = 0;");

		}

		else if (reszta > 0) {

			alert ("Ilosc musi być wielokrotnoscia liczby "+zm);

			eval( "document.grupa[\"il["+kod+"]\"].value = tmpIl - reszta;");

		}

		if (document.getElementById('zzm')) {

			

			document.getElementById('zzm').className  = "bma";

		}


calcSum();
}

function ocq (obj,zm,min) {
		
		var inp = obj.parentNode.firstChild;
		trobj = obj.parentNode.parentNode;
		inp = inp.nextSibling;
		
		var tmpIl = parseInt(inp.value,10);

		var reszta = tmpIl%zm;

		if ((zm > 0) && (tmpIl < 999999) ) {
			inp.value = tmpIl + zm - reszta;
		}

		else if ((zm < 0) && (tmpIl > 0)){

			if ( reszta > 0 ) { inp.value = tmpIl - reszta; }
			else {	inp.value = tmpIl + zm; }
			

		}
		trobj.className = (inp.value > 0)?'wyr':'';
calcSum();

}

function roundIl(obj,zm, min) {
		var tmpIl = parseInt(obj.value,10);
		reszta = tmpIl%zm;
		if (min && tmpIl < zm && tmpIl > 0) {
			obj.value = tmpIl = zm;
		}
		if (!min && reszta > 0) {
			alert ("Ilość musi być wielokrotnością liczby "+zm);
			obj.value = tmpIl - reszta + zm;
		}
		//else obj.value = 0;
	calcSum();
	
}


/* Made by Mathias Bynens <http://mathiasbynens.be/> */
function number_format(a, b, c, d) {

	if (b == null) b = 2;
	if (c == null) c = '.';
	if (d == null) d = '';
 a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
 e = a + '';
 f = e.split('.');
 if (!f[0]) {
  f[0] = '0';
 }
 if (!f[1]) {
  f[1] = '';
 }
 if (f[1].length < b) {
  g = f[1];
  for (i=f[1].length + 1; i <= b; i++) {
   g += '0';
  }
  f[1] = g;
 }
 if(d != '' && f[0].length > 3) {
  h = f[0];
  f[0] = '';
  for(j = 3; j < h.length; j+=3) {
   i = h.slice(h.length - j, h.length - j + 3);
   f[0] = d + i +  f[0] + '';
  }
  j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
  f[0] = j + f[0];
 }
 c = (b <= 0) ? '' : c;
 return f[0] + c + f[1];
}



function calcSum() {
	
	var cena, sumaold, cenaold, kcena, kcenab, ilosc, maraza, cw, vat, martyp, suma, sumab, ksuma, ksumab, msuma, msumab;
	
	
	if (document.getElementById('ofsum')) {
		//cw = document.getElementById('calcw').value;
		//martyp = document.getElementById('percent').value;
		lp = 0;
		sumaold = suma = sumab = ksuma = ksumab = msuma = msumab = 0;
		while (document.getElementById('itemAmount'+lp)) {
		
			if (document.getElementById('itemPrice'+lp)) {
			cena = parseFloat(document.getElementById('itemPrice'+lp).innerHTML.replace(',','.'));

			//cenaold = parseFloat(document.getElementById('itemPriceOld'+lp).innerHTML.replace(',','.'));
			ilosc = parseInt(document.getElementById('itemAmount'+lp).value,10);
			document.getElementById('itemWart'+lp).innerHTML =  number_format(cena * ilosc, 2, ',', ' ');					
			suma += cena * ilosc;
			sumaold += cenaold * ilosc;
			
			}
			++lp;
		}
		//alert (suma);
		document.getElementById('ofsum').innerHTML = number_format(suma, 2, ',', ' ');
		//document.getElementById('ofbonus').innerHTML = number_format((sumaold - suma), 2, ',', ' ');

	}
	return suma;
	
}


function wPrzelicz() {
var wIn = document.getElementById('wIn').value;
var wOut = document.getElementById('wOut').value;
var wKwota = parseFloat(document.getElementById('wKwota').value.replace(',','.'));

var inPLn = wKwota * waluty[wIn][0]/waluty[wIn][1];

document.getElementById('wWynik').innerHTML = wKwota+' '+wIn+' = '+Math.round(inPLn*100/(waluty[wOut][0]/waluty[wOut][1]))/100+' '+wOut;
void(0);
}


function sprawdzform(minsum) {
	if (minsum && calcSum() < minsum) {
		alert('Suma zamówienia musi wynosić przynajmniej '+minsum+' zł');
		return false;
	}
}
