(function($){
	

	$.fn.buttonize = function(opts) {
		var o = $.extend({}, $.fn.buttonize.defaults, opts);
		return this.each(function(){
			var wrap = $('<div />'), button = $(this), tail = $('<span />'), inp = (this.tagName == 'INPUT'), height, padd, top;
			height = inp ? '30px' : '24px';
			padd = inp ? '0 0 0 10px': '4px 0 0 10px';
			top = inp ? '5px' : '0px';
			button.css({ 'background-image':'url(/img/tomatou_buttons.png)', 'background-repeat':'no-repeat', 'background-color':'transparent', 'height':height, 'color':'#FFFFFF', 'font-size':'10px', 'border':'0', 'padding':padd, 'cursor':'pointer', 'text-decoration':'none', 'display':'block', 'position':'absolute', 'left':'0px', 'top':'0px', 'z-index':'30' });
			tail.css({ 'height':'25px', 'width':'20px', 'background-image':'url(/img/tomatou_buttons.png)', 'background-repeat':'no-repeat', 'background-color':'transparent', 'position':'absolute', 'z-index':'5', 'top':top, 'right':'0px', 'display':'block' });
			wrap.addClass('buttonize_wrap').css({ 'position':'relative', 'width': button.width() + 20, 'height':'30px', 'display':'block', 'margin':'8px 0px' });
			setBackgroundPos(button,tail,o.active,inp);
			button.wrap(wrap).after(tail);
			//button.mouseover(function(){ setBackgroundPos(button,tail,o.hover,inp); });
			//button.mouseout(function(){ setBackgroundPos(button,tail,o.active,inp); });
		});
		
	};
	$.fn.buttonize.defaults = { active: 'orange', hover: 'gray' };
	
	$.fn.gbutton = function() {
		return this.each(function(){
			var button = $(this);
			
			button.css({
				'-moz-user-select':'none',
				'-moz-border-radius':'3px',
				'background':'-moz-linear-gradient(center top, #F9F9F9, #E3E3E3) repeat',
				'border':'1px solid #BBBBBB',
				'color':'#000000',
				'cursor':'pointer',
				'font-family':'arial,sans-serif',
				'margin':'0 8px',
				'outline':'medium none',
				'padding':'3px 6px',
				'text-align':'center',
				'vertical-align':'middle',
				'white-space':'nowrap',
				'display':'inline-block',
				'position':'relative',
				'text-decoration':'none'				
			});
			
			button.hover(
				function() { button.css({'border':'1px solid #939393'}); },
				function() { button.css({'border':'1px solid #BBBBBB'}); }
			);
			
		});
	};
	
	function setBackgroundPos(m,t,s,i) {
		var p,a;
		if ( s == 'blue' ) p = 0;
		if ( s == 'lt_lt_blue' ) p = -90;
		else if ( s == 'lt_blue' ) p = -180;
		else if ( s == 'gray' ) p = -270;
		else if ( s == 'orange' ) p = -360;
		else p = 0;
		a = p - 40;
		a = i ? a : a - 5;
		m.css({'background-position':'0% ' + a + 'px' });
		t.css({'background-position':'100% ' + p + 'px' });
	};
	
	function debug(str) {
    	if (window.console && window.console.log) window.console.log(str);
  	};

/*
	$.fn.photoManager = function(opts) {
		var o = $.extend({}, $.fn.photoManager.defaults, opts),
			bg = $('<div />'),
			iframe = $('<iframe id="photoManager" name="photoManager" />');
			
		function open() {
			bg.css({'top':$(document).scrollTop(),'height':$(window).height()}).show().animate({ 'opacity':'0.8' }, 1000);
			$('body').css({'overflow':'hidden'});
			//document.getElementById("photoManager").contentWindow.name = 'Can you get info now?';			
			loadIframe();

			
			setTimeout(function(){ 
				var testFrame = document.getElementById("photoManager");
		   		var doc = testFrame.contentDocument;
		  		if ( doc == undefined || doc == null )
		    		doc = testFrame.contentWindow.document;		       
				testFrame.contentWindow.name = 'Tag your it!';
			},3000);
			
			return false;
		}
		
		function close() {
			bg.animate({ 'opacity':'0.0' }, 1000, function(){ bg.hide(); });
			$('body').css({'overflow':'auto'});
			closeIframe();
			return false;
		}
		
		function loadIframe() {
			var height = $(window).height(),
				width = $(window).width(),
				top = $(document).scrollTop(),
				fintop = top + 75,
				finheight = height - 150,
				finleft = (width / 2) - 350,
				finwidth = 700,
				intop = top + (height / 2) - 10,
				inleft = (width / 2) - 10;
			
			iframe.css({'top':intop,'left':inleft})
				.show()
				.animate({'top':fintop,'height':finheight}, 500, function(){ 
					iframe.animate({'left':finleft,'width':finwidth}, 1000, function(){
						$( document.getElementById("photoManager").contentWindow.document.getElementById('close_frame') ).click(close);
						var l = $(document.getElementById("photoManager").contentWindow.document).find('.left');
						l.click(function(){
							close();
						});
					})
				})
				.attr({'src':'/uploads/view/5'});
			return true;
		}
		
		function closeIframe() {
			iframe.animate({'width':'20px','left':($(window).width() / 2) - 10}, 800, function(){
				iframe.animate({'height':'20px','top':$(document).scrollTop() + ($(window).height() / 2) - 10}, 300, function(){
					iframe.hide();
				});
			});
		}
			
		bg.css({
			'width':'100%',
			'background-color':'#000000',
			'opacity':'0.0',
			'position':'absolute',
			'left':'0px',
			'z-index':'99999',
			'display':'none'
		}).click(close).appendTo('body');
		
		iframe.css({
			'background-color':'#FFFFFF',
			'position':'absolute',
			'z-index':'999999',
			'display':'none',
			'width':'20px',
			'height':'20px',
			'border':'0px',
			'-moz-box-shadow':'0px 0px 20px #000000'
		}).appendTo('body');
			
		return this.each(function(){
			var anchor = $(this);
			anchor.click(open);
		});
		
	};
	$.fn.photoManager.defaults = {};
*/
	
})(jQuery);
