function Modal() {
    this.title = null;
    this.message = null;
    this.callback = null;
    
    this.pageblock = null;
    this.dlg = null;
    this.dlgCenter = null;
    
    this.close = function () {
        document.body.removeChild(this.pageblock);
        document.body.removeChild(this.dlg);
        
        if (this.callback != null)
            this.callback();
    }
    
    this.go = function () {
        this._setupDialog();
        this._setTitleAndMessage();
        
        // OK button
        elem = document.createElement("p");
        elem.className = "buttons";
        this.dlgCenter.appendChild(elem);
        var button = document.createElement("a");
        button.href = "#";
        var _this = this;
        button.onclick = function () {
            _this.close();
            return false;
        };
        button.className = "button-ok";
        button.appendChild(document.createTextNode("OK"));
        elem.appendChild(button);
        
        elem.style.height = "28px";
        elem.style.margin = "0";
        
        this._centerDialog();
    };
    
    this.interstitial = function (url) {
        this._setupDialog();
        this._setTitleAndMessage();
        
        // OK & Cancel buttons
        elem = document.createElement("p");
        elem.className = "buttons";
        this.dlgCenter.appendChild(elem);
        
        var button = document.createElement("a");
        button.href = "#";
        var _this = this;
        button.onclick = function () {
            _this.close();
            return false;
        };
        button.className = "button-cancel";
        button.appendChild(document.createTextNode("Cancel"));
        elem.appendChild(button);
        
        var button = document.createElement("a");
        button.href = url;
        var _this = this;
        button.onclick = function () {
            window.open(url);
            _this.close();
            return false;
        };
        button.className = "button-ok";
        button.appendChild(document.createTextNode("OK"));
        elem.appendChild(button);
        
        elem.style.height = "28px";
        elem.style.margin = "0";
        
        this._centerDialog();
    };
    
    this._setupDialog = function () {
        // Setup page blocking div
        this.pageblock = document.createElement("div");
        this.pageblock.id = "pageblock";
        $(this.pageblock).setOpacity(0.5);
        document.body.appendChild(this.pageblock);
        
        // Setup modal div
        this.dlg = document.createElement("div");
        this.dlg.id = "modal";
        
        var div = document.createElement("div");
        div.className = "top";
        this.dlg.appendChild(div);
        
        div = this.dlgCenter = document.createElement("div");
        div.className = "center";
        this.dlg.appendChild(div);
        
        div = document.createElement("div");
        div.className = "bottom";
        this.dlg.appendChild(div);
        
        document.body.appendChild(this.dlg);
    };
    
    this._centerDialog = function () {
        var dlgSize = $(this.dlg).getSize();
        var windowSize = window.getSize();
        
        var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
		if (rslt != null && Number(rslt[1]) < 7.0) {
		    this.pageblock.style.top = windowSize.scroll.y + "px";
            this.pageblock.style.left = windowSize.scroll.x + "px";
		    this.dlg.style.top = (((windowSize.size.y - dlgSize.size.y) / 2) + windowSize.scroll.y) + "px";
            this.dlg.style.left = (((windowSize.size.x - dlgSize.size.x) / 2) + windowSize.scroll.x) + "px";
		} else {
            this.dlg.style.top = ((windowSize.size.y - dlgSize.size.y) / 2) + "px";
            this.dlg.style.left = ((windowSize.size.x - dlgSize.size.x) / 2) + "px";
        }
    };
    
    this._setTitleAndMessage = function () {
        // Title
        if (this.title != null) {
            var elem = document.createElement("h2");
            elem.appendChild(document.createTextNode(this.title));
            this.dlgCenter.appendChild(elem);
        }
        
        // Message
        if (this.message != null) {
            var arr = this.message.split('\n');
            for (var i=0; i<arr.length; i++) {
                elem = document.createElement("p");
                elem.appendChild(document.createTextNode(arr[i]));
                this.dlgCenter.appendChild(elem);
            }
        }
    }
}

var curr_gallery = 0;
var galleries = [
    // Main gallery
    {
        index: 0,
        cache: null,
        base: "",
        gallery_container: "gallery",
        image_container: "galleryImageContainer",
        caption_container: "caption",
        images: [
            "Al_Pierce.jpg",
		        "Alise_Jordan.jpg",
		        "Anthony_Parker_Alexander.jpg",
		        "Bonita_Trams.jpg",
		        "Brenda_Burger.jpg",
		        "Chris_Vogelsang.jpg",
		        "Christina_Bone.jpg",
		        "David_Mendosa.jpg",
		        "Debbie_Iaconiello.jpg",
		        "Debbie_Stephens.jpg",
		        "Denise_Bautista.jpg",
		        "Don_Kelly.jpg",
		        "Dr_Pink.jpg",
		        "Ed_Elson.jpg",
		        "Ed_Tierney.jpg",
		        "Genie_Brazzeal.jpg",
		        "George_Andrews.jpg",
		        "James_Patnaude.jpg",
		        "Janet_Mamane.jpg",
		        "Jeananne_Hawking.jpg",
		        "Judith_Bobel.jpg",
		        "Karl_Baldwin.jpg",
		        "Kenneth_Greene.jpg",
		        "Lionel_and_Albina_Brown.jpg",
		        "Michael_Brzezinski.jpg",
		        "Renee_Harrison.jpg",
		        "Richard_Palmer.jpg",
		        "Ronnie_Shea.jpg",
		        "Rudy_Moyado.jpg",
		        "Sam_Hundley.jpg",
		        "Sara_Hampton.jpg",
		        "Shirlesia_Hawkins-Dembley.jpg",
		        "Shirley_Little.jpg",
		        "Thomas_Haas.jpg",
		        "Travis_Grubbs.jpg",
		        "Yale_Kanter.jpg"
		        ],
        captions: [
            "<p class=\"captionTitle\">Al Pierce</p><p class=\"captionText\">Since returning to the U.S. after living and working in sales in Asia for more than 10 years, <strong>Al Pierce</strong>, 64, of Tampa, Florida, has begun following the diet and exercise advice of his doctor. Al enjoys traveling the world with his wife.  He recently returned from the Western Mediterranean and North Africa and looks forward to his next trip.</p>",
			      "<p class=\"captionTitle\">Alise Jordan</p><p class=\"captionText\">As a mother of three children, <strong>Alise Jordan</strong>, 39, of Cherry Hill, New Jersey, understands the importance of managing her type 2 diabetes.  Always dedicated to eating well and exercising, she was surprised when diagnosed with diabetes during her third pregnancy, but she knows she is capable of managing her disease.  Alise continues to manage her diabetes and is now a proud mother of four.</p>",
			      "<p class=\"captionTitle\">Anthony Alexander</p><p class=\"captionText\">The last few years of 44-year-old <strong>Anthony \"Parker\" Alexander\'s</strong> life have been filled with change.  The host of \"Parker After Dark\" and editor/publisher of the online magazine Urban, in Cleveland, Ohio, Parker saw his type 2 diabetes diagnosis as an opportunity to educate  others who were recently diagnosed.  After researching how prevalent diabetes is in the African-American population, Parker decided to start a magazine focused on what he calls \"an epidemic.\"</p>",
			      "<p class=\"captionTitle\">Bonita Trams</p><p class=\"captionText\">Even at 52, Springfield, Illinois native <strong>Bonita Trams</strong> is constantly learning &#150; whether it's about how to manage her type 2 diabetes care or studying for her Master\'s degree in History.  While earning three degrees in six years, Bonita has learned to monitor her diabetes and watch her diet.</p>",
			      "<p class=\"captionTitle\">Brenda Burger</p><p class=\"captionText\">When she was a child, 50-year-old <strong>Brenda Burger</strong> of Catasauqua, Pennsylvania saved her lunch money to buy candy.  But once she was diagnosed with type 2 diabetes, she stopped buying candy and adjusted her diet as a first step.</p>",
			      "<p class=\"captionTitle\">Chris Vogelsang</p><p class=\"captionText\">Already an established co-leader of a diabetes support group before she was diagnosed herself, <strong>Chris Vogelsang</strong>, of Cincinnati, Ohio, might have seen her diagnosis as bitter irony.  But for Chris, having type 2 diabetes afforded her the opportunity to heed the counsel she had been giving others for years.  Dedicated to managing her diabetes, she now benefits personally from the support group she leads, while adding a personal perspective in helping others manage their care.</p>",
			      "<p class=\"captionTitle\">Christina Bone</p><p class=\"captionText\"><strong>Christina Bone</strong>, 38, of Pittsburgh, Pennsylvania, calls herself an \"exercise freak.\" She was diagnosed with type 2 diabetes more than 10 years ago, when she noticed symptoms following a hospital stay for asthma. When Christina was diagnosed she was determined to learn all she could to manage her diabetes. That education process included changing her eating habits and exercising daily.</p>",
			      "<p class=\"captionTitle\">David Mendosa</p><p class=\"captionText\"><strong>David Mendosa</strong> of Boulder, Colorado, is a writer for the popular diabetes Web site My Diabetes Central.  An avid hiker for decades, David is dedicated to healthy living and was not expecting his type 2 diabetes diagnosis in 1994.  David is still facing new challenges, including a recent hike to an altitude of 12,550 feet along the Continental Divide in Colorado &#150; the highest elevation he has ever reached.</p> ",
			      "<p class=\"captionTitle\">Debbie Iaconiello</p><p class=\"captionText\">When <strong>Debbie Iaconiello</strong>, 42, of Waterford, Connecticut, was diagnosed with type 2 diabetes in 2005, it came as no surprise, since her job kept her sedentary all day, and her mother had struggled with diabetes for most of her life.  Debbie decided to try and improve her health by watching her diet, hiring a personal trainer and taking daily walks and bike rides along the shore near her home.</p> ",
			      "<p class=\"captionTitle\">Debbie Stephens</p><p class=\"captionText\"><strong>Debbie Stephens</strong>, 52, of Merrillville, Indiana, has been through the ups and downs of diabetes.  Diagnosed with type 2 diabetes during her pregnancy with her son, she also suffered from several strokes.  Debbie had to prove to herself that she could become independent again, free from her house and the stigma of diabetes. She changed her mindset and took charge of her medication, exercise and eating habits.  Now, Debbie is back at work, swimming and exercising regularly, and taking her medication.</p> ",
			      "<p class=\"captionTitle\">Denise Bautista</p><p class=\"captionText\">For years, <strong>Denise Bautista</strong>, 38, of Indianapolis, Indiana, struggled with managing her type 2 diabetes care.  She eventually learned how to better understand her body and her medications.  She returned to work and spends her free time playing with her two children.</p> ",
			      "<p class=\"captionTitle\">Don Kelly</p><p class=\"captionText\"><strong>Don Kelly</strong>, 53, was diagnosed with type 2 diabetes more than 10 years ago while working as a disaster recovery specialist.  He soon realized the stress of the position was taking a toll on his overall health.  Focused on managing his care, Don left his job and took a position at the local community theater near his hometown of Vallejo, California.</p> ",
			      "<p class=\"captionTitle\">Dr. Heinz-Guenther Pink</p><p class=\"captionText\">A resident of Honolulu for almost 50 years, <strong>Dr. Heinz-Guenther Pink</strong> has always appreciated Hawaii\'s natural beauty.  Since being diagnosed with type 2 diabetes, he now also enjoys the nearby beaches for exercise.  Since experiencing some vision loss, he has become an advocate and program evaluator for the blind, deaf and handicapped and served on Senator Chun Oakley\'s Deaf-Blind Task Force.</p> ",
			      "<p class=\"captionTitle\">Ed Elson</p><p class=\"captionText\"><strong>Ed Elson</strong>, of Anaheim, California, has learned that accepting change is part of living with type 2 diabetes.  Ed has embraced new diet and exercise habits.  Maintaining his diet, exercise and treatment regimen allows him to enjoy his passion for sailing, including a recent boat trip around Greece with his wife and friends.</p> ",
			      "<p class=\"captionTitle\">Ed Tierney</p><p class=\"captionText\">Born without a kidney, <strong>Ed Tierney</strong>, 52, of South Hadley, Massachusetts, has always faced health challenges.  After a recent kidney transplant, he was diagnosed with type 2 diabetes and viewed his diagnosis as his latest challenge.  Ed has a life-long dedication to taking good care of himself, including sticking to his diabetes care regimen and exercising.  Today, he is determined to continue managing his diabetes.</p> ",
			      "<p class=\"captionTitle\">Genie Brazzeal</p><p class=\"captionText\">Having witnessed her father\'s fight with diabetes and its complications, including the loss of a leg, <strong>Genie Brazzeal</strong>, 49, of Savannah, Georgia, is inspired to be proactive and manage her own type 2 diabetes. Genie values the importance of new information about treatment options and regularly discussing her treatment regimen with her doctors. She bike rides across Georgia and Ireland.</p> ",
			      "<p class=\"captionTitle\">George Andrews</p><p class=\"captionText\">A 58-year-old amateur athlete with type 2 diabetes, <strong>George Andrews</strong> of Seymour, Connecticut understands the importance of managing his health.  He has always approached life willing to test his limits, and after his diagnosis, George made the necessary changes to balance his diabetes with his passion for adventure.  Along with regular exercise, George stays conscious of his diet and is diligent about checking his blood sugar.  Having completed races on roads, trails and snow shoes, his next goal is to mountain bike across the country.</p> ",
			      "<p class=\"captionTitle\">James Patnaude</p><p class=\"captionText\">When Harlem, New York resident <strong>James Patnaude</strong>, 58, was diagnosed with type 2 diabetes at a local health fair, he made immediate changes to his diet and began taking daily walks to stay active.  Though he admits to having a sweet tooth, James is determined to monitor his health and speaks with his friend, Renee Harrison, who also has type 2 diabetes.</p> ",
			      "<p class=\"captionTitle\">Janet Mamane</p><p class=\"captionText\">A self-proclaimed sugar junkie, 62-year-old Bradenton, Florida resident <strong>Janet Mamane</strong> was diagnosed with type 2 diabetes.  Since her diagnosis, she has modified her diet and finds support in online diabetes care groups.</p> ",
			      "<p class=\"captionTitle\">Jeananne Hawking</p><p class=\"captionText\">Since being diagnosed with type 2 diabetes more than 10 years ago, <strong>Jeananne Hawking</strong>, 44, of Little Rock, Arkansas, has been dedicated to a strict diet and exercise plan.  When a friend was recently diagnosed, Jeananne swung into action, offering valuable advice about her friend\'s grocery shopping list, including which foods to buy and which to avoid.</p> ",
			      "<p class=\"captionTitle\">Judith Bobel</p><p class=\"captionText\">Registered Nurse <strong>Judith Bobel</strong>, 48, of Pittsburgh, Pennsylvania, made changes in her life, focusing on exercise and her treatment, after being diagnosed with type 2 diabetes, while also suffering from liver and kidney disease.  Judith began to exercise, walk and bike daily, in addition to participating in community service programs.</p> ",
			      "<p class=\"captionTitle\">Karl Baldwin</p><p class=\"captionText\"><strong>Karl Baldwin</strong>, 50, of Bridgewater, New Jersey, knew nothing about his family\'s medical history until he was diagnosed with type 2 diabetes in 1992.  Some research uncovered a history of diabetes on both sides of his family.  Armed with this knowledge, Karl began to take his overall health, and particularly his diabetes care, more seriously.  He enjoys fishing, hunting and swimming.</p> ",
			      "<p class=\"captionTitle\">Kenneth Greene</p><p class=\"captionText\"><strong>Kenneth Greene</strong>, 47, of Chicago, learned he had diabetes several years ago. Upon diagnosis, he re-evaluated his life to figure out what was important to him, which included being there for his family. So, in addition to continuing to bicycle regularly, his big change was learning to keep up with his diabetes treatment and to watch his diet. Kenneth also took on the role of assistant coach on his daughter/'s softball team.</p> ",
			      "<p class=\"captionTitle\">Lionel and Albina Brown</p><p class=\"captionText\">Having met later in life, <strong>Lionel and Albina Brown</strong>, of Villa Park, Illinois, understand the importance of staying healthy to help ensure that they grow old together.  Albina\'s diagnosis of diabetes inspired Lionel to go to the doctor, where he found out that he had diabetes, too.  Having been together for more than eight years, the couple completely changed their diet and exercise regimens.  Now, they work together to exercise and keep their diets on track as part of a diabetes management plan.</p> ",
			      "<p class=\"captionTitle\">Michael Brzezinski</p><p class=\"captionText\"><strong>Michael Brzezinski</strong>, 50, of Prairie du Sac, Wisconsin, was diagnosed with type 2 diabetes more than 13 years ago.  Despite a family history of diabetes, he was surprised by the diagnosis.  In search of further information, he ran across a local coalition that educates Wisconsin residents about the signs and symptoms of diabetes through local screening events.  Michael has begun monitoring his diet, exercising and taking daily medication.  He now serves as the business representative on the local coalition board.</p> ",
			      "<p class=\"captionTitle\">Renee Harrison</p><p class=\"captionText\">Diagnosed with type 2 diabetes more than 10 years ago, <strong>Renee Harrison</strong>, 43, of Harlem, New York, began to exercise more and cut starches out of her diet to gain control of her health.  She now also gets support from her friend, James Patnaude, who was recently diagnosed.</p> ",
			      "<p class=\"captionTitle\">Richard Palmer</p><p class=\"captionText\">After 10 years of living with type 2 diabetes, retired Navy Officer <strong>Richard Palmer</strong>, of San Diego, California, feared he was beginning to get complacent with his care.  With a renewed commitment to staying well-educated on diabetes care, Richard has recently completed a local diabetes education course.</p> ",
			      "<p class=\"captionTitle\">Ronnie Shea</p><p class=\"captionText\"><strong>Ronnie Shea</strong> refuses to let her type 2 diabetes stand in the way of her dreams.  A photographer who formerly worked as a DJ and an insurance salesperson, the 48-year-old resident of Mansfield, Texas, recently returned to college to become a registered nurse.  Upon completion of her degree, Ronnie and her husband plan to begin a two-and-a-half-year adventure as volunteers in the Peace Corps.</p> ",
			      "<p class=\"captionTitle\">Rudy Moyado</p><p class=\"captionText\">Being diagnosed with type 2 diabetes, the same disease that took his mother, <strong>Rudy Moyado</strong>, 51, of Portage, Indiana, knew he needed to face his disease.  He got off the couch and began to exercise.  Facing difficult life changes, Rudy learned to follow an exercise program, take his medication and adjust his diet.  More than 15 years later, Rudy is still following his routine and has participated in seven Chicago Marathons, with more on the way.</p> ",
			      "<p class=\"captionTitle\">Sam Hundley</p><p class=\"captionText\">With food as a focal point in his life, <strong>Sam Hundley</strong>, 61, of Chicago, took a new perspective on how he lived when he was diagnosed with type 2 diabetes in 1997.  As an amateur chef, he knew he had to make major changes &#150; beginning with his diet.  Not giving up his love of food, Sam instead refocused his skills and began learning how to incorporate different kinds of fruits and vegetables in his diet and change his diet to support his life with diabetes.</p> ",
			      "<p class=\"captionTitle\">Sara Hampton</p><p class=\"captionText\">For more than 10 years, <strong>Sara Hampton</strong>, 35, of Tacoma, Washington, was in denial about living with type 2 diabetes.  It wasn\'t until her daughter proclaimed, \"I\'m tired of Mom being sick,\" that Sara realized ignoring her diabetes care was affecting her entire family.  Now, she has a newfound dedication to diabetes management that includes careful control of her diet, an exercise regimen and daily medications.</p> ",
			      "<p class=\"captionTitle\">Shirlesia Hawkins-Dembley</p><p class=\"captionText\">Fourteen years after she was diagnosed with type 2 diabetes, <strong>Shirlesia Hawkins-Dembley</strong>, 44, of Minneapolis, was determined to turn her health around for her three children. Through the help of her doctor and a nutritionist she began to take her diabetes care more seriously.  Shirlesia is dedicated to her new diet and exercise regimen and refuses to fall back into her old habits.  She enjoys playing outside with her children, kickboxing and being involved in a leadership training program.</p> ",
			      "<p class=\"captionTitle\">Shirley Little</p><p class=\"captionText\"><strong>Shirley Little</strong>, 53, of Clayton, North Carolina, credits her coworkers with helping her manage her type 2 diabetes.  Working for a diabetes care company, she often seeks out the advice of the medical professionals she works with.  Since her type 2 diabetes diagnosis, Shirley says everyone in the office has been looking out for her and \"making sure she follows the rules at lunchtime.\"</p> ",
			      "<p class=\"captionTitle\">Thomas Haas</p><p class=\"captionText\">When <strong>Thomas Haas</strong>, 61, of Minneapolis, was first diagnosed with type 2 diabetes, he wasn\'t sure how he was going to deal with the diagnosis.  Thomas soon found the motivation to take steps toward improving his health, including taking daily walks with his neighbor.  Thomas is working to improve his diabetes through diet and exercise.  He enjoys gardening and collecting books, stamps and antiques.</p> ",
			      "<p class=\"captionTitle\">Travis Grubbs</p><p class=\"captionText\">Diagnosed with type 2 diabetes in May 2006, <strong>Travis Grubbs</strong>, 45, a home inspector from Statesboro, Georgia, adopted a new diet and exercise regimen.  Determined to maintain the dedication toward a healthy lifestyle he implemented when first diagnosed, Travis speaks to his doctor once a month to provide updates on his progress.</p> ",
			      "<p class=\"captionTitle\">Yale Kanter</p><p class=\"captionText\">A long family history of diabetes encouraged <strong>Yale Kanter</strong> to test his blood sugar twice a year before he was diagnosed with type 2 diabetes.  Yale always knew the value of properly managing his health, and once diagnosed, he learned how to cook meals for himself and his family.  As an educator at a V.A. clinic, he now teaches others about the importance of diabetes care.</p>"
            ]
    },
    
    // Additional photos
    {
        index: 0,
        cache: null,
        base: "additional_image/",
        gallery_container: "addition_gallery",
        image_container: "add_galleryImageContainer",
        caption_container: "add_caption",
        images: [
            "Ben_Pearlman.jpg",
			"George_Salisbury.jpg",
			"Polly_Kranzusch.jpg",
			"Ruth_Palmer.jpg"
            ],
        captions: [
            "<p class=\"captionTitle\">Ben Pearlman</p><p class=\"captionText\">Because his father had type 2 diabetes, <strong>Ben Pearlman</strong>, 81, of Las Vegas, Nevada, immediately recognized the warning signs, enabling early detection of his diabetes.  More than 40 years later, Ben remains diligent about monitoring his health.  Ben maintains a low-carbohydrate diet, and to stay active, he enjoys spending time caring for his cactus garden.</p>",
			      "<p class=\"captionTitle\">George Salisbury</p><p class=\"captionText\">World War II veteran <strong>George Salisbury</strong>, 86, of Slater, Colorado, was diagnosed with type 2 diabetes in 2005.  He has had to make some changes to his diet, including cutting out his usual mid-afternoon snack of cookies and milk, which he still misses.  But George knows that he must follow his diabetes care plan.</p> ",
			      "<p class=\"captionTitle\">Polly Kranzusch</p><p class=\"captionText\"><strong>Polly Kranzusch</strong>, 68, of Montgomery, Alabama, is a fighter.  Having previously won a battle with liver cancer, she knows she can continue to manage her type 2 diabetes care.  Polly has been fighting diabetes for more than 17 years and makes sure to take her medicine everyday.  She enjoys the time she gets to spend with her four grandchildren.</p> ",
			      "<p class=\"captionTitle\">Ruth Palmer</p><p class=\"captionText\">In 2006, 94-year-old <strong>Ruth Palmer</strong>, of Blissfield, Michigan, who has type 2 diabetes, decided to move into an assisted living facility. The relocation has proven beneficial to Ruth’s social life – she stays active through a strength program the community offers, and she has built a reputation as one of the best card players in the area.</p> "
            ]
    },
    
    // New faces
    {
        index: 0,
        cache: null,
        base: "new_faces/",
        gallery_container: "gallery",
        image_container: "galleryImageContainer",
        caption_container: "caption",
        images: [
            "Annetta_Jutila.jpg",
            "Barbara_Palmer.jpg",
            "Regina_Parks.jpg",
            "Robert_Gardner.jpg"
            ],
        thumbnails: [
            "Annetta_Jutila.png",
            "Barbara_Palmer.png",
            "Regina_Parks.png",
            "Robert_Gardner.png"
            ],
        captions: [
            "<p class=\"captionTitle_newFOC_large\">Annetta Jutila</p><p class=\"captionText\">Diagnosed with type 2 diabetes one year ago, <strong>Annetta Jutila</strong>, 65, of Sun City Grand in Surprise, Arizona, knows the importance of health screenings. Even though she wasn&rsquo;t experiencing any symptoms related to diabetes, she learned her blood sugar was higher than the normal range from a glucose test performed in her local pharmacy. When she confirmed with her doctor that she has type 2 diabetes, she made a commitment to exercise more and prepare healthy meals for her and her husband. Walking, bike riding, playing golf, and paying more attention to food nutrition labels are just some of the changes she has built into her lifestyle.</p><p class=\"captionText\">Photo by Emily Carroll</p>",
            "<p class=\"captionTitle_newFOC_large\">Barbara Palmer</p><p class=\"captionText\">People who knew <strong>Barbara Palmer</strong> 20 years ago may not recognize her today. Since being diagnosed with type 2 diabetes 22 years ago, she has lost a total of 170 pounds, but it hasn&rsquo;t always been easy. Barbara, 59, has had cycles of extreme weight loss and gain, but in 2005 when doctors warned her she was at risk for health problems in addition to her diabetes, she decided it was time to get serious. She has kept the weight off for a full year and now weighs herself every week to stay motivated to maintain what she calls a &ldquo;whole new lifestyle,&rdquo; which she describes as eating a healthier diet and exercising daily, including swimming three or four times a week.</p><p class=\"captionText\">Photo by Richard Coade</p>",
            "<p class=\"captionTitle_newFOC_large\">Regina Parks</p><p class=\"captionText\">Having maintained an active lifestyle through swimming and golfing, <strong>Regina Parks</strong>, resident of Sun City Summerlin in Las Vegas, was surprised when first diagnosed with type 2 diabetes during a routine check-up.  Since then, Gina, age 65, has made changes including taking insulin to help manage her diabetes and staying motivated by walking her new puppy, Shannon.</p><p class=\"captionText\">Photo by Sharon Sampsel</p>",
            "<p class=\"captionTitle_newFOC\">The Newest Face of Change</p><p class=\"captionTitle_newFOC_large\">Robert Gardner</p><p class=\"captionText\">Former high school football captain <strong>Robert Gardner</strong>, 52, was first diagnosed with type 1 diabetes at age 15. Since then, he has been focused on leading a happy, healthy life that includes proper diabetes management and spending time with his daughter. Robert is so committed to helping others with diabetes that he now spends time visiting local hospitals to speak with children who have been recently diagnosed. He continues to manage his own diabetes through insulin, careful monitoring, and regular exercise.</p><p class=\"captionText\">Photo by Tim Soter</p>"
            ]
    }
];

for (var i=0; i<galleries.length; i++)
    galleries[i].cache = new Array(galleries[i].images.length);

function processPrevious(){
    var gallery = galleries[curr_gallery];
	if (document.images) {
		if (gallery.index > 0)
			gallery.index--;
		else if (gallery.index == 0)
			gallery.index = gallery.images.length - 1;
		
		goToImage();
	}
}

function processNext(){
    var gallery = galleries[curr_gallery];
	if (document.images) {
		if (gallery.index < (gallery.images.length - 1))
			gallery.index++;
		else if (gallery.index == (gallery.images.length - 1))
			gallery.index = 0;
		
		goToImage();
	}
}

function showGallery(gallery_index, target_index) {
    if (gallery_index < 0)
        curr_gallery = 0;
    else if (gallery_index >= galleries.length)
        curr_gallery = galleries.length - 1;
    else
        curr_gallery = gallery_index;
    
    var gallery = galleries[curr_gallery];
	if (target_index < 0)
        gallery.index = 0;
    else if (target_index >= gallery.images.length)
        gallery.index = gallery.images.length - 1;
    else
        gallery.index = target_index;
    
    var prev = $("previous");
    var next = $("next");
    if (gallery.images.length == 1) {
        prev.setStyles({
            display: "none"
        });
        next.setStyles({
            display: "none"
        });
    } else {
        prev.setStyles({
            display: "block"
        });
        next.setStyles({
            display: "block"
        });
    }
    
	goToImage();
	document.getElementById('background').style.display='block';
	document.getElementById(gallery.gallery_container).style.display='block';
}

function loadCurrentGalleryImageAndDisplayPopup() {
    var gallery = galleries[curr_gallery];
	var gallery_container = $(gallery.gallery_container);
    var image_container = $(gallery.image_container);
    var image = gallery.cache[gallery.index];
    
    var callback = function() {
	    image_container.empty();
        image_container.appendChild(image);
        
        // Prep the popup for showing
	    gallery_container.setStyles({
	        visibility: "hidden",
	        display: "block"
	    });
    	
    	// Move window if necessary
	    var window_size = window.getSize();
	    var gallery_size = gallery_container.getSize();
	    var gallery_pos = gallery_container.getPosition();
	    var x = (window_size.size.x - gallery_size.size.x) / 2;
	    var y = (window_size.size.y - gallery_size.size.y) / 2;
	    if (x < 0)
	        x = 0;
	    if (y < 0)
	        y = 0;
	    var diff = gallery_pos.x - x;
	    if (diff > 20 || diff < -20)
	        gallery_container.setStyle("left", x);
	    diff = gallery_pos.y - y;
	    if (diff > 20 || diff < -20)
	        gallery_container.setStyle("top", y);
    	
    	gallery_container.setStyle("visibility", "visible");
    };
    
    if (image != null) {
        // Use cached image
        callback();
	    return;
    }
    
    var curr_image = image_container.getElements("img");
    if (curr_image.length > 0) {
        var image_container_size = curr_image[0].getSize();
        image_container.empty();
        image_container.appendChild(new Element("div", {
            "class": "modal_image_filler",
            "styles": {
                "width": image_container_size.size.x,
                "height": image_container_size.size.y,
                "margin-left": "auto",
                "margin-right": "auto"
            }
        }));
    }
    
    // Load image
	image = new Image();
	image.src = "http://www.faceofchange-us.com/mint/pepper/tillkruess/downloads/tracker.php?uri=http://www.faceofchange-us.com/images/slideshow/" + gallery.base + gallery.images[gallery.index];
	
	// Wait for image to load before displaying popup
	var date = new Date();
	var stopTime = date.getTime() + 60000;
	var interval = setInterval(function() {
	    // Check that we haven't gone past our allotted wait time
	    var date = new Date();
	    if (date.getTime() >= stopTime) {
	        clearInterval(interval);
	        alert("The image couldn't be loaded.  Please try again later.");
	        return;
	    }
	    
	    if (!image.complete)
	        return;
	    
	    // Stop checking for the image
	    clearInterval(interval);
	    
	    // Cache and show image
	    gallery.cache[gallery.index] = image;
	    
	    // Show popup
	    callback();
	}, 200);
}

function goToImage() {
    var gallery = galleries[curr_gallery];
    document.getElementById(gallery.caption_container).innerHTML = gallery.captions[gallery.index];
	loadCurrentGalleryImageAndDisplayPopup();
}

function closeGallery() {
    var gallery = galleries[curr_gallery];
	document.getElementById('background').style.display='none';
	$(gallery.gallery_container).setStyles({
	    display: "none",
	    visibility: "hidden"
	});
	document.getElementById(gallery.caption_container).innerHTML = '';
}

function createThumbnails() {
	var strThumbnails='';
	var startX=0;
	var startY=-76;
	var endX=74;
	var endY=-8;

	for (i=0;i<galleries[0].images.length;i++) {
		if (i%9==0) {
			startX=0;
			endX=74;
			startY=startY+81;
			endY=endY+84;
		} else {
			startX=startX+84;
			endX=endX+84;
		}
		strThumbnails=strThumbnails + '<area coords=\"'+startX+','+startY+','+endX+','+endY+'\" href=\"#\" onclick=\"showGallery(0, '+i+'); return false;\" />';
	}
	
	var thumbnails = $('thumbnails');
	if (thumbnails == null)
	    return;
	
	thumbnails.empty();
	thumbnails.innerHTML=strThumbnails;
}

var modal_clwd = new Modal();
modal_clwd.message = "You are about to enter CLWD.com, a web site created to help people with diabetes better manage their disease.\nYou may review the site's various community features and disease-management resources, and sign in or register to use those resources in managing your diabetes.\nClick the OK button below to enter CLWD.com.";

var modal_ask = new Modal();
modal_ask.message = "You are about to enter AskScreenKnow.com, a web site encouraging people enrolled in Medicare who are at risk to ask their healthcare provider for a free diabetes screening and to know their blood sugar numbers and what actions to take.\nClick the OK button below to enter AskScreenKnow.com.";

function createAdd_Thumbails(){
	var strThumbnails='';
	var startX=0;
	var startY=-50;
	var endX=60;
	var endY=-8; 
	
	for (i=0;i<galleries[1].images.length;i++) {
		if (i%4==0) {
			startX=0;
			endX=50;
			startY=startY+50;
			endY=endY+60;
		}else {
			startX=startX+65;
			endX=endX+65;
		}
		strThumbnails=strThumbnails + '<area coords=\"'+startX+','+startY+','+endX+','+endY+'\" href=\"#\" onclick=\"showGallery(1, '+i+'); return false;\"/>';
	}
	
	var thumbnails = $('add_thumbnails');
	if (thumbnails == null)
	    return;
	
	thumbnails.empty();
	thumbnails.innerHTML=strThumbnails;
}

window.addEvent('domready', function() {
    var menu_container = $("pi-dropdown-container");
    var menu = $("pi-dropdown");
    var trigger = $("header-pi");
    var background = $("background");
    
    if (menu_container == null || menu == null || trigger == null)
        return;
    
    menu_container.setStyle("display", "block");
    
    // Set opacity for background element
    if (background != null)
        $("background").setStyle("opacity", 0.5);
    
    // Effect for PI dropdown
    var fx = new Fx.Slide(menu, {
        duration: 400,
        onComplete: function () {
            if (this.open == true)
                $("pi-spacer").style.display = "none";
        }
    });
    fx.target = menu;
    fx.hide();
    
    // Setup mouse event triggers for menu behavior
    trigger.addEvent('click', function(e){
        new Event(e).stop();
    });
    
    trigger.addEvent('mouseenter', function(e){
        trigger.style.backgroundPosition = "right bottom";
        $("pi-spacer").style.display = "block";
        fx.slideIn();
    });
    
    menu_container.addEvent('mouseleave', function(e){
        trigger.style.backgroundPosition = "right top";
        fx.slideOut();
    });
    
    // Setup galleries
    createThumbnails();
    createAdd_Thumbails();
});

function set_element_background_image(elem, image)
{
  elem.style.backgroundImage = "url('" + image + "')";
}
