Event.observe (
		window,
		'load',
		function () {
		    var params='cat_num='+getParameter ( 'cat' );
			new Ajax.Request(
				'./products_vertical.php',
				{
					method: 'get',
					parameters: params,
					onComplete: function (response) {
						(new swapper(response)).inic();
						}
				}
				);
			}
		);


	function swapper (response) {

        oThis=this;
	    this.run=true;		//fut az időzítő vagy sem
		this.from=0;		//honnan
		this.n=4;			//max mennyi
		this.direction=1;	//irány, előre vagy hátra (1/-1)
		this.duration=2.0;  //eltűnés, előtűnés hossza
		this.time=10000;	//idő millisecundunban
		this.good_array=JSON.parse(response.responseText);

		// maximum milyen magas lesz az ajánló
		if (this.good_array.length>=this.n) {
			$('ajanlo').style.height=(630/4)*this.n+73; //+63 az akciós felirat (az is eltűnik ha nincs akciós)
			} else {				$('ajanlo').style.height=(630/4)*this.good_array.length+73; //+63 az akciós felirat (az is eltűnik ha nincs akciós)
				}

		//lesz e váltása a termékeknek
		if (this.good_array.length<=this.n) {			oThis.stop();			}

	}

	swapper.prototype.inic = function () {

				var ajanlo=$('ajanlo');

				if (oThis.n<oThis.good_array.length) {
				var up=Builder.node('div', {style: 'cursor:pointer'},
			    		[
			    		Builder.node('img', {src:'images/_siteimages/uparrow.gif'})
			    		]);
			    ajanlo.appendChild(up);
			    Event.observe (up, 'click', oThis.upArrow.bind(this));
			    }

				for (var i=0; i<oThis.good_array.length; i++) {

				    if (oThis.good_array[i]['kep']=='') {
				    	oThis.good_array[i]['kep']='images/_siteimages/no_image.jpeg';
				    	} else {
				    		oThis.good_array[i]['kep']='images/termekek/'+oThis.good_array[i]['tablanev']+'/th_'+oThis.good_array[i]['kep'];
				    		}
					if (oThis.good_array[i]['leiras']!=='') {
						oThis.good_array[i]['leiras']+='...';
						}

					var element=Builder.node('div', { id: 'product'+i, className: 'product', style: 'display:none;', onMouseOver: "oThis.stop()" },
									[
									Builder.node('div', {style:'background: url(images/_siteimages/topa.gif) no-repeat; height:14px;width:228px' }),
									Builder.node('div', {style:'width:206px; border-left: solid 1px #b1b1b1; border-right: solid 1px #b1b1b1; padding: 0 10px 0 10px;' }, [
										Builder.node('a', { href: 'product.php?id='+oThis.good_array[i]['id']+'&cat='+oThis.good_array[i]['kat_id'], target: '_self'},
											[
											Builder.node('h2', {className: 'red_10',style:'margin-bottom:10px'}, oThis.good_array[i]['tipus']),
											]),
									Builder.node('div', {style: 'height: 75px; width:207px;' },
											[
											Builder.node('div', {style: 'float:left; width:54px; margin-right: 10px; margin-bottom: 5px', align: 'center'},
												[
												Builder.node('a', { href: 'product.php?id='+oThis.good_array[i]['id']+'&cat='+oThis.good_array[i]['kat_id'], target: '_self'},
													[
													Builder.node('img', {src: oThis.good_array[i]['kep'], alt: oThis.good_array[i]['tipus']+' - '+oThis.good_array[i]['megnevezes'], className: 'pic'})
													])
												]),
											Builder.node('div', {style:'margin-bottom: 10px'}, oThis.good_array[i]['leiras']),
											]),
									Builder.node('div', {style:'width:207px;'},
											[
											Builder.node('div', {className:'penz', style:'margin-bottom: 5px'},
												[
												Builder.node('b',
													[
													'Akciós bruttó ár: ', oThis.good_array[i]['brutto_ar'],' Ft'
													])
												]),
											Builder.node('form', { id: 'a'+oThis.good_array[i]['tablanev']+oThis.good_array[i]['id'], action: "cart.php" },
												[
												Builder.node('div', { style: 'float:right'},
													[
													Builder.node('a', { href: 'index.php?cat='+oThis.good_array[i]['kat_id']+'&sort=brutto_arp', target: '_self', style: 'text-decoration: none'}, oThis.good_array[i]['megnevezes'].substring(0,22))
													]),
												Builder.node('input', { type: 'hidden', value: oThis.good_array[i]['id'], name: 'id'}),
												Builder.node('input', { type: 'hidden', value: oThis.good_array[i]['prod_color'],  name: 'prod_color'}),
												Builder.node('input', { type: 'hidden', value: oThis.good_array[i]['kat_id'],  name: 'cat'}),
												Builder.node('input', { type: 'hidden', value: oThis.good_array[i]['tablanev'], name: 'tb'}),
												Builder.node('input', { type: 'hidden', value: oThis.good_array[i]['brutto_ar'], name: 'bar'}),
												Builder.node('input', { type: 'hidden', value: oThis.good_array[i]['netto_ar'], name: 'nar'}),
												Builder.node('input', { onKeyPress: 'return alpha(event,numbers)', style: 'border: 1px solid rgb(0, 0, 0); background-color: rgb(255, 255, 255); color: rgb(0, 0, 0); font-size: 10px; width: 20px; margin-right: 5px;', value: '1', maxlength: '3', name: 'db'}),
												Builder.node('input', { type: 'submit', value: '', style: 'border: medium none ; background: transparent url(buy_icon.gif) repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; width: 56px; height: 15px; cursor: pointer;'})
												])
											])
										]),
									Builder.node('div', {style:'background: url(images/_siteimages/bottom.gif) no-repeat; height:14px;width:228px' })
									]);

					ajanlo.appendChild(element);
				}

				if (oThis.n<oThis.good_array.length) {
				var down=Builder.node('div', {style: 'cursor:pointer;'},
			    		[
			    		Builder.node('img', {src:'images/_siteimages/downarrow.gif'})
			    		]);
				ajanlo.parentNode.insertBefore(down, ajanlo.nextSibling);
			    Event.observe (down, 'click', oThis.downArrow.bind(this));
			    }


				$('ajanlo').style.background='none';
				oThis.show();
        		};


		swapper.prototype.show = function () {
				//növeli, megjeleníti a következő n-t
                oThis.from+=oThis.direction*oThis.n;
                if (oThis.from>=oThis.good_array.length) {
                	oThis.from=oThis.from-oThis.good_array.length;
                	}
                if (oThis.from<0) {
                	oThis.from=oThis.from+oThis.good_array.length-1;
                	}

				var j=oThis.from;
				var nodes=new Array();
                for (var i=0; i<oThis.n; i++) {
                	if (j.abs()>=oThis.good_array.length) {
                		j=0;
                		}

					nodes.push($('product'+j.abs()));
               		j+=oThis.direction*1;
                	}

				Effect.multiple(nodes, Effect.SlideDown);

				if (oThis.run) {
					oThis.t=setTimeout(oThis.hide, oThis.time);
					}
                };


		swapper.prototype.hide = function () {
				//eltünteti az előző n db-ot
				var j=oThis.from;
				var nodes=new Array();
                for (var i=0; i<oThis.n; i++) {
                	if (j.abs()>=oThis.good_array.length) {
                		j=0;
                		}

					nodes.push($('product'+j.abs()));
               		j+=oThis.direction*1;
                	}

      			Effect.multiple(nodes, Effect.DropOut);

				if (oThis.run) {
				oThis.t=setTimeout(oThis.show, oThis.duration*1000+1000);
				}
				};

		swapper.prototype.stop = function () {			oThis.run=false;
			clearTimeout(oThis.t);			};

		swapper.prototype.upArrow = function () {			oThis.stop();
			oThis.hide();
			//előző előtti kezdőértékre állítja a fromot
            oThis.from+=-2*oThis.direction*oThis.n;
            if (oThis.from>=oThis.good_array.length) {
              	oThis.from=oThis.from-oThis.good_array.length;
               	}
            if (oThis.from<0) {
               	oThis.from=oThis.from+oThis.good_array.length-1;
               	}

			oThis.show();
			};

		swapper.prototype.downArrow = function () {
			oThis.stop();
			oThis.hide();
			oThis.show();
			};