window.addEvent('domready', function() {
    var coor = $('slideshow').getCoordinates();
    $('onstate').setStyles({
	'top':coor.height + coor.top  - 16 + 'px',
	'left':coor.left + 1 + 'px'
    });

    $('slinks').setStyles({
	'position':'absolute',
	'top':coor.top + 'px',
	'left':coor.right - 80 + 'px',
	'z-index':100
    });

    images = $('imgcont').getElements('img');
    first = images[0];
    count = images.length + 1;

    $('imgcont').setStyle('width', (count * first.getStyle('width').toInt()) + (count * first.getStyle('padding').toInt()) + 'px');

    $('onstate').fade('hide');

    var ondata = new Hash({
	0:{'img':'images/caro_ins_on.jpg', 'text':"<p>The AOC 15/50 helps create greater predictability and stability in an insitution's electricity costs and therefore greater confidence when operating on fixed budgets. In addition, these insitutions - governments, hospitals, universities, schools, municipalities - are typically operating for the benefit of the public.  By taking a leadership position to reduce their carbon emissions, institutions can further demonstrate their value to their stakeholders and the general public.</p>"},
	1:{'img':'images/caro_bus_on.jpg', 'text':"<ul><li><p>reducing the costs of purchasing electricity from a utility,</p></li><li><p>creating greater predicability and stability in the company's electricity costs and therefore greater control over fixed operating costs,</p></li><li><p>the company's brand and customer and employtee loyalty by identifying with positive values of green initiatives to help the environment</p></li><li><p>enhancing competitive advantages by reducing costs and enhancing brand</p></li></ul>"},
	2:{'img':'images/caro_far_on.jpg', 'text':"<p>By taking advantage of this natural resource, farmers can provide cleaner and greener products for our kitchen tables &ndash; and at the same time help save the environment that is needed to provide us with nourishment.  The benefits for farmers extend beyond saving the planet and include reducing and having greater certainty over operating costs as well as enhancing their brand by marketing &quot;green&quot; food.</p>"},
	3:{'img':'images/caro_com_on.jpg', 'text':"<p>The AOC 15/50 helps create greater predictability and stability in an insitution's electricity costs and therefore greater confidence when operating on fixed budgets. In addition, these insitutions - governments, hospitals, universities, schools, municipalities - are typically operating for the benefit of the public.  By taking a leadership position to reduce their carbon emissions, institutions can further demonstrate their value to their stakeholders and the general public.</p>"}
    });

    var caro = new SimpleSlideShow.Carousel($('slideshow'), {
	startIndex: 0,
	slides: $$('#slideshow div.slide'),
	nextLink: 'nextl',
	prevLink: 'prevl',
	onNext:function() {
	    $('onstate').fade('out');
	},
	onPrev:function() {
	    $('onstate').fade('out');
	},
	onSlideClick:function() {
	    console.log('clicked');
	    $clear(timer);
	}
    });

    $$('#slideshow div.slide a.sread').each(function(el, i) {
	el.addEvent('click', function(e) {
	    e.stop();
	    $clear(timer);
	    $('oncopy').set('html', ondata[i].text);
	    $('onstate').setStyles({
		'background':'url('+ondata[i].img+') no-repeat top left'
	    }).fade('in');
	});
    });

    $('onstateclose').addEvent('click', function(e) {
	e.stop();
	$('onstate').fade('out');
    });

    var per = function() {
     caro.forward();
    }

    timer = per.periodical(3000);
});
