valueToSelect = 2;
var myheight=0;
            
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}			
			
function Left(str, n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
        output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

var button;

function Draai_StopFlashMovie()
{
    //var flashMovie=getFlashMovieObject("myFlashMovie");
    //flashMovie.StopPlay();
	button.dom.src = 'http://www.goedkoop.nl/backup/Searchfield_GO.jpg';
}

function Draai_PlayFlashMovie()
{
    //var flashMovie=getFlashMovieObject("myFlashMovie");
    //flashMovie.Play();
    //embed.nativeProperty.anotherNativeMethod();
	button.dom.src = 'http://www.goedkoop.nl/backup/GO_animated.gif';
}

function doAjaxX()
{
	//alert("hello world");
	//return
	//NS_Goedkoop.doAjax();
	NS_Goedkoop.doAjax();
}

            Ext.namespace('NS_Goedkoop');
            //Ext.useShims = true;
            Ext.onReady(function() 
            {
                
				
				//slideToggle(Ext.get('My-Div'));
				function slideToggle(e)
				{
					var myelement = Ext.get('panel_searchinfo');
					//myelement.setVisibilityMode(Ext.Element.DISPLAY);
					//myelement.hide();
					//console.log('pop');
					myelement.update('informatie....<br>informatie....<br>informatie....');
				}
				
				
				
				
				
				//Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
                var win;
                var mystr;
                mystr = '';
                var clickedonwindow = false;
                var mypop=false;
                
                Ext.get('win_zoekcategorieen').on('click', function() {
                    //...
                    if (!mypop)
                    {
                        clickedonwindow = true;
                    }
                })

                button = Ext.get('show-btn');

                button.on('click', function(){
                    if (!mypop)
                    {
                        //mypop = true;
                        //doAjax();
						NS_Goedkoop.doAjax();
                    }
                });
                
                var buttonShowBekeken = Ext.get('showbekeken');

                buttonShowBekeken.on('click', function(){
                    if (!mypop)
                    {
                        mypop = true;
                        doAjax_ShowBekeken();
                    }
					//slideToggle(Ext.get('panel_searchinfo'));
                }); 
                
                var buttonShowGezocht = Ext.get('showgezocht');

                buttonShowGezocht.on('click', function(){
                    if (!mypop)
                    {
                        mypop = true;
                        doAjax_ShowGezocht();
                    }
                });
                
                var ds = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                    url: 'http://www.goedkoop.nl/gk_search_controller.php?m=zoekcatsoptitel'
                    }),
                    reader: new Ext.data.JsonReader({
                        root: 'topics',
                        totalProperty: 'totalCount',
                        id: 'post_id'
                    }, [
                        {name: 'title', mapping: 'topic_title'},
                        {name: 'topicId', mapping: 'topic_id'},
                        {name: 'author', mapping: 'author'},
                        {name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp'},
                        {name: 'excerpt', mapping: 'post_text'},
                        {name: 'categorie', mapping: 'categorie'},
                        {name: 'subcategorie', mapping: 'subcategorie'},
                        {name: 'genre', mapping: 'genre'}
                        ])
                });

                // Custom rendering Template
                var resultTpl = new Ext.XTemplate(
                    '<tpl for="."><div class="search-item">',
                        '{author}',

                    '</div></tpl>'
                );
                
                var dsLiveSearchCatCombo = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                    url: 'http://www.goedkoop.nl/gk_search_controller.php?m=zoekcatsoptitel'
                    }),
                    reader: new Ext.data.JsonReader({
                        root: 'categories',
                        totalProperty: 'totalCount'
                    }, [
                        {name: 'catpath', mapping: 'FoundPath'},
                        {name: 'level', mapping: 'FoundLevel'},
                        {name: 'displaycatname', mapping: 'FoundCat'}
                        ])
                });
                
                
				var tplLiveSearchCatCombo = new Ext.XTemplate(
                    '<tpl for="."><div class="search-item" style="margin-bottom:3px; margin-top:3px; margin-left:3px; margin-right:3px;">',
                        '{displaycatname}',

                    '</div></tpl>'
                );
				
				/*
				var tplLiveSearchCatCombo = new Ext.XTemplate(
					'<tpl for="."><div class="search-item" style="color:#666666; font-style:normal; line-height:15px; margin-bottom:3px; margin-top:3px; margin-left:3px; margin-right:3px;">',
					'{displaycatname}',
					'</tpl>'
				);
				*/
				
                var search = new Ext.form.ComboBox({
                    store: dsLiveSearchCatCombo,//ds,
                    displayField:'title',
                    typeAhead: false,
                    loadingText: 'Zoeken naar categorieen...',
                    width: 257,
                    //minChars:3,
                    //pageSize:50,
                    //triggerAction: 'all',
                    selectOnFocus: true,
                    emptyText: 'Wat zoekt u Goedkoop?', 
                    hideTrigger:true,
                    tpl: tplLiveSearchCatCombo,//resultTpl,
                    applyTo: 'search',
                    itemSelector: 'div.search-item',
                    //shim: true,
					/*
                    onSelect: function(record){ // override default onSelect to do redirect
                        var retCatPath = '';
                        var NavigatieCatPath = 'winkels';
                        var _displaypage = '';
                        retCatPath = retCatPath + '&' + 'allcatpage='+view_allcat;
                        retCatPath = retCatPath + '&' + 'catpage='+view_cat;
                        retCatPath = retCatPath + '&' + 'subcatpage='+view_subcat;
                        retCatPath = retCatPath + '&' + 'genrepage='+view_genre;
                        retCatPath = retCatPath + '&' + 'g2page='+view_g2;
                        retCatPath = retCatPath + '&' + 'prodpage='+view_produkt;
                        if (record.data.level > 0)
                        {
                            NavigatieCatPath = NavigatieCatPath+'|'+record.data.catpath;
                            _displaypage = view_allcat;
                        }
                        if (record.data.level==1)
                        {
                            _displaypage = view_cat;
                        }
                        if (record.data.level==2)
                        {
                            _displaypage = view_subcat;
                        }
                        if (record.data.level==3)
                        {
                            _displaypage = view_genre;
                        }
                        if (record.data.level==4)
                        {
                            _displaypage = view_g2;
                        }
						*/
                        //_namecatalogus = '';
                        //_namecat = record.data.categorie;
                        //_namesubcat = record.data.subcategorie;
                        //_namegenre = record.data.genre;
                        
						//window.location =
                        //    String.format('http://www.goedkoop.nl/'+name_shopname+'/'+view_genre+'/shopsearchresults/'+NavigatieCatPath+'/-1/1/10/*/?goedkoopsid='+name_gksid+retCatPath);
                    //},
					//
                    listeners:{
                        specialkey:function(f,o){
                            if(o.getKey()==13){
                                NS_Goedkoop.doAjax();
                            }
                        }
                    }
                });
         
var search2 = new Ext.form.ComboBox({
		store: dsLiveSearchCatCombo,//ds,
		displayField:'title',
		typeAhead: false,
		loadingText: 'Categorieen zoeken ...',
		width: 262,
		minChars:3,
		//pageSize:50,
		//triggerAction: 'all',
		selectOnFocus: true,
		emptyText: 'Welke categorie zoekt u?', 
		hideTrigger:true,
		tpl: tplLiveSearchCatCombo,//resultTpl,
		applyTo: 'searchcategories',
		itemSelector: 'div.search-item',
		//shim: true,

		onSelect: function(record){ // override default onSelect to do redirect
			var retCatPath = '';
            var NavigatieCatPath = 'winkels';
            var _displaypage = '';
            retCatPath = retCatPath + '&' + 'allcatpage='+view_allcat;
            retCatPath = retCatPath + '&' + 'catpage='+view_cat;
            retCatPath = retCatPath + '&' + 'subcatpage='+view_subcat;
            retCatPath = retCatPath + '&' + 'genrepage='+view_genre;
            retCatPath = retCatPath + '&' + 'g2page='+view_g2;
            retCatPath = retCatPath + '&' + 'prodpage='+view_produkt;
            if (record.data.level > 0)
			{
				NavigatieCatPath = NavigatieCatPath+'|'+record.data.catpath;
				_displaypage = view_allcat;
			}
			if (record.data.level==1)
			{
				_displaypage = view_cat;
			}
			if (record.data.level==2)
			{
				_displaypage = view_subcat;
			}
			if (record.data.level==3)
			{
				_displaypage = view_genre;
			}
			if (record.data.level==4)
			{
				_displaypage = view_g2;
			}
			//_namecatalogus = '';
			//_namecat = record.data.categorie;
			//_namesubcat = record.data.subcategorie;
			//_namegenre = record.data.genre;
			window.location = String.format('http://www.goedkoop.nl/'+name_shopname+'/'+_displaypage+'/shopsearchresults/'+NavigatieCatPath+'/-1/1/10/*/?goedkoopsid='+name_gksid+retCatPath);
		},
		listeners:{
			specialkey:function(f,o){
				if(o.getKey()==13){
					doAjax();
				}
			}
		}
	});
	

	search2.on('expand', function( comboBox ){
		comboBox.list.setWidth( 'auto' );
		comboBox.innerList.setWidth( 'auto' );
		}, 
		this, 
		{ single: true }
	);

         
                //function doAjax() {
				NS_Goedkoop.doAjax = function() {
                        //Draai_PlayFlashMovie();
						
						var mysearchstr = search.getRawValue();
                        //alert(mysearchstr);
                        if ((mysearchstr.toLowerCase()!='') && (mysearchstr.toLowerCase()!='zoek uw product'))
                        {
                        Draai_PlayFlashMovie();
                        mystr = '';
                        var retCatPath = '';
                        
                        retCatPath = retCatPath + '&allcatpage='+view_allcat;
                        retCatPath = retCatPath + '&catpage='+view_cat;
                        retCatPath = retCatPath + '&subcatpage='+view_subcat;
                        retCatPath = retCatPath + '&genrepage='+view_genre;
                        retCatPath = retCatPath + '&g2page='+view_g2;
                        retCatPath = retCatPath + '&prodpage='+view_produkt;
                        retCatPath = retCatPath + '&shopname='+name_shopname;
                        
						var Lzoekphrase=search.getRawValue();
						Lzoekphrase=Lzoekphrase.trim();
						Lzoekphrase=URLEncode(Lzoekphrase);
						
                        Ext.Ajax.request({
                            url : String.format('http://www.goedkoop.nl/gk_search_controller.php?m=zoekcatsoptitel&goedkoopsid='+name_gksid+retCatPath) , 
                            //url : 'http://www.goedkoop.nl/gk_search_controller.php?m=gkzoekplus&goedkoopsid='+name_gksid+retCatPath,
                            //params : { pzoekdit : search.getRawValue() },
							params : { pzoekdit : Lzoekphrase },
                            method: 'GET',
                            success: function ( result, request) { 
                                //Ext.fly('win_zoekcategorieen').update(result.responseText);
                                //Ext.MessageBox.alert('Success', 'Data return from the server: '+ result.responseText); 
                                mystr = result.responseText;

								var s = new String(mystr);
								// use it like this
								s=s.trim();								
								var myRegExp = /http/;								
								var matchPos1 = s.search(myRegExp);
                                //
								//var leftpart="";
                                //leftpart = Left(mystr, 10);
                                //if (leftpart=="http://www")
								if (matchPos1 == 0)
                                {
                                    //alert(mystr);
                                    window.location = mystr;
                                }
                                else
                                {
                                // create the window on the first click and reuse on subsequent clicks
                                    if(!win){
                                        win = new Ext.Window({
                                            el:'win_zoekcategorieen',
                                            layout:'fit',
                                            //width:1000,
                                            //height:500,
                                            closeAction:'hide',
                                            plain: true,
                                            frame:false,
                                            shadow:true,
                                            shadowOffset: 5,
                                            //autoScroll: true,
                                            resizable: false,
                                            //border:true,
                                            //modal: false,
                                            autoHeight: true,
                                            closable: false,
                                            //autoWidth: true,
                                            //title: 'zoeken',
                                            //center: true,
                                            animShow: function(){
                                                //this.y = 240;
                                                
                                                this.el.slideIn('t', {duration: 0, callback: function(){
                                                    
                                                    this.afterShow(true);
                                                }, scope: this});
                                                
                                            },
                                            animHide: function(){
                                                this.el.disableShadow();
                                                this.el.slideOut('t', {duration: 0, callback: function(){
                                                    this.el.hide();
                                                    this.afterHide();
                                                    Ext.EventManager.un(document, 'click', doit, this);
                                                    mypop = false;
                                                }, scope: this});
                                            }
                                            
                                        });
                                        
                                        Ext.get('win_zoekcategorieen').on('click', function() {
                                            clickedonwindow = true;
                                        })                     
                                    }
                                    
                                    //win.y = 240;
                                    //win.x = 335;
                                    mypop = true;
                                    
                                    win.render();
                                    
                                    win.body.update(mystr);
                                    win.center();
                                    //win.y = 238;
									win.y = 133;
                                    win.render();
                                    win.show(Ext.getBody());

                                    
                                    Ext.EventManager.on(document, 'click', doit, this);
                                    
                                    Ext.get('closewinlink').on('click', function() {
                                        //...
                                        //clickedonwindow = true;
                                        doit();
                                    })
                                }
								Draai_StopFlashMovie();
                                
                            },
                            failure: function ( result, request) { 
                                Draai_StopFlashMovie();
								Ext.MessageBox.alert('Failed', result.responseText); 
                            } 
                        });
                        
                        }
                    }
                 
                    //var button = new Ext.Button('subButton', {
                    //    applyTo: 'subButton', 
                    //    text: 'Zoek categorieen',
                    //    handler: doAjax
                    //});
                
                   //function doit() {
                   //     win.hide();
                   //}
                
                
                function doAjax_ShowBekeken() {
                        mystr = '';
                        Ext.Ajax.request({
                            url : 'http://www.goedkoop.nl/gk_search_controller.php?m=getlistbekekenprodukten&goedkoopsid='+name_gksid , 
                            //params : { goedkoopsid : name_gksid },
                            method: 'GET',
                            success: function ( result, request) { 
                                //Ext.fly('win_zoekcategorieen').update(result.responseText);
                                
                                //Ext.MessageBox.alert('Success', 'Data return from the server: '+ result.responseText); 
                                mystr = result.responseText;
                                // create the window on the first click and reuse on subsequent clicks
                                    if(!win){
                                        win = new Ext.Window({
                                            el:'win_zoekcategorieen',
                                            layout:'fit',
                                            //width:460,
                                            //height:500,
                                            closeAction:'hide',
                                            plain: true,
                                            frame:false,
                                            shadow:true,
                                            shadowOffset: 5,
                                            //autoScroll: true,
                                            resizable: false,
                                            //border:true,
                                            //modal: false,
                                            autoHeight: true,
                                            closable: false,
                                            //autoWidth: true,
                                            //title: 'zoeken',
                                            //center: true,
                                            animShow: function(){
                                                
                                                this.el.slideIn('t', {duration: 0, callback: function(){
                                                    
                                                    this.afterShow(true);
                                                }, scope: this});
                                                //this.y = 150;
                                            },
                                            animHide: function(){
                                                this.el.disableShadow();
                                                this.el.slideOut('t', {duration: 0, callback: function(){
                                                    this.el.hide();
                                                    this.afterHide();
                                                    Ext.EventManager.un(document, 'click', doit, this);
                                                    mypop = false;
                                                }, scope: this});
                                            }
                                            
                                        });
                                        Ext.get('win_zoekcategorieen').on('click', function() {
                                            clickedonwindow = true;
                                        })                        
                                    }
                                    //win.y = 240;
                                    //win.x = 260;
                                    
									
									//
									
                                    win.render();
                                    
                                    win.body.update(mystr);
                                    win.center();
                                    //win.y = 238;
									win.y = 133;
                                    win.render();
                                    win.show(Ext.getBody());
                                    
                                    //win.show(Ext.getBody());
                                    //win.body.update(mystr);
                                    Ext.EventManager.on(document, 'click', doit, this);
                                    
                                    Ext.get('closewinlink').on('click', function() {
                                        //...
                                        //clickedonwindow = true;
                                        doit();
                                    })
                                    
                                
                            },
                            failure: function ( result, request) { 
                                Ext.MessageBox.alert('Failed', result.responseText); 
                            } 
                        });
                    }
                    
                    function doAjax_ShowGezocht() {
                        mystr = '';
                        Ext.Ajax.request({
                            url : 'http://www.goedkoop.nl/gk_search_controller.php?m=getlistgezocht&goedkoopsid='+name_gksid , 
                            //params : { goedkoopsid : name_gksid },
                            method: 'GET',
                            success: function ( result, request) { 
                                //Ext.fly('win_zoekcategorieen').update(result.responseText);
                                
                                //Ext.MessageBox.alert('Success', 'Data return from the server: '+ result.responseText); 
                                mystr = result.responseText;
                                // create the window on the first click and reuse on subsequent clicks
                                    if(!win){
                                        win = new Ext.Window({
                                            el:'win_zoekcategorieen',
                                            layout:'fit',
                                            //width:460,
                                            //height:500,
                                            closeAction:'hide',
                                            plain: true,
                                            frame:false,
                                            shadow:true,
                                            shadowOffset: 5,
                                            //autoScroll: true,
                                            resizable: false,
                                            //border:true,
                                            //modal: false,
                                            autoHeight: true,
                                            closable: false,
                                            //autoWidth: true,
                                            //title: 'zoeken',
                                            //center: true,
                                            animShow: function(){
                                                
                                                this.el.slideIn('t', {duration: 0, callback: function(){
                                                    
                                                    this.afterShow(true);
                                                }, scope: this});
                                                //this.y = 150;
                                            },
                                            animHide: function(){
                                                this.el.disableShadow();
                                                this.el.slideOut('t', {duration: 0, callback: function(){
                                                    this.el.hide();
                                                    this.afterHide();
                                                    Ext.EventManager.un(document, 'click', doit, this);
                                                    mypop = false;
                                                }, scope: this});
                                            }
                                            
                                        });
                                        Ext.get('win_zoekcategorieen').on('click', function() {
                                            clickedonwindow = true;
                                        })                        
                                    }
                                    //win.y = 240;
                                    //win.x = 260;
                                    
                                    win.render();
                                    
                                    win.body.update(mystr);
                                    win.center();
                                    //win.y = 238;
									win.y = 133;
                                    win.render();
                                    win.show(Ext.getBody());
                                    
                                    //win.show(Ext.getBody());
                                    //win.body.update(mystr);
                                    Ext.EventManager.on(document, 'click', doit, this);
                                    
                                    Ext.get('closewinlink').on('click', function() {
                                        //...
                                        //clickedonwindow = true;
                                        doit();
                                    })
                                    
                                
                            },
                            failure: function ( result, request) { 
                                Ext.MessageBox.alert('Failed', result.responseText); 
                            } 
                        });
                    }
                 
                    //var button = new Ext.Button('subButton', {
                    //    applyTo: 'subButton', 
                    //    text: 'Zoek categorieen',
                    //    handler: doAjax
                    //});
                
                   function doit() {
                        if (!clickedonwindow)
                        {
                            win.hide();
                        }
                        else
                        {
                            clickedonwindow=false;
                        }
                   }
                   
                  // doAjaxDealOfTheDay();
				  
				  
				  
				  
				  // basic tabs 1, built from existing content
	var tabs = new Ext.TabPanel(
	{
		renderTo: 'tabs1',
		width:699,
		activeTab: 3,
		plain:true,
		border:false,
		frame:false,
		defaults:
		{
			autoHeight: true,
			preventBodyReset: true
		},
		items:
		[
			{contentEl:'tabkortingnieuws', title: 'Vandaag GOEDKOOP', border:true},
			{contentEl:'tabkortingscodes', title: 'Kortingscodes', border:true},
			{contentEl:'tabpopulairmerken', title: 'Merken', border:true},
			{contentEl:'tabovergoedkoop', title: 'Over GOEDKOOP', border:true}
			//{contentEl:'tabpopulairprodukten', title: 'Overzicht', border:true},
			
			//{contentEl:'tabkortingnieuws', title: 'Superdeals', border:true},
			//,{contentEl:'taballes', title: 'Alles', border:true}
		]
	});

			var dsWinkels = new Ext.data.Store(
            {
				proxy : new Ext.data.HttpProxy({
					url: 'http://www.goedkoop.nl/gallerie_controller.php?m=allshopshome'
				}),       
				reader: new Ext.data.JsonReader({
                    root: 'shops',
					totalProperty: 'totalCount',
                    id: 'tagidentifier'
                }, [
                    {name: 'tagidentifier'},
                    {name: 'tag'},
        			{name: 'count'}
                ]),
                //id: 'tagidentifier',
                remoteSort: false
			});
			
			
			var cloud = new Ext.ux.TagCloud({
                store: dsWinkels, 
                displayField: 'tag', 
                weightField: 'count', 
                displayWeight: false
                }
        	);

            cloud.on('tagselect', function(cloud, record, index){
                alert('Winkel "'+record.get('tag')+'"!');
            });
        	cloud.render('cloud');
			
        	dsWinkels.load();
			
			
			
			var dsBrands = new Ext.data.Store(
            {
				proxy : new Ext.data.HttpProxy({
					url: 'http://www.goedkoop.nl/gallerie_controller.php?m=allbrandshome'
				}),       
				reader: new Ext.data.JsonReader({
                    root: 'brands',
					totalProperty: 'totalCount',
                    id: 'tagidentifier'
                }, [
                    {name: 'tagidentifier'},
                    {name: 'tag'},
        			{name: 'count'}
                ]),
                //id: 'tagidentifier',
                remoteSort: false
			});
			
			
			var cloudbrands = new Ext.ux.TagCloud({
                store: dsBrands, 
                displayField: 'tag', 
                weightField: 'count', 
                displayWeight: false
                }
        	);

            cloudbrands.on('tagselect', function(cloudbrands, record, index){
                
				var visitorName = " ";
				var myOldString = record.get('tag');
				var myNewString = myOldString.replace("&nbsp;", visitorName);
				var retCatPath = '';
				retCatPath = retCatPath + '&' + 'allcatpage='+view_allcat;
				retCatPath = retCatPath + '&' + 'catpage='+view_cat;
				retCatPath = retCatPath + '&' + 'subcatpage='+view_subcat;
				retCatPath = retCatPath + '&' + 'genrepage='+view_genre;
				retCatPath = retCatPath + '&' + 'g2page='+view_g2;
				retCatPath = retCatPath + '&' + 'prodpage='+view_produkt;
				//alert('Merk: "'+myNewString+'"!');
				
				//window.location = String.format('http://www.goedkoop.nl/'+name_shopname+'/'+view_cat+'/shopsearchresults/winkels/-1/1/10/_td_brand='+myNewString+'/?goedkoopsid='+name_gksid+retCatPath);
				window.location = String.format('http://www.goedkoop.nl/'+myNewString+'/goedkoop.html'+'?goedkoopsid='+name_gksid+retCatPath);
				
            });
        	cloudbrands.render('cloudbrands');
			
        	dsBrands.load();
				  
			
			//setup datastore voor de categorieeen alles
			//setup datastore voor de produkten in de picwall
			var ProduktenStore = new Ext.data.Store(
			{
				proxy : new Ext.data.HttpProxy(
				{
					url: 'http://www.goedkoop.nl/gallerie_controller.php?start=0&limit=10'
				}),                   
				reader: new Ext.data.JsonReader(
				{
					root: 'images',
					totalProperty: 'totalCount',
					id: 'uid'
				}, 
				[
					{name: 'uid'},
					{name: 'filename'},
					{name: 'name'},
					{name: 'description'},
					{name: 'price'},
					{name: 'merknaam'}
					,{name: 'gkid'}
				])
			});
			
			//setup html template voor de weergave van de picwall items
			var imageTemplate = new Ext.XTemplate(
				'<table width="100%" border="0" cellspacing="0" cellpadding="0" id="{image_id}">',
					'<tr>',
						'<tpl for=".">',
							'<td>',
								'<table width="161" height="286" border="0" cellpadding="0" cellspacing="0">',
									'<tr>',
										'<td width="161"  class="picwallTop"></td>',
									'</tr>',
									'<tr>',
										'<td height="255" class="picwallMid">',
											'<table width="160" border="0" cellspacing="0" cellpadding="0">',
												'<tr>',
													'<td height="167">',
														'<center>',
															'<img src="{filename}" alt="{name}" class="PicWallPic" />',
														'</center>',
													'</td>',
												'</tr>',
												'<tr>',
													'<td height="31" class="PicWallP_titles"><div align="left">{name}</div></td>',
												'</tr>',
												'<tr>',
													'<td class="PicWallP_brand"><div align="left">{merknaam}</div></td>',
												'</tr>',
												'<tr>',
													'<td height="31" class="PRIJS_small"><div align="left">&euro;&nbsp;{price}</div></td>',
												'</tr>',
												'<tr>',
													'<td height="31" align="left"><a href="http://www.goedkoop.nl/'+name_shopname+'/'+view_produkt+'/gk_shopsearchresultsitem/'+'{[this.generateCategoriePath()]}'+'/'+use_zoekwoord+'/1/10/'+use_searchextraparams+'/{gkid}/?goedkoopsid='+name_gksid+'{[this.generateExtraUrlParams()]}'+'" target="_self"><img src="http://www.goedkoop.nl/site/images/CSS/btn-bekijk.jpg" alt="{name}" class="PicWallP_brand" /></a></td>',
												'</tr>',
											'</table>',
											'',
										'</td>',
									'</tr>',
									'<tr>',
										'<td class="picwallBot">&nbsp;</td>',
									'</tr>',
								'</table>',
							'</td>',
						'{[xindex % 4 === 0 ? "</tr><tr>" : ""]}',
					'</tpl>',
				'</tr>',
			'</table>',
			{
				generateCategoriePath : function() {
					var retCatPath = name_catalogus;
					
					if (use_catid!='-1')
					{
						retCatPath = retCatPath + '|'+name_categorie;
					}
					if (use_subcatid!='-1')
					{
						retCatPath = retCatPath + '|'+name_subcategorie;
					}
					if (use_genreid!='-1')
					{
						retCatPath = retCatPath + '|'+name_genre;
					}
					if (use_g2id!='-1')
					{
						retCatPath = retCatPath + '|'+name_g2;
					}
					return retCatPath;
				},
				generateExtraUrlParams : function() {
					var retExtraUrlParams = '';
					retExtraUrlParams = retExtraUrlParams + '&' + 'allcatpage='+view_allcat;
					retExtraUrlParams = retExtraUrlParams + '&' + 'catpage='+view_cat;
					retExtraUrlParams = retExtraUrlParams + '&' + 'subcatpage='+view_subcat;
					retExtraUrlParams = retExtraUrlParams + '&' + 'genrepage='+view_genre;
					retExtraUrlParams = retExtraUrlParams + '&' + 'g2page='+view_g2;
					retExtraUrlParams = retExtraUrlParams + '&' + 'prodpage='+view_produkt;
					return retExtraUrlParams;
				}
			});
									   
			//loading visual widget voor inladen afbeeldingen
			var mask = new Ext.LoadMask('view', {store: ProduktenStore, msg: '<b>goedkoop.nl</b><br>Even geduld aub'});
						
			//Setup een dataview component voor weergave plaatjes
			NS_Goedkoop.imageView = new Ext.DataView(
			{
				id: 'imageView',
				renderTo: 'view',
				store: ProduktenStore,
				loadingText: 'Ophalen produkten...',
				tpl: imageTemplate,
				itemSelector:'img.PicWallPic',
				overClass: 'over',
				selectedClass: 'selected',
				singleSelect: true,
				emptyText: 'Geen produkten gevonden.',
				
				listeners: {
				selectionchange: {
					fn: function(dataview, nodes) {
						var l = nodes.length;
						var s = l != 1 ? 's' : '';

						if (dataview.getSelectionCount() > 0) {
							var name = dataview.getSelectedRecords()[0].get('filename');
							var fotonaam = dataview.getSelectedRecords()[0].get('name');
							var fotodescription = dataview.getSelectedRecords()[0].get('description');
							//var fotouid = dataview.getSelectedRecords()[0].get('uid');
							var fotouid = dataview.getSelectedRecords()[0].get('gkid');

							var retCatPath = name_catalogus;
							if (use_catid!='-1')
							{
								retCatPath = retCatPath + '|'+name_categorie;
							}
							if (use_subcatid!='-1')
							{
								retCatPath = retCatPath + '|'+name_subcategorie;
							}
							if (use_genreid!='-1')
							{
								retCatPath = retCatPath + '|'+name_genre;
							}
							if (use_g2id!='-1')
							{
								retCatPath = retCatPath + '|'+name_g2;
							}
							
							var retExtraUrlParams = '';
							retExtraUrlParams = retExtraUrlParams + '&' + 'allcatpage='+view_allcat;
							retExtraUrlParams = retExtraUrlParams + '&' + 'catpage='+view_cat;
							retExtraUrlParams = retExtraUrlParams + '&' + 'subcatpage='+view_subcat;
							retExtraUrlParams = retExtraUrlParams + '&' + 'genrepage='+view_genre;
							retExtraUrlParams = retExtraUrlParams + '&' + 'g2page='+view_g2;
							retExtraUrlParams = retExtraUrlParams + '&' + 'prodpage='+view_produkt;
							
							//window.location.href = 'http://www.goedkoop.nl/'+name_shopname+'/'+view_produkt+'/shopsearchresultsitem/'+retCatPath+'/'+use_zoekwoord+'/1/10/'+use_searchextraparams+'/'+fotouid+'/?goedkoopsid='+name_gksid+retExtraUrlParams;
							  window.location.href = 'http://www.goedkoop.nl/'+name_shopname+'/'+view_produkt+'/gk_shopsearchresultsitem/'+retCatPath+'/'+use_zoekwoord+'/1/10/'+use_searchextraparams+'/'+fotouid+'/?goedkoopsid='+name_gksid+retExtraUrlParams;
							
						}
					}                                                                                                                                                  
				}}
			}); 

			var aantalrecordstonen = 40;
		   
			// simple array store ('The Model')
			var AantalShowRowsStore = new Ext.data.SimpleStore({
				fields: ['showcountid', 'showcounttext'],
				data : [
						[40,'10 rijen'],
						[60,'15 rijen'],
						[80,'20 rijen'],
						[120,'30 rijen'],
						[200,'50 rijen']
						]
			});
			
			//combobox voor toon N aantal rijen
			NS_Goedkoop.cboAantalShowRows = new Ext.form.ComboBox(
			{
				store: AantalShowRowsStore,
				displayField:'showcounttext',
				valueField: 'showcountid' ,
				width: 150,
				typeAhead: true,
				mode: 'local',
				triggerAction: 'all',
				emptyText:'Aantal tonen...',
				selectOnFocus:true,
				//renderTo: 'aantalshowrowscombo',
				forceSelection: true
			});
			
			//als er een aantalrijen is geklikt in de combo
			NS_Goedkoop.cboAantalShowRows.on('select', function() 
			{
				aantalrecordstonen = NS_Goedkoop.cboAantalShowRows.getValue();
				//NS_Goedkoop.imageView.store.proxy.conn.url = 'http://www.goedkoop.nl/gallerie_controller.php?catid='+use_catid+'&subcatid='+use_subcatid+'&genreid='+use_genreid+'&g2id='+use_g2id+'&query='+use_zoekwoord;
				//NS_Goedkoop.imageView.store.load({params:{start:0, limit:aantalrecordstonen}});
				//var mytestmin = Test.zone2.getSlider('start2').value.toFixed(0);
				//var mytestmax = Test.zone2.getSlider('middle2').value.toFixed(0);
				var mysort = 'PRICE_UP';
				//var mybrands = URLEncode(lc.getValue());
				
				
				
				/*
				switch(sortflag_price)
				{
				case 0:
				  mysort = 'PRICE_UP';
				  break;
				case 1:
				  mysort = 'PRICE_UP';
				  break;
				}
				
				*/
				
				
				NS_Goedkoop.imageView.store.proxy.conn.url = 'http://www.goedkoop.nl/gallerie_controller.php?catid='+use_catid+'&subcatid='+use_subcatid+'&genreid='+use_genreid+'&g2id='+use_g2id+'&query='+use_zoekwoord+'&sortfield='+mysort;
				//NS_Goedkoop.imageView.store.proxy.conn.url = 'http://www.goedkoop.nl/gallerie_controller.php?catid='+use_catid+'&subcatid='+use_subcatid+'&genreid='+use_genreid+'&g2id='+use_g2id+'&query='+use_zoekwoord+'&sortfield='+mysort+'&minprijs='+mytestmin+'&maxprijs='+mytestmax;
				NS_Goedkoop.imageView.store.load({params:{start:0, limit:aantalrecordstonen}});    
				paging.pageSize = aantalrecordstonen;
			});

			 //paging toolbar
			var paging = new Ext.PagingToolbar(
			{
				renderTo: 'paging_toolbar',
				store: ProduktenStore,
				pageSize: aantalrecordstonen,
				items: [
						  '->',
						  NS_Goedkoop.cboAantalShowRows
						]
			});
			
			
			Ext.get('pgPreviousButton').on('click', function() {
				//paging.movePrevious();
				//if ( (paging.cursor-paging.pageSize)>0 )
				//{
					paging.doLoad(Math.max(0, paging.cursor-paging.pageSize));
				//}
			})
			
			Ext.get('pgNextButton').on('click', function() {
				//paging.moveNext();
				var mytotalpages = paging.store.getTotalCount();
				
				if ( mytotalpages > (paging.cursor+paging.pageSize) )
				{
					paging.doLoad(paging.cursor+paging.pageSize);
				}
			})
			
			
			//Start de listweergave met startparameters
			NS_Goedkoop.imageView.store.proxy.conn.url = 'http://www.goedkoop.nl/gallerie_controller.php?catid='+use_catid+'&subcatid='+use_subcatid+'&genreid='+use_genreid+'&g2id='+use_g2id+'&query='+use_zoekwoord+ '&filterbrands=' + use_merk_filter2;
			//NS_Goedkoop.imageView.store.load({params:{start:0, limit:aantalrecordstonen}});
			NS_Goedkoop.imageView.store.load({params:{start:0, limit:aantalrecordstonen}});
                   
         });
        
