////////////////////////////////////////////////////////////
// FPSBanana modJS :: Modify Your Profile with JavaScript //
// Concept, Design and Code by Big Ross                   //
////////////////////////////////////////////////////////////
// VERSION: 0.5 beta                                      //
// RELEASE DATE: 1/12/2010                                //
// Copyright (c) 2009-2010 Big Ross Labs                  //
////////////////////////////////////////////////////////////
// Requires JQuery - Read the Documentation               //
////////////////////////////////////////////////////////////
				
(function($){
	$.fn.extend({ 
		// You 2 Me Image Fix
		y2mfix: function(options) {
			var defaults = {
				mode: 'replace', // replace - Replace You 2 Me Image with default or your own : hide - Hide the You 2 Me Image
				img: 'http://www.bigrosslabs.com/fpsb/y2mfix/y2m.gif' // The source of the image you want to use
			};
			
			var options = $.extend(defaults, options);
		
    		return this.each(function() {
				var o =options;
				var obj = $(this);
				var y2m = $("img[src='http://image.fpsbanana.com/ico/y2m.gif']", obj);			
				
				if(o.mode == 'replace') {
					y2m.attr('src', o.img);
				} else if(o.mode == 'hide') {
					y2m.css('display', 'none');
				}
    		});
    	},
		// Affiliate Image Fix
		affiliateFix: function(options) {
			var defaults = {
				mode: 'fix' // fix - Attempt to fix broken Image : hide - Hide the Image
			};
			
			var options = $.extend(defaults, options);
		
    		return this.each(function() {
				var o =options;
				var obj = $(this);
				var aimg = $("img[src^='http://image.fpsbanana.com/flags/clubs/']", obj);
				
				if(o.mode == 'fix') {
					$("img[src^='http://image.fpsbanana.com/flags/clubs/']", obj).each(function() {
						$(this).attr('src', $(this).attr('src').replace('/clubs/', '/studios/'));
    				});
				} else if(o.mode == 'hide') {
					aimg.css('display', 'none');
				}
    		});
    	},
		// My Images : Replace certain images with your own
		myImages: function(options) {
			var defaults = {
				imgFind   : '',
				imgReplace: '' // The image to replace 
			};
			
			var options = $.extend(defaults, options);
		
    		return this.each(function() {
				var o =options;
				var obj = $(this);
				
				if(o.imgReplace != null) {
					$("img[src='"+o.imgFind+"']", obj).each(function() {
						$(this).attr('src', o.imgReplace);
    				});
				}
    		});
    	},
		// Image Hider Function
		hideImage: function(options) {
			var defaults = {
				type: '', // url - hide image by it's url : class - hide image by class (.myimage) : id - hide image by ID (#myimage)
				hide: '' // The url or class or id of the image you want to hide
			};
			
			var options = $.extend(defaults, options);
		
    		return this.each(function() {
				var o =options;
				var obj = $(this);	
				
				if(o.type == 'url') {
					$("img[src='"+o.hide+"']", obj).hide();
				} else if(o.type == 'class') {
					$("img[class='"+o.hide+"']", obj).hide();
				} else if(o.type == 'id') {
					$("img[id='"+o.hide+"']", obj).hide();
				}
    		});
    	},
		// Info Box Function :: Curently in production
		/*infoBox: function(options) {
			var defaults = {
				bgColor: '#222', // The background color of the info box
				borderSize: '3', // The size of the bottom border in pixels
				borderColor: '#333', // The bottom border color
				fontSize: '12', // The font size in pixels
				fontColor: '#FFF', // The font color
				content: '', // The content of the info box
				showClose: true // true - link will be show to close the box : false - box cannot be closed by the user
			};
			
			var options = $.extend(defaults, options);
		
    		return this.each(function() {
				var o =options;
				var obj = $(this);	
				var current = $('select:last', obj).val();
				var themelnk = location.href+'?settheme=';
				var boxCSS = {
					'position' : 'relative',
					'width' : '100%',
					'height' : 'auto',
					'top' : '0px',
					'margin-bottom' : '20px',
					'padding-top' : '15px',
					'padding-bottom' : '15px',
					'text-align' : 'center',
        			'background-color' : o.bgColor,
					'border-bottom' : o.borderSize+'px solid '+o.borderColor,
        			'font-weight' : 'normal',
					'font-size' : o.fontSize+'px',
        			'color' : o.fontColor,
					'display' : 'none',
					'z-index' : '1000'
      			};
				var boxContent = o.content;
				if(o.showClose == true) {
					boxContent = boxContent+'<p align="right"><a href="#" onclick="$(\'#modJS_theme\').slideUp(\'normal\');">&times; Close Box</a>&nbsp;&nbsp;&nbsp;&nbsp;';
				}
				$("<div>").attr('id', 'modJS_theme').css(boxCSS).html(boxContent).prependTo('body').slideDown('normal');
    		});
    	},*/
		// Text Replace Function
		textReplace: function(options) {
			var defaults = {
				textFind: '', // The text to find
				textReplace: '' // The text to replace the found text
			};
			
			var options = $.extend(defaults, options);
		
    		return this.each(function() {
				var o =options;
				var obj = $(this);
				var strReplaceAll = obj.html();
				var intIndexOfMatch = strReplaceAll.indexOf(o.textFind);
				while (intIndexOfMatch != -1){
					strReplaceAll = strReplaceAll.replace(new RegExp(o.textFind, "i"), o.textReplace)
					intIndexOfMatch = strReplaceAll.indexOf(o.textFind);
				}
				obj.html(strReplaceAll);
    		});
    	},
		// modJS Micro Banner Function
		supportBanner: function() {
			var obj = $(this);
			$('div.row_dark:last', obj).append('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.fpsbanana.com/studios/32970"><img src="http://img.bigrosslabs.com/modjs_micro_banner.png" border="0" title="Powered by modJS!" /></a>');
    	},
		// Page Title Function
		pageTitle: function(options) {
			var defaults = {
				title: '' // The title you want to set your profile as
			};
			
			var options = $.extend(defaults, options);
		
    		return this.each(function() {
				var o =options;
				document.title = o.title;
    		});
    	},
		// Avatar Hider Function
		hideAvatars: function() {
			var obj = $(this);
			$("div#box_messages table[onmouseout='ttObj.Close();']", obj).hide();
    	},
		// Element Hider Function
		hideElement: function(options) {
			var defaults = {
				element: '' // The element to hide as class name (.elementClass) or id (#elementID)
			};
			
			var options = $.extend(defaults, options);
		
    		return this.each(function() {
				var o =options;
				var obj = $(this);
				$(element, obj).hide();
    		});
    	},
		// modUber Function
		uberstyler: function(options) {
			var defaults = {
				user: null // DO NOT SET THIS VARIABLE!
			};
			
			var options = $.extend(defaults, options);
		
    		return this.each(function() {
				var o =options;
				var obj = $(this);
				var current = $('style:first', obj).text();
				var foot = $('div.row_dark:last');
				foot.children("a[href='http://www.fpsbanana.com/pages/192']").attr("href", "javascript:$(this).uberstylerOpen();").html('Open UberStyler');
    		});
    	},
		// modUberOpen Function
		uberstylerOpen: function(options) {
			var defaults = {
				user: null // DO NOT SET THIS VARIABLE!
			};
			
			var options = $.extend(defaults, options);
		
    		return this.each(function() {
				var o =options;
				var obj = $(this);
				var current = $('style:first').text();
				var defaultU = current;
				var modCSS = {
					'position' : 'relative',
					'width' : '800px',
					'height' : '420px',
					'top' : '0px',
					'margin' : '0 auto',
					'margin-bottom' : '20px',
					'padding-top' : '15px',
					'padding-bottom' : '15px',
					'text-align' : 'center',
        			'background-color' : '#222',
					'border-bottom' : '3px solid #333',
        			'font-weight' : 'normal',
					'font-size' : '11px',
        			'color' : '#fff',
					'display' : 'none',
					'z-index' : '1000'
      			};
				var logoCSS = {
					'display' : 'block',
					'width' : '96%',
					'height' : 'auto',
					'margin' : '0 auto',
					'margin-bottom' : '5px',
					'padding-bottom' : '5px',
					'text-align' : 'left',
					'border-bottom' : '1px dotted #333'
      			};
				var areaCSS = {
					'width' : '95% !important',
					'height' : '300px !important',
					'margin-bottom' : '5px',
					'text-align' : 'left'
      			};
				var optsCSS = {
					'position' : 'relative',
					'width' : '96%',
					'height' : 'auto',
					'margin' : '0 auto',
					'text-align' : 'right'
      			};
				var btnCSS = {
					'background' : '#1a1a1a !important',
					'color' : '#ccc !important',
					'margin-top' : '6px',
					'font-family' : 'tahoma, verdana, arial, sans !important',
					'font-weight' : 'bold',
					'cursor' : 'pointer'
      			};
				
				if($('#modUber').is(':visible')) {
					$('html, body').animate({scrollTop:0}, 'slow');
				} else {
					$('html, body').animate({scrollTop:0}, 'slow');
					$('<div>').html('<span><img src="http://modjs.bigrosslabs.com/images/uberstyler/mjs_us_logo.png" border="0" /></span><textarea id="modUberStyle">'+current+'</textarea><br /><div id="modUber_opts"><small><b class="red">NOTICE!</b> Any changes made here are only seen by you. The changes will not be saved unless you copy the code above and paste it into your UberStyle Editor!&nbsp;&nbsp;&nbsp;&nbsp;</small> &nbsp;&nbsp;&nbsp; <input type="button" id="modUber_select" class="border_green" value="Select All"></input> &nbsp;&nbsp; <input type="button" id="modUber_revert" class="border_red" value="Revert to Default"></input> &nbsp;&nbsp; <input type="button" id="modUber_close" class="border_blue" value="&times; Close"></input></div>').attr('id', 'modUber').css(modCSS).prependTo('body').slideDown('normal');
					$('#modUber span').css(logoCSS);
					$('#modUber textarea').css(areaCSS);
					$('#modUber_opts').css(optsCSS);
					$('#modUber_revert, #modUber_close, #modUber_select').css(btnCSS);
					$("#modUberStyle").live("keyup", function(){
						$('style:first').text($('#modUberStyle').val());
					});
					$("#modUber_select").live("click", function(){
						$('#modUberStyle').select();
					});
					$("#modUber_revert").live("click", function(){
						$('style:first').text(defaultU);
						$('#modUberStyle').val(defaultU);
					});
					$("#modUber_close").live("click", function(){
						$('style:first').text(defaultU);
						$('#modUberStyle').val(defaultU);
						$('#modUber').slideUp('normal');
					});
				}
    		});
    	}
	});
})(jQuery);
