function addCommas(nStr)
{
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}

$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).slideDown('slow').addClass(c); },
            function() { $(this).removeClass(c); }
        );
        
    });
};

$.fn.clickClass = function(c) {
    return this.each(function(){
        $(this).click( 
            function() { 
            	if ($(this).attr('class') == c)
    			{
    				$(this).removeClass(c);
    			}
    			else
    			{
    				$(this).addClass(c);
    			}
             }
        );
        
    });
};

$(document).ready(
	
	function() 
	{
		/* KEEP CODE FROM HERE DOWN TO NEXT COMMENT BLOCK ON ALL PROJECTS */
		
		$('input#filename').keyup(function()
		{
			jQuery.ajax(
		   	{
		   		type: "GET",
		   		url: "/page/check_filename.html?filename=" + $(this).val() + '&old_filename='+$('#old_filename').val(),
		   		dataType: "html",
		   		timeout: 15000,
		   		error: function() {},
		   		success: function(r) {
		   								if (r == 'success')
		   								{
		   									$("#filename_status").attr({src: '/images/icons/accept.png'}); 
		   									if ($('input#title').val() != '') 
		   										$("#edit_submit").attr('disabled', false);
		   									$("#filename_text").html('');
		   								}
		   								else
		   								{
		   									$("#filename_status").attr({src: '/images/icons/delete.png'}); 
		   									$("#filename_text").html(r);
		   									$("#edit_submit").attr('disabled', true);
		   								}
		   							}
		   	});
		});
		
		$('input#title').keyup(function()
		{
			if ($(this).val() != '')
			{
				$("#title_status").attr({src: '/images/icons/accept.png'}); 
				if ($("#filename_status").attr('src') == '/images/icons/accept.png')
					$("#edit_submit").attr('disabled', false);
		   	}
		   	else
		   	{
		   		$("#title_status").attr({src: '/images/icons/delete.png'}); 
		   		$("#edit_submit").attr('disabled', true);
		   	}
		});
		
		$('.confirm_anchor').click(function()
		{
			return confirm('Are you SURE you want to do this???');
		});
		
		
		/* KEEP CODE FROM HERE UP TO PREVIOUS COMMENT BLOCK ON ALL PROJECTS*/

		if ($.browser.msie && $.browser.version < 7)
		{
			//alert('you are ie less than 7');
			//$("ul.nav li").click(function(){ $(this).fadeIn("fast"); }, function() { } );
			$("ul.nav li").clickClass ("hover");
		}
		else
		{
			//$("ul.nav li").hover(function(){ $(this).slideDown('slow'); }, function() { } );
			$("ul.nav li").hoverClass("hover");
		}
		

		$('#gen_phone_number').flash(null, {version: 7}, function(htmlOptions){
			var gen_phone_number = $(this);
			// Set options
			htmlOptions.src     = gen_phone_number.attr('rel');
			htmlOptions.width   = 190;
			htmlOptions.height  = 70;
			htmlOptions.quality = 'high';
			htmlOptions.wmode   = 'transparent';
			// Embed it!
			gen_phone_number.prepend($.fn.flash.transform(htmlOptions));
		});

		$('#surgery_phone_number').flash(null, {version: 7}, function(htmlOptions){
			var gen_phone_number = $(this);
			// Set options
			htmlOptions.src     = gen_phone_number.attr('rel');
			htmlOptions.width   = 190;
			htmlOptions.height  = 70;
			htmlOptions.quality = 'high';
			htmlOptions.wmode   = 'transparent';
			// Embed it!
			gen_phone_number.prepend($.fn.flash.transform(htmlOptions));
		});

		$('#ask_gilbert').flash(null, {version: 7}, function(htmlOptions){
			var gen_phone_number = $(this);
			// Set options
			htmlOptions.src     = gen_phone_number.attr('rel');
			htmlOptions.width   = 178;
			htmlOptions.height  = 121;
			htmlOptions.quality = 'high';
			htmlOptions.wmode   = 'transparent';
			// Embed it!
			gen_phone_number.prepend($.fn.flash.transform(htmlOptions));
		});

		$('#hours').flash(null, {version: 7}, function(htmlOptions){
			var gen_phone_number = $(this);
			// Set options
			htmlOptions.src     = gen_phone_number.attr('rel');
			htmlOptions.width   = 480;
			htmlOptions.height  = 75;
			htmlOptions.quality = 'high';
			htmlOptions.wmode   = 'transparent';
			// Embed it!
			gen_phone_number.prepend($.fn.flash.transform(htmlOptions));
		});

		// changer links when clicked
		$("a.changer").click(function(){
			<!-- jquery for this page -->
			//set the div with class mainText as a var called $mainText
				var $mainText = $('div#content');
			// set the current font size of .mainText as a var called currentSize
				var currentSize = $mainText.css('font-size');
			// parse the number value out of the font size value, set as a var called 'num'
				var num = parseFloat(currentSize, 10);
			// make sure current size is 2 digit number, save as var called 'unit'
				var unit = currentSize.slice(-2);
			// javascript lets us choose which link was clicked, by ID
				if (this.id == 'font_up'){
					num = num * 1.2;
				} else if (this.id == 'font_down'){
					num = num / 1.2;
				}
			// jQuery lets us set the font Size value of the mainText div
				$mainText.css('font-size', num + unit);
   			return false;
		});

		$("#example").accordion();
		$("#example2").accordion();
		
		$("#tabs > ul").tabs({ fxFade: true, fxSlide: true, fxSpeed: 'slow' });
		
		$('#tv_commercial').click(function()
		{
			$("#tv_commercial").replaceWith("<div id=\"tv_commercial\"><object type=\"application/x-shockwave-flash\" data=\"/flash/player_blue_home1.swf?movie=Eye_Center_TV_Commercial\" style=\"width: 450px; height: 333px;\"><param name=\"movie\" value=\"/flash/player_blue_home1.swf?movie=Eye_Center_TV_Commercial\"> <a href=\"http://www.adobe.com\"><img src=\"/images/download_flash.png\" alt=\"Get Flash Player\" style=\"border: 0px none ;\" height=\"333\" width=\"450\"></a> </object></div>");
		});
	}
);
