


(function($) {

	var pv_uiactive = false;

	$.fn.podviewer = function(options) {
		
		var options = $.extend({}, $.fn.podviewer.defaults, options);
		
		return this.each(function() {
			
			var self = this;
			$this = $(this);
			self.$scroller = $this.find('.carousel-scroller');
			self.$content = $this.find('.content');

			$this.find('.carousel-prev').click(function() { self.next();});
			$this.find('.carousel-next').click(function() { self.prev();});
			self.$content.hover(function() {self.overlayshow();} , function() {self.overlayhide();});
			self.$scroller.find('a').click(function(event) {self.scrollbuttonclick(event);});
						

			this.prev = function() {
				if(pv_uiactive) return;
				pv_uiactive = true;
				var currentpos = parseInt(self.$scroller.css('marginLeft'));
				if(!currentpos || isNaN(currentpos)) currentpos = 0;
				self.$scroller.find(':first').clone(true).appendTo(self.$scroller);
				self.$scroller.animate({marginLeft: (currentpos - options.scrollwidth) + 'px'}, options.scrollspeed, null, function() {
					self.$scroller.find(':first').remove();
					self.$scroller.css('marginLeft', (currentpos) + 'px');
					pv_uiactive = false;
				});
			};

			this.next = function() {
				if(pv_uiactive) return;
				pv_uiactive = true;
				var currentpos = parseInt(self.$scroller.css('marginLeft'));
				if(!currentpos || isNaN(currentpos)) currentpos = 0;
				self.$scroller.find(':last').clone(true).prependTo(self.$scroller);
				self.$scroller.css('marginLeft', (currentpos - options.scrollwidth) + 'px');
				self.$scroller.animate({marginLeft: (currentpos) + 'px'}, options.scrollspeed, null, function() {
					self.$scroller.find(':last').remove();
					pv_uiactive = false;
				});
			};

			this.overlayshow = function() {
				self.$content.find('a:visible .overlay').stop().animate({marginLeft: '0px'});
			};

			this.overlayhide = function() {
				self.$content.find('a:visible .overlay').stop().animate({marginLeft: -options.overlaywidth+'px'});				
			};
		
			this.scrollbuttonclick = function(event) {
				$btn = $(event.target);
				var rel = $btn.attr('rel');
				self.$content.find('a:visible').hide();
				self.$content.find('a.' + rel).show();
				event.preventDefault();
				
				self.$scroller.find('.isover').each(function() {
					var classes = $(this).attr('class').split(' ');
					for(var i=0,j=classes.length;i<j;i++) {
						if(classes[i].indexOf('-over') > -1) {							
							$(this).removeClass(classes[i]).removeClass('isover');
							break;
						}
					}
				});
				
				$btn.addClass(rel + '-over').addClass('isover');
				
			};
		});
		


	};

	function debug($obj) {
		if (window.console && window.console.log) {
			 window.console.log($obj);
		}
	}

	
	$.fn.podviewer.defaults = {
		scrollwidth: 220,
		scrollspeed: 250,
		overlayslidefrom: 'left',
		overlaywidth: 214
	};


})(jQuery);
	


$(function() {
	$('.bigpod').podviewer();
	$('.small-scroller').podviewer({scrollwidth: 140});
});

	//function for image switching 
	function swap_image(dest,newimage)
	{
		$(dest).attr('src',newimage);
	}
