	$(document).ready(function(){
		inithomeimg();
	});

	function inithomeimg()
	{
		var imgs = [];
	    var appRoot = document.getElementById('appRoot').getAttribute('href');
		var prefix = '<img alt="" src="' + appRoot + 'homeimgs/';
		var suffix = '" />';
		
//		$('#piclist li').each(function(){
//			imgs.push($(this)[0].innerText);
//		});
	    var piclist = document.getElementById('piclist').childNodes;
	    for (var x = 0; x < piclist.length; x++)
	    {
	    	imgs.push(piclist[x].innerHTML);
	    }
		
		//imgs = ['one', 'two', 'three'];		
		var homeimgSlideCount = 1 + imgs.length;

		$('#homeimg').append(prefix + imgs.shift() + suffix);
		$('#homeimg').append(prefix + imgs.shift() + suffix);


		$('#homeimg').cycle({
		  fx: 'fade',
		  speed: 1500,
		  next:   '#homeimgnext',
    	  prev:   '#homeimgprev',
    	  pause: 1,
		  before:   onBefore
 		});
		$('#homeimgprev').show();
		$('#homeimgpause').show();
		$('#homeimgnext').show();
		
		// inner function has access to imgs homeimgSlideCount;
        function onBefore(curr, next, opts, fwd) { 
            // on Before arguments: 
            //  curr == DOM element for the slide that is currently being displayed 
            //  next == DOM element for the slide that is about to be displayed 
            //  opts == slideshow options 
            //  fwd  == true if cycling forward, false if cycling backward 
                 
            // on the first pass, addSlide is undefined (plugin hasn't yet created the fn yet) 
            if (!opts.addSlide) 
                return; 
                 
            // have we added all our slides? 
            if (opts.slideCount == homeimgSlideCount) 
                return; 
 
            // shift or pop from our slide array  
            var nextSlideSrc = fwd ? imgs.shift() : imgs.pop(); 
             
            // add our next slide 
            //opts.addSlide('<img alt="" src="../homeimgs/'+ nextSlideSrc +'" />', fwd == false); 
            opts.addSlide(prefix + nextSlideSrc + suffix, fwd == false); 
        }; 
	}
		
	function pause()
	{
		$('#homeimg').cycle('pause');
		$('#homeimgpause').hide();
		$('#homeimgresume').show();
	}
	
	function resume()
	{
		$('#homeimg').cycle('resume');
		$('#homeimgresume').hide();
		$('#homeimgpause').show();
	}
