/**
 * @plugin: thi.jquery.reel
 * @author: THI Dev team
 * @version: 1.1
 * */
(function($) {

	$.fn.thiReel = function(options) {
		
		//Default settings
		var settings = {
			all_link: '.view_all',
			prev_link: '#prev',
			next_link: '#next',
			thumbs: '.thumbs',
			hover: '.hover'
		};
		
		//extend
		$.extend(settings,options);
		
		return this.each(function() {
			var base 		= this,
				$all_link	= $(base).find(settings.all_link),
				$thumbs		= $(base).find(settings.thumbs);
			
			/**
			 * @method: init
			 * */
			this.init = function() {
				
				this.setCurrent();
				
				//Attach toggle event
				this.showAll();
				
				this.hoverItems();
			}
			
			/**
			 * @method: showAll
			 * */
			this.showAll = function() {
				$all_link.toggle(
					function() {
						$thumbs.slideDown();						
						return false;
					},
					function() {
						$thumbs.slideUp();						
						return false;
					}
				);
			}
			
			/**
			 * @method: setCurrent
			 * */
			this.setCurrent = function() {				
				base.maskItem(
						$thumbs.children(':not(.separator)').filter('.current')
				);
			};
			
			/**
			 * @method: hoverItems
			 * */
			this.hoverItems = function() {
				$thumbs.children(':not(.separator):not(.current)').hover(
					//On
					function() {
						base.maskItem($(this));
						$(this).addClass('on');
					},
					//Off
					function() {
						base.unMaskItem($(this));
						$(this).removeClass('on');
					}
				);
			};
			
			/**
			 * @method: maskItem
			 * */
			this.maskItem = function(current) {				
				var $hover = current.find('.hover');
				var $mask = $('<div />');
				$mask
					.addClass('mask')
					.css({
						'position': 'absolute',
						'top': '0',
						'left': '0',
						'width': '100%',
						'height': '100%',
						'cursor': 'pointer'
					})
					.appendTo($hover);
			};
			/**
			 * @method: unMaskItem
			 * */
			this.unMaskItem = function(current) {
				current.find('.mask').remove();
			};
			
			this.init();
		});
		
	}
	
})(jQuery);


$(document).ready(function() {
	$('#reel').thiReel();
});
