/*
 * Name: actionbox
 * Description: Display options menu to launch lightbox or web links.
 * Author: Soh Ching Boon
 * Author URI: http://www.chingboon.com
 * Copyright (C)
 * All rights reserved
 *
 * Usage:
 * jQuery(document).ready(function() {
 * 	jQuery('.snapshot').actionbox();
 * });
 *
 */
(function($) {
	// Constructor prototype for actionbox
	$.fn.actionbox = function(settings) {
		$.extend($.fn.actionbox.settings, settings);

		var preload = [new Image(), new Image(), new Image()];
		preload[0].src = $.fn.actionbox.settings.btnZoom;
		preload[1].src = $.fn.actionbox.settings.btnLink;
		
		return this.bind({
			mouseenter: function() {
				$.fn.actionbox.reveal($(this));
				return false;
			},
			mouseleave: function() {
				$.fn.actionbox.hide($(this));
				return false;
			}
		});
	};
		
	/*
	* Public, $actionbox methods
	*/
	$.extend($.fn.actionbox, {
		settings: {
			btnZoom: 'images/shared/btn_zoom_100x200.png',
			btnLink: 'images/shared/btn_link_100x200.png'
    	},
    	reveal: function(ele) {
			$('.overlay a.zoom, .overlay a.link').css({
				display: 'block',
				position: 'relative',
				top: $('.overlay').height()/2 - 100/2,
				left: $('.overlay').width()/2 - 200/2 - 60,
				margin: '0 30px',
				float: 'left',
				width: '100px',
				height: '100px',
				zIndex: 1000,
				textIndent: '-9999px',
				cursor: 'pointer'
			}).bind({
				mouseenter: function() {
					$(this).css('backgroundPosition', 'left bottom');
					return false;
				},
				mouseleave: function() {
					$(this).css('backgroundPosition', 'left top');
					return false;
				},
				click: function() {
					$.fn.actionbox.hide($(this));
				}
			}).hide();
	
			$('.overlay a.zoom').css('background', 'url(' + $.fn.actionbox.settings.btnZoom + ') no-repeat');
			$('.overlay a.link').css('background', 'url(' + $.fn.actionbox.settings.btnLink + ') no-repeat');
    		ele.find('.overlay, .overlay a').fadeIn(200);
    	},
    	hide: function(ele) {
			$('.overlay a').unbind('mouseenter mouseleave');
    		ele.find('.overlay, .overlay a').fadeOut(200);
    	}
	});

})(jQuery);
