function Wyczysc() {
	document.getElementById('buttonApPa').checked = false;
	document.getElementById('buttonRpPr').checked = false;
	document.getElementById('buttonPp').checked = false;
	document.getElementById('pen1').src = 'images/pendrive1_06.gif';
	document.getElementById('pen2').src = 'images/pendrive1_07.gif';
	document.getElementById('pen3').src = 'images/pendrive1_08.gif';
}

function showMenu(menuId, akcja) {
	if(akcja == 'over') {
		document.getElementById(menuId).style.display = 'block';
		document.getElementById('slide').style.zIndex = 0;
	}
	else
		document.getElementById(menuId).style.display = 'none';
}

function showPromo(promoId) {
	var promoBoxes = document.getElementById('promoBoxes').getElementsByTagName('div');
	var i,n = 0;
	var itemsLen = promoBoxes.length;
	for (i=0,n=itemsLen;i<n;i++)
		if (promoBoxes[i].className.indexOf('promoBox') !=-1) {
				promoBoxes[i].style.display = 'none';
				document.getElementById(promoBoxes[i].id.replace('Box','')).className = document.getElementById(promoBoxes[i].id.replace('Box','')).className.replace("active_menu","");
		}
		document.getElementById(promoId+'Box').style.display = 'block';
		document.getElementById(promoId).className = document.getElementById(promoId).className + ' active_menu';

}

function Przelicz() {
	var slownikApPa = document.getElementById('buttonApPa').checked;
	var slownikRpPr = document.getElementById('buttonRpPr').checked;
	var slownikPp = document.getElementById('buttonPp').checked;
	
	var pojemnosc = document.getElementById('pojemnosc');
	var wolne = document.getElementById('wolne');
	var cenawlasciwa = document.getElementById('cenawlasciwa');
	var cenaprzed = document.getElementById('cenaprzed');
	var odnosnik = document.getElementById('odnosnik')
	
	if (slownikApPa) 
	{
		if (slownikRpPr)
		{
			if(slownikPp)
			{
				pojemnosc.innerHTML = "4GB";
				wolne.innerHTML = "2,45GB";
				cenaprzed.innerHTML = "349,02 zł";
				cenawlasciwa.innerHTML = "314,00 zł";
				odnosnik.href = "http://ksiegarnia.pwn.pl/produkt/7283/megapendrive-pwn.html?ksiazka_id=7283";
			}
			else
			{
				pojemnosc.innerHTML = "2GB";
				wolne.innerHTML = "0,8GB";
				cenaprzed.innerHTML = "299,01 zł";
				cenawlasciwa.innerHTML = "269,00 zł";
				odnosnik.href = "http://ksiegarnia.pwn.pl/produkt/7286/pendrive-pwn-1.html?ksiazka_id=7286";
			}
		}
		else
		{
			if(slownikPp)
			{
				pojemnosc.innerHTML = "2GB";
				wolne.innerHTML = "1GB";
				cenaprzed.innerHTML = "299,01 zł";
				cenawlasciwa.innerHTML = "269,00 zł";
				odnosnik.href = "http://ksiegarnia.pwn.pl/index.php?ksiazka_id=7285"; //USUNIĘTY Z KSIĘGARNI
			}
			else
			{
				pojemnosc.innerHTML = "2GB";
				wolne.innerHTML = "1,4GB";
				cenaprzed.innerHTML = "199,01 zł";
				cenawlasciwa.innerHTML = "179,00 zł";
				odnosnik.href = "http://ksiegarnia.pwn.pl/produkt/7282/wielki-multimedialny-slownik-angielskopolski-polskoangielski-pwnoxford-wersja-30-pendrive.html?ksiazka_id=7282";
			}
		}
	}
	else
	{
		if(slownikRpPr)
		{
			if(slownikPp)
			{
				pojemnosc.innerHTML = "2GB";
				wolne.innerHTML = "1GB";
				cenaprzed.innerHTML = "249,01 zł";
				cenawlasciwa.innerHTML = "224,00 zł";
				odnosnik.href = "http://ksiegarnia.pwn.pl/produkt/7284/pendrive-pwn-2.html?ksiazka_id=7284";
			}
			else
			{
				pojemnosc.innerHTML = "2GB";
				wolne.innerHTML = "1,4GB";
				cenaprzed.innerHTML = "149,01 zł";
				cenawlasciwa.innerHTML = "134,00 zł";
				odnosnik.href = "http://ksiegarnia.pwn.pl/produkt/7278/wielki-multimedialny-slownik-rosyjskopolski-polskorosyjski-pwn-wersja-20-pendrive.html?ksiazka_id=7278"; 
			}
		}
		else
		{
			if(slownikPp)
			{
				pojemnosc.innerHTML = "2GB";
				wolne.innerHTML = "1,6GB";
				cenaprzed.innerHTML = "149,01 zł";
				cenawlasciwa.innerHTML = "134,00 zł";
				odnosnik.href = "http://ksiegarnia.pwn.pl/produkt/7281/uniwersalny-slownik-jezyka-polskiego-pwn-wersja-30-pendrive.html?ksiazka_id=7281";

			}
			else
			{
				pojemnosc.innerHTML = "---";
				wolne.innerHTML = "---";
				cenaprzed.innerHTML = "00,00 zł";
				cenawlasciwa.innerHTML = "00,00 zł";
				odnosnik.href = "#";
			}
		}
	}
}

function Zamawiam()
{
	var slownikApPa = document.getElementById('buttonApPa').checked;
	var slownikRpPr = document.getElementById('buttonRpPr').checked;
	var slownikPp = document.getElementById('buttonPp').checked;
	if (! (slownikApPa || slownikRpPr || slownikPp)) alert('Aby zamówić musisz wybrać co najmniej jeden słownik!');
}

function Wybierz(imgId, chkId, ktore, option)
{
	var imgcont = document.getElementById(imgId);
	var checkbox = document.getElementById(chkId);
	var file = imgcont.src;
	var lng = file.length;
	var imgno = "0";
	if ((ktore == 1))
	{
		if (checkbox.checked && !option)
		{
			checkbox.checked = false;
			imgno = "1";
		}
		else
		{
			checkbox.checked = true;
			imgno = "2";
		}
	}
	else if (ktore == 2)
	{
		if (checkbox.checked)
		{
			imgno = "2";
		}
		else
		{
			imgno = "1";
		}
	}
	imgcont.src = file.slice(0,lng-8).concat(imgno, file.slice(lng-7));
	Przelicz();
}

function ZmienObrazek(imgId, fileName)
{
	var imgcont = document.getElementById(imgId);
	imgcont.src = fileName;
}

function getTopPos(inputObj)
{		
  var returnValue = inputObj.offsetTop;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
  }
  return returnValue;
}

function getLeftPos(inputObj)
{
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
  }
  return returnValue;
}

var slownik_checkbox = false;
var flyingDiv = false;
var slownik_checkbox_x = false;
var slownik_checkbox_y = false;
var slownik_img = false;
var slownik_img_width = false;
var slownik_img_height = false;
var currentXPos = false;
var currentYPos = false;
var diffX = false;
var diffY = false;
var ratx = false;
var raty = false;

function Lec(imgId, chkId, speed)
{
	var maxDiff = Math.max(Math.abs(diffX),Math.abs(diffY));
	var moveX = (diffX / maxDiff) * speed;
	var moveY = (diffY / maxDiff) * speed;	
	
	currentXPos = currentXPos + moveX;
	currentYPos = currentYPos + moveY;
	ratx = Math.abs(slownik_checkbox_x - currentXPos);
	raty = Math.abs(slownik_checkbox_y - currentYPos);
	if (ratx == 0) ratx = 1;
	if (raty == 0) raty = 1;
	var picMoveX = (slownik_img_width - 1) * Math.abs(moveX) / ratx;
	var picMoveY = (slownik_img_height - 1) * Math.abs(moveY) / raty
	slownik_img_width = slownik_img_width - picMoveX ;
	slownik_img_height = slownik_img_height - picMoveY ; 
	
	flyingDiv.style.left = Math.round(currentXPos) + 'px';
	flyingDiv.style.top = Math.round(currentYPos) + 'px';	

	if (slownik_img_width < 1) slownik_img_width = 1;
	if (slownik_img_height < 1) slownik_img_height = 1;
	
	flyingDiv.firstChild.style.width = Math.round(slownik_img_width) + 'px';
	flyingDiv.firstChild.style.height = Math.round(slownik_img_height) + 'px';
	
	if(moveX>=0 && currentXPos >= slownik_checkbox_x){
		flyingDiv.style.display='none';
	}
	if(moveX<=0 && currentXPos <= slownik_checkbox_x){
		flyingDiv.style.display='none';
	}
	if(flyingDiv.style.display=='block') 
	{
		setTimeout('Lec("' + imgId + '", "' + chkId + '", ' + speed + ')', 10); 
	}
	else 
	{
		
		Wybierz(imgId, chkId, 1, true);
	}
}

function DodajSlownik(productId, imgId, chkId, speed)
{
	slownik_checkbox = document.getElementById(chkId);
	if (!flyingDiv) 
	{
		flyingDiv = document.createElement('DIV');
		flyingDiv.style.position = 'absolute';
		flyingDiv.style.textAlign = 'left';
		document.body.appendChild(flyingDiv);
	}
	slownik_checkbox_x = getLeftPos(slownik_checkbox);
	slownik_checkbox_y = getTopPos(slownik_checkbox);
	slownik_img = document.getElementById(productId);
	slownik_img_width = slownik_img.width;
	slownik_img_height = slownik_img.height;
	currentXPos = getLeftPos(slownik_img);
	currentYPos = getTopPos(slownik_img);
	diffX = slownik_checkbox_x - currentXPos;
	diffY = slownik_checkbox_y - currentYPos;
	
	flyingDiv.innerHTML = '<img src="' + slownik_img.src + '" alt="' + slownik_img.alt + '" />';
	flyingDiv.style.left = currentXPos + 'px';
	flyingDiv.style.top = currentYPos + 'px';
	flyingDiv.style.display='block';
	flyingDiv.style.width = slownik_img.offsetWidth + 'px';
	Lec(imgId, chkId, speed);
}