(function(){


(function($) {
$.fn.jGallery = function(o) {
    return this.each(function(){

		var index = 1, max = 0;

		var self = $(this), self2 = $(this);

		self.append('<ul></ul>');
		self.find('img').each(function(){
			max++;
			$(this).addClass('img-' + max);
			self2.find('ul').append('<li class="n-' + max + '"><a href="#">' + max + '</a></li>').end();
		}).end();
		self.find('li.n-1').addClass('active').end();
		self.find('li a').click(function(){
			$(this.parentNode).removeClass('active');
			var nn = parseInt(this.parentNode.className.split('-')[1]);
			go(nn);
			return false;
		}).end();
		setInterval(next, 5000);

		function next(){
			var nn = index + 1;
			if (nn > max)
				nn = 1;
			go(nn);
		};
		function go(nn) {
			self.
				find('img').hide().end().
				find('p').hide().end().
				find('li').removeClass('active').filter('.n-' + nn).addClass('active').end().end().
				find('img.img-' + nn).show().next('p').show().end();
			index = nn;
		};
   });
};
})(jQuery);



var api = {
	init: function(){
		$('#header, #productTop .photo').jGallery();
		tabs.init('#menu2');
		
		$('#pullouts p').each(function(){
			var w = $(this).width();
			var l = - (w - 12 -25);
			$.data(this, 'info', { 'w': w, 'l': l });
			$(this).css({ left: l + 'px' });
		});
		$('#pullouts p').hover(function(){
			$(this).animate({ left: '0px' }, 250);
		}, function(){
			var info = $.data(this, 'info');
			$(this).animate({ left: info.l + 'px' }, 300);
		});
	}
};
var tabs = {
	init: function(id)
	{
		$(id + ' p a').click(function(){
			$(id + ' p a').removeClass('active');
			$(this).addClass('active');
			$(id + ' > ul').hide();
			var i = $(this).attr('href');
			$(i).show();
			return false;
		});
	}
};

$(document).ready(api.init);

})();

