
	// var bname = navigator.appName;
	// var bver  = parseFloat( navigator.appVersion );
	// var bcode = navigator.appCodeName;
	// var bplat = navigator.platform;
		
	//alert("You are using " + bname + "\nIt's version is " + bver + "\nThe code name of this browser is '" + bcode + "'\nYou're working on " + bplat);

// Menu Functions
	function start ( menu_exp ) {
		if (!document.getElementById || !document.createElement || !document.appendChild) return false;
		
		var is_ie = (navigator.appName == 'Microsoft Internet Explorer');
		
		//Catalog		
		for (i=0; i<menu_exp.length; i++) {
			if (menu_exp[i] != null) {
				var exp_el = document.getElementById("menu"+menu_exp[i]).getElementsByTagName('ul')[0];
				exp_el.style.display = "block";
				exp_el.parentNode.getElementsByTagName('img')[0].src = "http://www.gigasiste.lt/eshop/images/minus.gif";
			}
		}
		
		var li = document.getElementById('categories').getElementsByTagName('li');
		for (i=0; i<li.length; i++) {
			if ((i == 0) || (i == (li.length-1))) li[i].style.margin = "0";			
			var is_sub = (li[i].getElementsByTagName('li').length > 0);	
			var li_img = li[i].getElementsByTagName('img')[0];
			if ( is_sub ) {
				$(li_img).click(function() {
					var ptg = this.parentNode.parentNode.tagName;
					if (ptg != 'DIV') {
						$('.active').removeClass();
						$(this).addClass('active');
					}
					hideSimilarMenus( this.parentNode, ptg, is_ie );					
					if (this.parentNode.getElementsByTagName('ul')[0].style.display != 'block') {
						var exp_obj = this.parentNode.getElementsByTagName('ul')[0];
						if (is_ie) exp_obj.style.display = "block";	 else $(exp_obj).slideDown("normal");
						this.src = "http://www.gigasiste.lt/eshop/images/minus.gif";
					} else this.src = "http://www.gigasiste.lt/eshop/images/plus.gif";
				});				
			}
		}
		
		//Product Info
		var prod_img = document.getElementById("prod_img");
		if (prod_img != null) {
			if( $(prod_img).width() > $(prod_img).height() ) $(prod_img).width(200);
			else $(prod_img).height(200);
		}
		
		//Add To Cart
		$(".prodaddtocart").click(function() { addToCart(urlparamselect('prod_id')); });
		$(".addtocart").click(function() { addToCart(this.parentNode.parentNode.id); });
		
	}
	
	function hideSimilarMenus( obj, ptg, is_ie ) {		
		var li = obj.getElementsByTagName('li');		
		for (i=0; i<li.length; i++) if (li[i].className == 'active') return;
		if (ptg == 'DIV') $('.active').removeClass();
		
		var subs = obj.parentNode.getElementsByTagName('ul');
		if (is_ie) for (i=0; i<subs.length; i++) subs[i].style.display = "none";
		else for (i=0; i<subs.length; i++) $(subs[i]).slideUp();
		
		var images = obj.parentNode.getElementsByTagName('img');
		for (i=0; i<images.length; i++) images[i].src = "http://www.gigasiste.lt/eshop/images/plus.gif";		
		
	}
	
// Cart Functions
	
	function loadcart ( div_id, req ) {
		document.getElementById(div_id).innerHTML = '<div>Kraunasi... <img src="http://www.gigasiste.lt/eshop/images/cart_load.gif" /></div>';
		$("#"+div_id).load("http://www.gigasiste.lt/eshop/index.php?"+req, function(response, status, xhr) {
			if (status == "error") { var msg = "Sorry but there was an error: "; $("#"+div_id).html(msg + xhr.status + " " + xhr.statusText); }
		} );
	}
	
	function updateproduct( prod_id ) {
		var new_amount = document.getElementById("prod-" + prod_id + "-amount").value;
		var subm = new Array();		
		subm[0] = new Array("cartfunc", 'updateprod');
		subm[1] = new Array("prodid", prod_id);
		subm[2] = new Array("amount", new_amount);		
		submitPost ( 'http://www.gigasiste.lt/eshop/index.php?page_id=101', subm );	
	}
	
	function deleteproduct( prod_id ) {
		var subm = new Array();		
		subm[0] = new Array("cartfunc", 'deleteprod');
		subm[1] = new Array("prodid", prod_id);	
		submitPost ( 'http://www.gigasiste.lt/eshop/index.php?page_id=101', subm );
	}
	
	function addToCart( add_prod_id ) { loadcart( "cart", "cartfunc=addtocart&prodid=" + add_prod_id); }
	
	function emptycart () { loadcart("cart", "cartfunc=emptycart"); }
	
// Additional Functions

	function urlparamselect ( req_name ) {
		var result = window.location.search.match( new RegExp(req_name + "=((\\d+)(,(\\d+))*)", "i") );
		if (result != null) result = RegExp.$1.split(',');
		return result;
	}
	
	function urllastparamselect () {
		var result = window.location.href.match( new RegExp("((\\d+)(,(\\d+))*)" + ".html", "i") );
		if (result != null) return RegExp.$1.split(',');
		else return 0;
	}

	function getCookie (Name) { 
		var ret = new RegExp(Name+"=[^;]+", "i");
		if (document.cookie.match(ret)) return document.cookie.match(ret)[0].split("=")[1];
		return null;
	}
	
	function setCookie(name, value) { document.cookie = name + "=" + value + "; path=/"; }
	
	function createElement(type, father_obj, id, class_name) {		
		var newel = document.createElement( type );
		newel.setAttribute('id', id);
		newel.setAttribute('class', class_name);
		father_obj.appendChild(newel);
		return newel;
	}
	
	function getObjAbsolutePosition( obj, do_alert ) {
		var topValue=0, leftValue=0;
		while (obj) {
			leftValue += obj.offsetLeft;
			topValue += obj.offsetTop;
			obj = obj.offsetParent;
		}
		if (do_alert) alert("Left: " + leftValue + ", Top:" + topValue);
		else {
			var ret = new Array();
			ret['left'] = leftValue; ret['top'] = topValue;
			return ret;
		}
	}
	
	function submitPost( action, subm ) {		
		var myForm = document.createElement("form"); myForm.method = "post"; myForm.action = action;		
		for (i=0; i<subm.length; i++) {
			var myInput = document.createElement("input") ;
			myInput.setAttribute("name", subm[i][0]) ;
			myInput.setAttribute("value", subm[i][1]);
			myForm.appendChild(myInput);
		}
		document.body.appendChild(myForm); myForm.submit(); document.body.removeChild(myForm);		
	}
