$css = "<style>.mousemenu {position:absolute; width:150px; border:2px solid #5f9710; background:#f4ffec; padding:4px} .mousemenu div {padding:2px} .mousemenu a {text-decoration:none; color:#000000}</style>";
document.write($css);

$translates = new Array();
$translates[2] = new Array();
$translates[1] = new Array();
$translates[3] = new Array();
$translates[2][0] = "Nopirkt preci";
$translates[1][0] = "Купить товар";
$translates[3][0] = "Buy";

function mouseover(){

	this.$interval 	= null;
	this.$posX 		= null;
	this.$posY 		= null;
	this.$menu		= null;
	this.$lastItem	= null;

	this.init = function($obj){
		$obj.onmousemove 	= this.start_catch;
		$obj.onmouseout 	= this.stop_catch;
	}

	this.start_catch = function($event){
		if (this != $mouseover.$lastItem){
			$mouseover.hide_menu();
			$mouseover.$lastItem = this;
		}


		$mouseover.stop_catch();
		$mouseover.$interval = window.setInterval("$mouseover.show_menu()", 250);
		if (!$event) var $event = window.event;

		if ($event.pageX || $event.pageY) {
			$mouseover.$posX = $event.pageX;
			$mouseover.$posY = $event.pageY;
		} else if ($event.clientX || $event.clientY) {
			$mouseover.$posX = $event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			$mouseover.$posY = $event.clientY + document.body.scrollTop	+ document.documentElement.scrollTop;
		}
	}

	this.stop_catch = function(){
		window.clearInterval($mouseover.$interval);
	}

	this.show_menu = function($obj){
		if (!$_CFG_admin){
			return;
		}
		
		$product_id = $mouseover.$lastItem.getAttribute("prod_id");
		if (!$_CFG_admin){
			var $string = "<div><img src='images/sm-large.gif' style='vertical-align:middle'  hspace='2' border='0'/><a href=''>Palielināt attēlu</div>";
			$string += "<div><img src='images/sm-compare.gif' style='vertical-align:middle' hspace='5' border='0'/><a href=''>Salidzināt</a></div>";
			$string += "<div><img src='images/sm-basket.gif' style='vertical-align:middle'  hspace='2' border='0'/><a href=''>Ielikt grozā</a></div>";
		} else {
			var $string = $admin.show_menu($product_id);
		}

		var $pX = window.document.body.clientWidth + document.body.scrollLeft;
		var $pY = window.document.body.clientHeight + document.body.scrollTop;

		$mouseover.hide_menu();
		$mouseover.$menu 				= document.createElement("DIV");
		$mouseover.$menu.className		= "mousemenu"
		$mouseover.$menu.innerHTML 		= $string;
		$mouseover.$menu.style.top 		= ($mouseover.$posY + 50) < $pY ? $mouseover.$posY+5+"px" : ($pY - 50) + "px";
		$mouseover.$menu.style.left 	= ($mouseover.$posX + 150) < $pX ? $mouseover.$posX+5+"px" : ($pX - 180) + "px";
		document.body.appendChild($mouseover.$menu);
	}

	this.hide_menu = function(){
		if ($mouseover.$menu){
			$mouseover.$menu.parentNode.removeChild($mouseover.$menu);
			$mouseover.$menu = null;
		}
	}

}
$mouseover = new mouseover();


//======================================================================================



var $currentTD 		= null;
var $currentTR		= null;


var $currentWidth = 0;
var $items_onrow = 0;
function get_sizer(){
	$size 			= document.getElementById("sizer").offsetLeft;
	$currentWidth 	= ($size - 540);
	$items_onrow 	= Math.round($currentWidth / 130);
}

function add_item($image, $title, $price, $link, $id, $vertical, $owner, $instock){
	if (!$currentWidth){
		get_sizer();
	}

	if ($vertical){
		$currentTD = null
	}
	
	if (!$currentTD){
		var $table 	= document.getElementById("products");
		$currentTR 	= $table.insertRow(-1);
		$nextTR 	= $table.insertRow(-1);
	}

	//$src_site = $owner ? $owner+".inteon.lv" : "ec.web-gooroo.com";
	$src_site = "ec.web-gooroo.com";
	
	$classAdd = "";
	if(!$instock){
		$classAdd = " notinstock";
	}
	
	$newTD = $currentTR.insertCell(-1);
	$newTD.id  = "item-"+$id;
	$newTD.innerHTML = '<a href="'+$link+'" onmousemove="$mouseover.init(this)" prod_id="'+$id+'" style="background:url(\'http://'+$src_site+'/images/'+$image+'\') no-repeat center;"></a><div>'+$title+'</div>';
	$newTD.className = "img"+$classAdd;

	$newTD = $nextTR.insertCell(-1);
	$newTD.id = "footer-"+$id;
	$newTD.innerHTML = '<a href="'+$link+'">'+$price+'</a><p><input type="button" class="but" name="" value="'+$translates[$_CFG_language][0]+'" onclick="document.location.href=\''+$_CFG_basket_url+'?tobasket='+$id+'\'"/></p><img src="images/void.gif" width="120" height="1px" border="0"/>';
	$newTD.className = "foot";

	$currentTD ++;
	if ($currentTD == $items_onrow){
		$currentTD = 0;
	}

}

//======================================================================================

function start_filter(){
	var $checkboxes = document.getElementsByTagName("input");
	var $url = new Array();
	$counter = $checkboxes.length;
	for ($x=0; $x < $counter; $x++) {
		if ($checkboxes[$x].name.match("ff")){

			if ($checkboxes[$x].checked){
				$url.push($checkboxes[$x].name+"[]="+encodeURI($checkboxes[$x].value));
			}
		}
	}
	document.getElementById("products-list").innerHTML = '<div style="text-align:center; border:1px solid #bfe3a6; background:#ffffff; padding:150px 10px; margin:10px"><img src="images/loading.gif" border="0"/></div>';
	rpc_get_file("/wbg/modules/components/rpc.products_list.php?"+$url.join("&")+"&p_from="+document.getElementById("p_from").value+"&p_to="+document.getElementById("p_to").value+"&inprod="+document.getElementById("inprod").value, "products-list", 0);
}

function select_numerics($field){
	var $from  = document.getElementById("mffrom["+$field+"]").value;
	var $to  = document.getElementById("mfto["+$field+"]").value;
	var $checkboxes = document.getElementsByTagName("input");
	var $url = new Array();
	$counter = $checkboxes.length;
	for ($x=0; $x < $counter; $x++) {
		if ($checkboxes[$x].name == "ff["+$field+"]"){
			if ($checkboxes[$x].value *1 >= $from && $checkboxes[$x].value *1 <= $to && $checkboxes[$x].disabled == false){
				$checkboxes[$x].checked = true;
			} else {
				$checkboxes[$x].checked = false;
			}
		}
	}
	start_filter();
}

function radio_check($name, $object){
	var $checkboxes = document.getElementsByTagName("input");
	$counter = $checkboxes.length;
	for ($x=0; $x < $counter; $x++) {
		if ($checkboxes[$x].name == "ff["+$name+"]"){
			if ($checkboxes[$x].value != $object.previousSibling.value){
				$checkboxes[$x].checked = false;
			} else {
				$checkboxes[$x].checked = true;
			}
		}
	}	
}

function display_filter(){
	document.getElementById("filter").className = document.getElementById("filter").className == "hidden" ? "visible" : 'hidden';
	$mouseover.hide_menu();
}

function disable_filters(){
	var $checkboxes = document.getElementsByTagName("input");
	$counter = $checkboxes.length;
	for ($x=0; $x < $counter; $x++) {
		if ($checkboxes[$x].name.match("ff") && !$checkboxes[$x].getAttribute("nodis")){
			$checkboxes[$x].disabled = true;
		}
	}
}
function enable_filter($title, $value){
	var $checkboxes = document.getElementsByTagName("input");
	$counter = $checkboxes.length;
	for ($x=0; $x < $counter; $x++) {
		if ($checkboxes[$x].name == "ff["+$title+"]"){
			if ($checkboxes[$x].value == $value){
				$checkboxes[$x].disabled = false;
			}
		}
	}
}
function enable_group($title){
	var $checkboxes = document.getElementsByTagName("input");
	$counter = $checkboxes.length;
	for ($x=0; $x < $counter; $x++) {
		if ($checkboxes[$x].name == "ff["+$title+"]"){
			$checkboxes[$x].disabled = false;
		}
	}
}

function check_filter($title, $value){
	var $checkboxes = document.getElementsByTagName("input");
	$counter = $checkboxes.length;
	for ($x=0; $x < $counter; $x++) {
		if ($checkboxes[$x].name == "ff["+$title+"]"){
			if ($checkboxes[$x].value == $value){
				$checkboxes[$x].checked = true;
			}
		}
	}
}


//======================================================================================


function big_image($image){
	var $newDiv = document.createElement("DIV");
	$newDiv.className= "img_layer";
	$newDiv.innerHTML = '<img src="'+$image+'" border="0" style="cursor:pointer" onclick="close_big_image(this)"/>';
	document.body.appendChild($newDiv);
	return false;
}
function close_big_image($obj){
	$div = $obj.parentNode;
	$div.parentNode.removeChild($div);
}


//======================================================================================

function scroll_to(){

	this.scroll = function($obj_name){
		$item = document.getElementById("item-"+$obj_name);
		if (!$item) {return;}
		$item.style.border = "1px solid red"
		$footer = document.getElementById("footer-"+$obj_name);
		$footer.firstChild.style.background="#f4d0d0"

		$pos = this.findPos($item);
        $winh = window.document.body.clientHeight/2;
        window.scrollTo(0,($pos-$winh));
	}
    this.findPos = function($obj) {
        var $curtop = 0;
        while ($obj.offsetParent) {
                $curtop += $obj.offsetTop
                $obj = $obj.offsetParent;
        }
        return $curtop;
    }
}
$scroll_to = new scroll_to();


