// slideshow (home page)
var slideshow = {
			
	slideshow	: false,
	nav			: false,
	buttons		: false,
	container	: false,
	slides		: false,
	static		: false,
	corner_tl	: false,
	tooltip		: false,
	
	pos			: 0,
	max			: 0,
	
	delay		: 4000,
	transition	: 200,
	paused		: false,
	pause_delay : 8000,
	timer		: false,
	
	initiated	: false,
	
	next : function (new_pos) {
		clearTimeout(slideshow.timer);
		
		slideshow.slides.fadeOut();
		
		var _pos = slideshow.pos;
		
		if ( typeof new_pos === 'undefined' ) {
			_pos = ( ( slideshow.pos + 1 ) < slideshow.max ) ? slideshow.pos + 1 : 0;
		} else {
			if ( isNaN(new_pos) == false ) {
				_pos = new_pos;
			}
		}
		
		if ( _pos != slideshow.pos ) {
			
			slideshow.slides.eq(_pos).fadeIn(slideshow.transition, function () {
				if ( ! slideshow.paused ) {
					slideshow.timer = setTimeout( function () { slideshow.next() } , slideshow.delay );
				}
			});
			
			slideshow.buttons
				.removeClass('active')
				.eq(_pos)
					.addClass('active');
			
			slideshow.pos = _pos;
		}
	},
	
	go_to : function (e) {
		sender = $j(this);
		
		var new_pos = parseInt((sender.attr('data')));
		
		slideshow.next(new_pos);
	},
	
	create_nav : function () {
		var html = '';
		
		for ( var i = 0; i < slideshow.max; i++ ) {
			var a = document.createElement('a');
			
			a.setAttribute('href', 'javascript:void(0);');
			a.setAttribute('data', i);
			
			if ( i == 0 ) a.setAttribute('class', 'active');
			
			slideshow.nav.append( $j(a).click(slideshow.go_to) );
		}
		
		slideshow.buttons = slideshow.nav.children('a');
	},
	
	show_tooltip : function () {
		slideshow.tooltip.fadeIn('fast');
	},
	
	hide_tooltip : function () {
		slideshow.tooltip.fadeOut('fast');
	},
	
	pause : function () {
		clearTimeout( slideshow.timer );
		slideshow.paused = true;
	},
	
	unpause : function () {
		slideshow.timer = setTimeout( function () { slideshow.next() } , slideshow.pause_delay );
		slideshow.paused = false;
	},
	
	initialise : function () {
		
		if ( slideshow.initiated == false ) {
			slideshow.slideshow = $j('#slideshow');
			slideshow.nav		= $j('#slideshow-nav');
			slideshow.container = $j('#container');
			slideshow.slides	= slideshow.container.find('img');
			slideshow.static	= $j('#slideshow-static');
			slideshow.corner	= $j('#slideshow-tl-corner');
			slideshow.tooltip	= $j('#slideshow-tooltip');
			
			slideshow.max		= slideshow.slides.length;
			
			slideshow.create_nav();
			
			slideshow.slideshow.hover(slideshow.pause, slideshow.unpause);
			
			slideshow.static.children('span').hover(slideshow.show_tooltip, slideshow.hide_tooltip);
			
			setTimeout( function () {
				slideshow.slides.first().fadeIn('slow', function () {
					slideshow.static.fadeIn('slow', function () {
						slideshow.corner.fadeIn('slow', function () {
							slideshow.timer = setTimeout( function () { slideshow.next() } , slideshow.delay );
						});
					});
				});
			}, 1000 );
		}
		
		slideshow.initiated = true;
	}
};

var vouchers = {
	initialise : function () {
		$j('.featured-voucher:nth-child(3n)').css('margin-right', 0);
	}
};

// on ready
bob.add_onready_function( vouchers.initialise );

// on load
bob.add_onload_function( slideshow.initialise );
