// gorne menu
function submenuAnimation() {
	var submenuPosition = document.getElementById('mainMenu').getElementsByTagName('ins');
	var submenuHref = document.getElementById('mainMenu').getElementsByTagName('a');
	var submenusUl = document.getElementById('mainMenu').getElementsByTagName('ul')
	for (var i=0; i<submenuPosition.length; i++) {
		submenuPosition[i].onclick = function (){
			for (var k=0; k<submenusUl.length; k++) {
				if (submenusUl[k].className == "submenu") {
					submenusUl[k].style.display = "none";
				}
			}
			for (var l=0; l<submenuPosition.length; l++) {
				submenuPosition[l].className = "";
				submenuPosition[l].parentNode.getElementsByTagName('div')[0].style.display = "none";
			}
			this.className = "selected";
			this.parentNode.getElementsByTagName('div')[0].style.display = "block";
			this.parentNode.getElementsByTagName('ul')[0].style.display = "block";
		}
	}
	for (var j=0; j<submenuHref.length; j++) {
		if (submenuHref[j].className == "submenu") {
			submenuHref[j].onclick = function () {
				if (this.parentNode.getElementsByTagName('div')[0] != null ) {
					this.parentNode.getElementsByTagName('div')[0].style.display = "block";
				}
				for (var k=0; k<submenusUl.length; k++) {
					if (submenusUl[k].className == "submenu2nd") {
						submenusUl[k].style.display = "none";
					}
				}
				for (var l=0; l<submenuHref.length; l++) {
					submenuHref[l].className = "submenu"
				}
				this.className = "submenu selected"
				var submenuHrefsId = document.getElementById(String(this.href).split('#')[1]);
				submenuHrefsId.style.display = "block";
				return false;
			}
		}
	}
	var categories = document.getElementById('mainMenu').getElementsByTagName('span');
	for (var j=0; j<categories.length; j++) {
		categories[j].onclick = function () {
			this.parentNode.className = "active";
			this.parentNode.style.zIndex = "4";
			if (this.parentNode.getElementsByTagName('ul')[0] != null) {
				this.parentNode.getElementsByTagName('ul')[0].onmouseover = function () {
					this.parentNode.className = "active";
					this.parentNode.style.zIndex = "4";				
				}
				this.parentNode.getElementsByTagName('ul')[0].onmouseout = function () {
					this.parentNode.className = "";
					this.parentNode.style.zIndex = "1";
				}
			}
		}
		categories[j].onmouseout = function () {
			this.parentNode.className = "";
			this.parentNode.style.zIndex = "1";	
		}
		categories[j].onmouseover = function () {
			for (var i=0; i<this.parentNode.getElementsByTagName('ul').length; i++) {
				if (this.parentNode.getElementsByTagName('ul')[i].className == "submenu3rd") {
					this.parentNode.getElementsByTagName('ul')[i].style.display = "none";
				}
			}
		}

	}
	var subcategories = document.getElementById('mainMenu').getElementsByTagName('em');
	for (var j=0; j<subcategories.length; j++) {
		subcategories[j].onclick = function (){
			if(this.parentNode.getElementsByTagName('ul')[0].style.display != "block") {
				this.parentNode.getElementsByTagName('ul')[0].style.display = "block"
			}
			else {
				this.parentNode.getElementsByTagName('ul')[0].style.display = "none"
			}
		}
	}
}

/*function submenuAnimation() {
	var position = document.getElementById('mainMenu').childNodes;
	for (i=0; i<position.length; i++) {
		if (position[i].tagName&&position[i].tagName.toLowerCase()=="li") {
			position[i].onclick = function () {
				var curretPosition = this;
				for (var k=0; k<document.getElementById('mainMenu').getElementsByTagName('li').length; k++) {
					if (document.getElementById('mainMenu').getElementsByTagName('li')[k].getElementsByTagName('ins')[0] != null) {
						document.getElementById('mainMenu').getElementsByTagName('li')[k].getElementsByTagName('ul')[0].style.display = "";
						document.getElementById('mainMenu').getElementsByTagName('li')[k].getElementsByTagName('ins')[0].className = "";
					}
				}
				curretPosition.getElementsByTagName('ul')[0].style.display = "block";
				curretPosition.getElementsByTagName('ins')[0].className = "selected";
				if (String(window.navigator.appVersion).match('MSIE 6')) {
					var curretSubmenuHeight = curretPosition.getElementsByTagName('ul')[0].offsetHeight;
					curretPosition.parentNode.style.height = curretSubmenuHeight +"px";
				}
			}
		}
		var categories = document.getElementById('mainMenu').getElementsByTagName('span');
		for (var j=0; j<categories.length; j++) {
			categories[j].onclick = function () {
				this.parentNode.className = "active";
				this.parentNode.style.zIndex = "4";				
				this.parentNode.getElementsByTagName('dl')[0].onmouseover = function () {
					this.parentNode.className = "active";
					this.parentNode.style.zIndex = "4";				
				}
				this.parentNode.getElementsByTagName('dl')[0].onmouseout = function () {
					this.parentNode.className = "";
					this.parentNode.style.zIndex = "1";				
				}
			}
			categories[j].onmouseout = function () {
				this.parentNode.className = "";
				this.parentNode.style.zIndex = "1";				
			}
		}
	}
}*/


// otwieranie linkw w nowym oknie
function newWindow() {
	var hyperlink = document.getElementsByTagName('a');
	
	for (var i=0; i<hyperlink.length; i++) {
		if (String(hyperlink[i].className).match("openNew")) {
			hyperlink[i].onclick = function () {
				window.open(this.href);
				return false;
			}
		}
	}
}


// slider produktow
function codaSlider() {
	jQuery(window).bind("load", function() {
		jQuery("div#slider1").codaSlider()
		jQuery("div#slider2").codaSlider()
		jQuery("div#slider3").codaSlider()
	});
	
	var boxMenu = document.getElementById('boxMenu').getElementsByTagName('li');
	for (var i=0; i<boxMenu.length; i++) {
		var boxMenuPositions = boxMenu[i];
		boxMenu[i].onclick = function () {
			for (var j=0; j<document.getElementById('boxMenu').getElementsByTagName('a').length; j++) {
				document.getElementById('boxMenu').getElementsByTagName('a')[j].className = "";
			}
			
			this.getElementsByTagName('a')[0].className = "selected";
			var tabId = String(this.getElementsByTagName('a')[0].href).split('#')[1];
			var tabs = document.getElementById('newPopular').childNodes;
			for (var j=0; j<tabs.length; j++) {
				if (tabs[j].tagName&&tabs[j].tagName.toLowerCase()=="div") {
					tabs[j].style.visibility = "hidden";
				}
			}
			document.getElementById(tabId).style.visibility = "visible";
			return false;
		}
	}
}


// rozwijanie boxa z kontaktem
function contact() {
	var more = document.getElementById('contact').getElementsByTagName('span')[0];
	var addresses = document.getElementById('contact').getElementsByTagName('ul')[0];
	if (more != null) {
		more.onclick = function () {
			if (addresses.style.display != "block") {
				addresses.style.display = "block";
			}
			else {
				addresses.style.display = "none";
			}
		}
	}
}


// rozwijanie boxa wyszukiwania
function searchBox() {
	var box = document.getElementById('searchBox');
	var more = document.getElementById('searchBox').getElementsByTagName('strong')[0];
	if (more != null) {
		more.onclick = function () {
			this.style.display = "none";
			var fieldsetHeight = box.getElementsByTagName('fieldset')[0].offsetHeight;
			box.style.height = fieldsetHeight +"px";
			var boxinputs = document.getElementById('searchBox').getElementsByTagName('input');
			for (var i=0; i<boxinputs.length; i++) {
				if(boxinputs[i].className == "button") {
					boxinputs[i].style.bottom = "0";
				}
			}
		}
	}
}


// pokazywanie boxa z porównywaniem
function compareBox() {
	var hyperlink = document.getElementsByTagName('a');
	
	for (var i=0; i<hyperlink.length; i++) {
		if (String(hyperlink[i].className).match("compare")) {
			hyperlink[i].onclick = function () {
				var compareBox = document.getElementById(String(this.href).split('#')[1]);
				if (compareBox.style.display != "block") {
					compareBox.style.display = "block"
				}
				else {
					compareBox.style.display = "none"
				}
				return false;
			}
		}
	}
}		


// odsluga pokazywania szczegolow faktur
function invoices() {
	var hyperlink = document.getElementsByTagName('a');
	var divs = document.getElementsByTagName('div');

	for (var i=0; i<hyperlink.length; i++) {
		if (String(hyperlink[i].className).match("invoiceParticulars")) {
			function invoiceParticulars() {
				for (var j=0; j<divs.length; j++) {
					if (divs[j].className == "invoice") {
						divs[j].style.display = "none"
					}
				}
			}
			function clearRowClass() {
				var row = document.getElementById('basket').getElementsByTagName('tr');
				for (var j=0; j<row.length; j++) {
					row[j].className = "";
				}
			}
			hyperlink[i].onclick = function () {
				invoiceParticulars();
				clearRowClass();
				this.parentNode.parentNode.className = "selected";
				var invoiceParticularsId = document.getElementById(String(this.href).split('#')[1]);
				invoiceParticularsId.style.display = "block";
				return false;
			}
		}
	}
}		


// pokazywanie dodatkowych pozycji do pobrania w karcie produktu
function files() {
	var showButton = document.getElementById('files').getElementsByTagName('strong')[0];
	
	showButton.onclick = function () {
		var list = document.getElementById('files').getElementsByTagName('ul')[0];
		if (list.className == null || list.className == "") {
			list.className = "all";
			this.className = "less";
		}
		else {
			list.className = "";
			this.className = "more";
		}
	}
}

window.onload = function () {
	submenuAnimation();
	newWindow();
	if(document.getElementById('slider1')){codaSlider();}
	contact();
	if(document.getElementById('searchBox')){searchBox();}
	compareBox();
	invoices();
	if(document.getElementById('files')){files();}
}

















