﻿
var Ticker = new Class({
	setOptions: function(options) {
		this.options = Object.extend(/**{
			speed: 100,
			delay: 100,
			direction: 'horizontal',
			onComplete: Class.empty,
			onStart: Class.empty
		},*/ options || {});
	},
	initialize: function(el,options){
		this.setOptions(options);
		this.el = $(el);
		this.items = this.el.getElements('li');
		var w = 0;
		var h = 0;
		if(this.options.direction.toLowerCase()=='horizontal') {
			h = this.el.getSize().y;
				this.items.each(function(li,index) {
				w += li.getSize().x;
			});
		} else {
				w = this.el.getSize().x;
				this.items.each(function(li,index) {
					h += li.getSize().y;
				});
			}
			this.el.setStyles({
				position: 'absolute',
				top: 0,
				left: 0,
				width: w,
				height: h
			});
			this.fx = new Fx.Morph(this.el,{duration:this.options.speed,onComplete:function() {
				var i = (this.current==0)?this.items.length:this.current;
				this.items[i-1].injectInside(this.el);
				this.el.setStyles({
					left:0,
					top:0
				});
			}.bind(this)});
			this.current = 0;
			this.next();
			},
	
	pause: function() {
	    $clear(mytimer);
	    mytimer = null;
	},
	resume: function() {
	    if (mytimer == null) {
	    this.next();
	    }
	},
	next: function() {
		this.current++;
		if (this.current >= this.items.length) this.current = 0;
		var pos = this.items[this.current];
		this.fx.start({
			top: -pos.offsetTop,
			left: -pos.offsetLeft
		});
		mytimer = this.next.bind(this).delay(this.options.delay+this.options.speed);
	},
	prev: function() {
		this.current--;
		if (this.current < 0) this.current = this.items.length-1;
		var pos = this.items[this.current];
		this.fx.start({
			top: -pos.offsetTop,
			left: -pos.offsetLeft
		});
		mytimer = this.next.bind(this).delay(this.options.delay+this.options.speed);
	}
});

var mytimer = null;

function startSlideshow(ulId, hasNav, slideSpeed, delayValue)
{
   var hor = new Ticker(ulId, {speed: slideSpeed, delay: delayValue, direction: 'horizontal', onComplete: Class.empty, onStart: Class.empty});

    if(hasNav)
    {
	    $$('.gallery-holder .next')[0].addEvent('click', function() {
	        hor.pause();
		    hor.next();
	    });
    	
	    $$('.gallery-holder .prev')[0].addEvent('click', function() {
	        hor.pause();
		    hor.prev();
	    });
	}
	
	/**$('stop_scroll').addEvent('click', function() {
		hor.pause();
	});
	$('start_scroll').addEvent('click', function() {
		hor.resume();
	});*/
}

function generateMainSlideshow(container)
{
	$(container).adopt(
		new Element('div', {id:'slideshow-mask'}).adopt(
			new Element('ul', {id:'slides'}).adopt(
				new Element('li').adopt(
					new Element('a', {href:'/Bli-medlem'/**,'onclick':"_gaq.push(['_<wbr>trackEvent', 'Slider', 'Klick', 'Erbjudanden']);"*/}).adopt(
			            new Element('img', {'src':'/images/common/img06.jpg','alt':'Se våra erbjudanden!'})			
					)
				),
				new Element('li').adopt(
					new Element('a', {href:'/vad-ingår-på-nya-gi-viktkoll'/**,'onclick':"_gaq.push(['_<wbr>trackEvent', 'Slider', 'Klick', 'Erbjudanden']);"*/}).adopt(
			            new Element('img', {'src':'/images/common/img06b.jpg','alt':'Detta får du som medlem!'})			
					)
				),
				new Element('li').adopt(
					new Element('a', {href:'/Bli-medlem'/**,'onclick':"_gaq.push(['_<wbr>trackEvent', 'Slider', 'Klick', 'Erbjudanden']);"*/}).adopt(
			            new Element('img', {'src':'/images/common/img06c.jpg','alt':'Se våra erbjudanden!'})			
					)
				),
				new Element('li').adopt(
					new Element('a', {href:'/hur-fungerar-gi'/**,'onclick':"_gaq.push(['_<wbr>trackEvent', 'Slider', 'Klick', 'Erbjudanden']);"*/}).adopt(
			            new Element('img', {'src':'/images/common/img06d.jpg','alt':'Hur fungerar GI?'})			
					)
				)
			)
		)
	);
}

function generatePuffSlideshow(container)
{
	
	/**
	
						    <div class="image">
							    <img src="/images/common/img08.jpg" width="307" height="200" alt="Specialerbjudande!">
						    </div>
						    <div class="info">
							    <p>Bli gratismedlem idag och ta chansen att få Olas nya bok! <a href="http://www.giviktkoll.se/templates/PublicPage.aspx?id=28540" class="more">Läs mer </a></p>
						    </div>
	*/
	
	$(container).adopt(
		new Element('div', {id:'small-slideshow-mask'}).adopt(
			new Element('ul', {id:'puff-slides'}).adopt(
				new Element('li').adopt(
		            new Element('div', {'class':'image'}).adopt(
		                new Element('img', {'src':'/images/common/slides/sem.jpg','width':'307','height':'200','alt':'Specialerbjudande!'})
		            ),
		            new Element('div', {'class':'info'}).adopt(
		                new Element('p',{'html':'Kom på föreläsning med mig och lär dig GI-metoden! '}).adopt(
		                    new Element('a',{'class':'more','href':'http://www.giviktkoll.se/templates/PublicPage.aspx?id=28538','html':'Läs mer'})
		                )
		            )
				),
				new Element('li').adopt(
		            new Element('div', {'class':'image'}).adopt(
		                new Element('img', {'src':'/images/common/slides/bok.jpg','width':'307','height':'200','alt':'Specialerbjudande!'})
		            ),
		            new Element('div', {'class':'info'}).adopt(
		                new Element('p',{'html':'Bli gratismedlem idag och ta chansen att få Olas nya bok! '}).adopt(
		                    new Element('a',{'class':'more','href':'http://www.giviktkoll.se/templates/PublicPage.aspx?id=28540','html':'Läs mer'})
		                )
		            )
				),
				new Element('li').adopt(
		            new Element('div', {'class':'image'}).adopt(
		                new Element('img', {'src':'/images/common/slides/zumba.jpg','width':'307','height':'200','alt':'Specialerbjudande!'})
		            ),
		            new Element('div', {'class':'info'}).adopt(
		                new Element('p',{'html':'Bli turbomedlem och få specialpris på Zumba! '}).adopt(
		                    new Element('a',{'class':'more','href':'http://www.giviktkoll.se/templates/PublicPage.aspx?id=28517','html':'Läs mer'})
		                )
		            )
				),
				new Element('li').adopt(
		            new Element('div', {'class':'image'}).adopt(
		                new Element('img', {'src':'/images/common/slides/boxen.jpg','width':'307','height':'200','alt':'Specialerbjudande!'})
		            ),
		            new Element('div', {'class':'info'}).adopt(
		                new Element('p',{'html':'Färdiglagad smalmat, direkt till dörren! '}).adopt(
		                    new Element('a',{'class':'more','href':'http://www.giviktkoll.se/Bli-medlem','html':'Läs mer'})
		                )
		            )
				)
			)
		)
	);
}

function initiateSlideshow()
{
    var delayValue = 4500;
    var slideSpeed = 1000;

	var mainSlideContainer = $$('.gallery-content')[0];
	if(mainSlideContainer)
	{
//		generateMainSlideshow(mainSlideContainer);
		setTimeout("startSlideshow('slides', " + true + ", " + slideSpeed + ", " + delayValue + ")", delayValue);
	}
	
	var puffSlideContainer = $$('.small-gallery-content')[0];
	if(puffSlideContainer)
	{
//		generatePuffSlideshow(puffSlideContainer);
		setTimeout("startSlideshow('puff-slides', " + true + ", " + slideSpeed + ", " + delayValue + ")", delayValue);
	}
}
	/**
function generateTumbnailSlideshow(container)
{
	$(container).adopt(
		new Element('div', {id:'slideshow-mask'}).adopt(
			new Element('ul', {id:'slides'}).adopt(
				new Element('li').adopt(
					new Element('a', {href:'/zumba','onclick':"_gaq.push(['_<wbr>trackEvent', 'Slider', 'Klick', 'Erbjudanden']);"}).adopt(
			            new Element('img', {'src':'/images/common/img06.jpg','alt':'Köp Zumba nu!'})			
					)
				),
				new Element('li').adopt(
					new Element('a', {href:'/martin','onclick':"_gaq.push(['_<wbr>trackEvent', 'Slider', 'Klick', 'Erbjudanden']);"}).adopt(
			            new Element('img', {'src':'/images/common/img06b.jpg','alt':'Köp Martin nu!'})			
					)
				),
				new Element('li').adopt(
					new Element('a', {href:'/martin','onclick':"_gaq.push(['_<wbr>trackEvent', 'Slider', 'Klick', 'Erbjudanden']);"}).adopt(
			            new Element('img', {'src':'/images/common/img06c.jpg','alt':'Köp Martin nu!'})			
					)
				)
			)
		)
	);
}

function initiateTumbnailSlideshow()
{
    var delayValue = 4000;
    var slideSpeed = 1000;

	var slideshowContainer = $$('.frame .info')[0];
	if(slideshowContainer)
	{
		generateSlideshow(slideshowContainer);
		setTimeout("startSlideshow(" + true + ", " + slideSpeed + ", " + delayValue + ")", delayValue);
	}
}*/

/**window.addEvent('domready', function() {
	initiateSlideshow();
});*/
