        //
        // change page
        //
        function changePage(index)
        {
            renderPage(data.items, config.pageSize, index, data.listStyle);
            renderPager(index, data.items.length, config.pageSize, config.pagerSize);
        }

        //
        // render playlist grid
        //
        function renderPage(items, size, page)
        {
            var container = $(config.playListULid);
            
            //cancel all playlist animations before emptying container
            for(i=0;i<fxArray.length;i++)
            {
            	$clear(fxArray[i].timer);
            }

            for(i=0;i<fxArray.length;i++)
            {
      //      	fxArray[i].fx.cancel();
            } 
            
            container.empty();
            
            var start = size * page;
            var end = size * (page + 1);
            end = end.limit(0, items.length);
            
            fxChain = new Chain();
			var boxlink = "";
			
            for(i=start; i < end; i++)
            {

           		boxlink = "javascript:startMovie(" + items[i].clipId + ")";
				
                var el = new Element("li", {
                    "id" : items[i].clipId,
                    "class": "clipHolder" + (items[i].clipId == currentClipId ? " "+config.highlightClass : "") + ((i-start) % 3 == 2 ? " right" : ""),
                    "styles": {
                        opacity : 0                   
                    }
                });
                
                
                if (items[i].imageId) {
					var imageDiv = new Element("div", {
	                }).inject(el);

					var imageA = new Element("a", {
	                    "href" : boxlink 
	                }).inject(imageDiv);

	                var image = new Element("img", {
	                    "src" : config.imgBasePath + items[i].imageId + "-162.jpg",
	                    "alt" : items[i].title + "\n" + items[i].descr
	                }).inject(imageA);
                }


				var h3 = new Element("h3", {
                    "class" : "clipTitle"
                }).inject(el);

				new Element("a", {
                    "href" : boxlink,
                    "html" : items[i].title
                }).inject(h3);


	            new Element("p", {
	                "class" : "clipDescr",
	                "html" : items[i].descr
	            }).inject(el);
				

                el.inject(container); 
                
				fx = el.set('tween', {duration: 300});

                f = function(){
	                    this.tween('opacity', 1);
	                }.delay(100 * (i - start), fx)
	                
	            fxArray.push({"fx": fx, "timer" : f});
	            
	            if (i==start+2){
	            	new Element("div", {
	            		"class": "clearthis",
	            		"html":"&nbsp;"
	            	}).inject(container);
	            }
//		        player.highlight($(player.activeItem), $('playlist')); 
            }
       }
        


        //
        // create pager (UL)
        //
        function renderPager(currentPage, collectionSize, pageSize, pagerSize)
        {
            var container = $(config.pagerULid)
            container.empty();
            
            var lBound = 0;
            var uBound = pagerSize.limit(0, ((collectionSize + pageSize - 1)/pageSize).floor());
            
            if(currentPage >= ((pagerSize-1)/2).round())
            {
                lBound = (currentPage - ((pagerSize-1)/2).round()).limit(0, currentPage - 1);
                uBound = (lBound + pagerSize).limit(lBound, ((collectionSize + pageSize - 1)/pageSize).floor());
                lBound2 = (uBound - pagerSize).limit(0, lBound);
                lBound = lBound2;
            }
            
            if (uBound > 1) {
	            for(i=lBound;i<uBound;i++)
	            {
	                new Element("li", {
	                    "id"   : "page" + i,
	                    "class" : (i != currentPage ? ("") : ("nav_current")),
	                    "html" : (i != currentPage ? ("<a href=\"javascript:changePage(" + i + ")\">" + (i + 1) + "</a>") : ("<a class=\"sel\">" + (i + 1) + "</a>"))
	                }).inject(container, "bottom");     
	            }
	        }
        }

        //
        // format duration string
        //
        function getDurationString(sec)
        {
            var m = Math.floor(sec/60);
            var s = Math.round(sec - (m * 60));
            
            return m + ":" + (s > 9 ? s : (s > 0 ? ("0" + s) : "00"));
        }


		function autostart() {
			var clipId = data.items[0].clipId;
			var play = false;
			if (document && document.location.search && document.location.search.length > 0) {
				var params = location.search.substr(1).split(",");
				for(i=0;i<data.items.length;i++) {
					if (data.items[i].clipId == params[0]) {
						clipId = data.items[i].clipId;
						play = true;
					}
				}
			}
			
			if (play == true)
				startMovie(clipId,false)
			else
				startMovie(clipId,true)

		}

		function startMovie(id,dontPlay) {
			var clipElement = null;
			currentClipId = id;
						
			for(i=0;i<data.items.length;i++) {
				if (data.items[i].clipId == id) {
					clipElement = data.items[i];
				}
			}
			
			if (clipElement != null) {
				if (dontPlay) {
					loadFile("mediaplayer",{file:clipElement.url,image:"http://dynimg.rte.ie/" + clipElement.imageId + "-512.jpg"}, false);
				}
				else {
					loadFile("mediaplayer",{file:clipElement.url}, true);
				}
				loadClipData(clipElement.clipId);
				highlight(clipElement.clipId);
			}
		}

		function highlight (el){
			$$("#" + config.playListULid + " ." + config.highlightClass).each(function(item, i){
				item.removeClass(config.highlightClass)
			}, this);

			if($(el)) $(el).addClass(config.highlightClass);
		}

		function thisMovie(movieName) {
		    if(navigator.appName.indexOf("Microsoft") != -1) {
		        return window[movieName];
		    } else {
		        return document[movieName];
		    }
		};
		
		function loadFile(swf,obj,play) {
			var movie = thisMovie(swf);
			movie.loadFile(obj);
			if (play) movie.sendEvent("playpause");
		};
		
		function loadClipData(el){
			for(i=0;i<data.items.length;i++) {
				if (data.items[i].clipId == el) {
					var clipElement = data.items[i];				
					$('player-meta').getElement('h3').set('html', clipElement.title);
					$('player-meta').getElement('p').set('html', clipElement.descr); 
				}
			}
		}	
		
		

