$(document).ready(function() {


	//COOKIE FUNCTIONS
	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}

	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}

	function eraseCookie(name) {
		createCookie(name,"",-1);
	}
	//COOKIE FUNCTIONS

	//IF VIEWING ON THE IPAD REMOVE THE PRINT BUTTON
	if(iPad()) $(".printButton").css({display: "none"});
	
    var barkerClicked = 0;

    //SELECT DEFAULT HOME PAGE IMAGE SLIDER DIV
    var defaultFrame = 2;


    //VARIABLES
    var divWidth;
    var displayVideos = 5;
    var keepSizeIsSet;
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /* This original function was creating over 200 cookies; we're loking for another solution to the dynamic font size functionality */
    /*$(function() {
    var zIndexNumber = 1;
    $('div').each(function(index) {
    $(this).css('zIndex', zIndexNumber);
    zIndexNumber += 10;
    (getCookie("keepSizes")) ? setFontSizes(this, index) : setCookie("div" + index, $(this).css("font-size"), 7);
    });
    });*/

    /* This is here for the time being */
    $(function() {
        var zIndexNumber = 1;
        $('.msie7 div').not('#ra-fit-kit-customization-form div').each(function(index) {
            $(this).css('zIndex', zIndexNumber);
            zIndexNumber += 10;

        });
    });

    $(function() {

        $('div').each(function(index) {

            (getCookie("keepSizes")) ? setFontSizes(this, index) : '';
        });
    });


    keepSizeIsSet = getCookie("currSize");
    //alert(keepSizeIsSet);

    //////////// CHANGE HOVER STATE TO POINTER FOR DIV'S THAT ARE BEING USED AS LINKS

    $(".hoverCursor").hover(function() {
        $(this).css({ cursor: 'pointer' });
    }, function() {
        $(this).css({ cursor: 'default' });
    });

    // HOME PAGE IMAGE SCROLLER
	var stack = 0;
    if ($("#popArticlesInnerHolder").length > 0) {

        divWidth = $(".diet").width(); //WIDTH OF THE DIVS.
        var startFrame = divWidth * defaultFrame;

        var colors = new Array();
        colors[0] = "green";
        colors[1] = "orange";
        colors[2] = "yellow";
        colors[3] = "blue";
        var i = 0;
        var clicked = true;

        $(".arrowRight").click(function(e) {
            e.preventDefault();
            
			//THIS WAS ORIGINALLY MEANT TO CALCULATE THE NUMBER OF BOXES AND DYNAMICALLY UPDATE THE SCROLLER
			//BYT JUST ADDED MORE BOXES. SINCE IE IS A BASTARD CHILD THIS HAD TO BE ALL DONE STATICALLY
			/*var pos = $("#popArticlesInnerHolder").position().left;
            var holderWidth = $("#popArticlesInnerHolder").width();
            var newpos = pos - divWidth;
            var result = pos % divWidth;
            if (BrowserDetect.browser === "Explorer" && pos < 0) newpos = newpos - 1; //IE JQUERY FIX.
            if (Math.abs(pos) >= (holderWidth - divWidth)) newpos = 0;
            if (clicked) {
                clicked = false;
                if (result === 0) {
                    $(this).animate({ opacity: 0 }, 150);
                    $(".arrowLeft").animate({ opacity: 0 }, 150, function() {
                        $("#popArticlesInnerHolder").animate({ left: newpos }, 250, function() {
                            if (i + 1 > 3) i = -1;
                            $("#img-prev").attr('src', 'images/icon-arrow-left-' + colors[i + 1] + '.jpg');
                            $("#img-next").attr('src', 'images/icon-arrow-right-' + colors[i + 1] + '.jpg');
                            (i === 3) ? i = 0 : i = i + 1;
                            $(".arrowRight").animate({ opacity: 1 }, 150, function() { clicked = true; });
                            $(".arrowLeft").animate({ opacity: 1 }, 150);
                        });

                    });

                }

            }*/
			
			//STATIC VERSION
			switch(stack)
			{
				case 0:
					if(clicked){
						clicked = false;
						$(".arrowLeft").animate({ opacity: 0 }, 150);
						$(".arrowRight").animate({ opacity: 0 }, 150, function() {
							$("#popArticlesInnerHolder").animate({ left: "-439px" }, 250, function() {
								if (i + 1 > 3) i = -1;
								$("#img-prev").attr('src', 'images/icon-arrow-left-' + colors[1] + '.jpg');
								$("#img-next").attr('src', 'images/icon-arrow-right-' + colors[1] + '.jpg');
								(i === 3) ? i = 0 : i = i + 1;
								$(".arrowRight").animate({ opacity: 1 }, 150, function() { clicked = true; stack = 1});
								$(".arrowLeft").animate({ opacity: 1 }, 150);
							});
						});
					}
				break;
				case 1:
					if(clicked){
						clicked = false;
						$(".arrowLeft").animate({ opacity: 0 }, 150);
						$(".arrowRight").animate({ opacity: 0 }, 150, function() {
							$("#popArticlesInnerHolder").animate({ left: "-878px" }, 250, function() {
								if (i + 1 > 3) i = -1;
								$("#img-prev").attr('src', 'images/icon-arrow-left-' + colors[2] + '.jpg');
								$("#img-next").attr('src', 'images/icon-arrow-right-' + colors[2] + '.jpg');
								(i === 3) ? i = 0 : i = i + 1;
								$(".arrowRight").animate({ opacity: 1 }, 150, function() { clicked = true; stack = 2});
								$(".arrowLeft").animate({ opacity: 1 }, 150);
							});
						});
					}
				break;
				case 2:
					if(clicked){
						clicked = false;
						$(".arrowLeft").animate({ opacity: 0 }, 150);
						$(".arrowRight").animate({ opacity: 0 }, 150, function() {
							$("#popArticlesInnerHolder").animate({ left: "-1317px" }, 250, function() {
								if (i + 1 > 3) i = -1;
								$("#img-prev").attr('src', 'images/icon-arrow-left-' + colors[3] + '.jpg');
								$("#img-next").attr('src', 'images/icon-arrow-right-' + colors[3] + '.jpg');
								(i === 3) ? i = 0 : i = i + 1;
								$(".arrowRight").animate({ opacity: 1 }, 150, function() { clicked = true; stack = 3});
								$(".arrowLeft").animate({ opacity: 1 }, 150);
							});
						});
					}
				break;
				case 3:
					if(clicked){
						clicked = false;
						$(".arrowLeft").animate({ opacity: 0 }, 150);
						$(".arrowRight").animate({ opacity: 0 }, 150, function() {
							$("#popArticlesInnerHolder").animate({ left: "-0px" }, 250, function() {
								if (i + 1 > 3) i = -1;
								$("#img-prev").attr('src', 'images/icon-arrow-left-' + colors[0] + '.jpg');
								$("#img-next").attr('src', 'images/icon-arrow-right-' + colors[0] + '.jpg');
								(i === 3) ? i = 0 : i = i + 1;
								$(".arrowRight").animate({ opacity: 1 }, 150, function() { clicked = true; stack = 0});
								$(".arrowLeft").animate({ opacity: 1 }, 150);
							});
						});
					}
				break;
			}
			

        }); //END ARROW RIGHT CLICK

        $(".arrowLeft").click(function(e) {
            e.preventDefault();
            
			//THIS WAS ORIGINALLY MEANT TO CALCULATE THE NUMBER OF BOXES AND DYNAMICALLY UPDATE THE SCROLLER
			//BYT JUST ADDED MORE BOXES. SINCE IE IS A BASTARD CHILD THIS HAD TO BE ALL DONE STATICALLY
			/*var pos = $("#popArticlesInnerHolder").position().left;
            var holderWidth = $("#popArticlesInnerHolder").width();
            var newpos = divWidth + pos;
            var result = pos % divWidth;

            if (pos === 0) newpos = (-(holderWidth - divWidth));
            if (BrowserDetect.browser === "Explorer" && newpos < -(divWidth) - 1) newpos = newpos - 1; //IE JQUERY FIX
            if (clicked) {
                clicked = false;
                if (result === 0) {
                    $(this).animate({ opacity: 0 }, 150);
                    $(".arrowRight").animate({ opacity: 0 }, 150, function() {
                        $("#popArticlesInnerHolder").animate({ left: newpos }, 250, function() {
                            if (i === 0) i = 4;
                            $("#img-prev").attr('src', '/images/icon-arrow-left-' + colors[Math.abs(i - 1)] + '.jpg');
                            $("#img-next").attr('src', '/images/icon-arrow-right-' + colors[Math.abs(i - 1)] + '.jpg');
                            i = i - 1;
                            $(".arrowRight").animate({ opacity: 1 }, 150);
                            $(".arrowLeft").animate({ opacity: 1 }, 150, function() { clicked = true; });
                        });

                    });

                }

            }*/
			
			//STATIC VERSION
			switch(stack)
			{
				case 0:
					if(clicked){
						clicked = false;
						$(".arrowLeft").animate({ opacity: 0 }, 150);
						$(".arrowRight").animate({ opacity: 0 }, 150, function() {
							$("#popArticlesInnerHolder").animate({ left: "-1317px" }, 250, function() {
								if (i + 1 > 3) i = -1;
								$("#img-prev").attr('src', 'images/icon-arrow-left-' + colors[3] + '.jpg');
								$("#img-next").attr('src', 'images/icon-arrow-right-' + colors[3] + '.jpg');
								(i === 3) ? i = 0 : i = i + 1;
								$(".arrowRight").animate({ opacity: 1 }, 150, function() { clicked = true; stack = 3});
								$(".arrowLeft").animate({ opacity: 1 }, 150);
							});
						});
					}
				break;
				case 1:
					if(clicked){
						clicked = false;
						$(".arrowLeft").animate({ opacity: 0 }, 150);
						$(".arrowRight").animate({ opacity: 0 }, 150, function() {
							$("#popArticlesInnerHolder").animate({ left: "0px" }, 250, function() {
								if (i + 1 > 3) i = -1;
								$("#img-prev").attr('src', 'images/icon-arrow-left-' + colors[0] + '.jpg');
								$("#img-next").attr('src', 'images/icon-arrow-right-' + colors[0] + '.jpg');
								(i === 3) ? i = 0 : i = i + 1;
								$(".arrowRight").animate({ opacity: 1 }, 150, function() { clicked = true; stack = 0});
								$(".arrowLeft").animate({ opacity: 1 }, 150);
							});
						});
					}
				break;
				case 2:
					if(clicked){
						clicked = false;
						$(".arrowLeft").animate({ opacity: 0 }, 150);
						$(".arrowRight").animate({ opacity: 0 }, 150, function() {
							$("#popArticlesInnerHolder").animate({ left: "-439px" }, 250, function() {
								if (i + 1 > 3) i = -1;
								$("#img-prev").attr('src', 'images/icon-arrow-left-' + colors[1] + '.jpg');
								$("#img-next").attr('src', 'images/icon-arrow-right-' + colors[1] + '.jpg');
								(i === 3) ? i = 0 : i = i + 1;
								$(".arrowRight").animate({ opacity: 1 }, 150, function() { clicked = true; stack = 1});
								$(".arrowLeft").animate({ opacity: 1 }, 150);
							});
						});
					}
				break;
				case 3:
					if(clicked){
						clicked = false;
						$(".arrowLeft").animate({ opacity: 0 }, 150);
						$(".arrowRight").animate({ opacity: 0 }, 150, function() {
							$("#popArticlesInnerHolder").animate({ left: "-878px" }, 250, function() {
								if (i + 1 > 3) i = -1;
								$("#img-prev").attr('src', 'images/icon-arrow-left-' + colors[2] + '.jpg');
								$("#img-next").attr('src', 'images/icon-arrow-right-' + colors[2] + '.jpg');
								(i === 3) ? i = 0 : i = i + 1;
								$(".arrowRight").animate({ opacity: 1 }, 150, function() { clicked = true; stack = 2});
								$(".arrowLeft").animate({ opacity: 1 }, 150);
							});
						});
					}
				break;
			}

        }); //END ARROW LEFT CLICK


        //ANIMATE TO DEFAULT FRAME. 
        $("#popArticlesInnerHolder").animate({ left: -(divWidth * (defaultFrame - 1)) }, 250, function() {
            if (i + 1 > 3) i = -1;
            $("#img-prev").attr('src', 'images/icon-arrow-left-' + colors[i + 1] + '.jpg');
            $("#img-next").attr('src', 'images/icon-arrow-right-' + colors[i + 1] + '.jpg');
            (i === 3) ? i = 0 : i = i + 1;
            $(".arrowRight").animate({ opacity: 1 }, 150, function() { clicked = true; });
            $(".arrowLeft").animate({ opacity: 1 }, 150);
			stack = 1;
        });

        $(".popArticlesHader").click(function() {

            var frame = $(this).attr('id') - 1;
            $(".arrowLeft").animate({ opacity: 0 }, 150);
            $(".arrowRight").animate({ opacity: 0 }, 150, function() {
                $("#popArticlesInnerHolder").animate({ left: -(divWidth * frame) }, 250, function() {
                    if (i + 1 > 3) i = -1;
                    $("#img-prev").attr('src', 'images/icon-arrow-left-' + colors[frame] + '.jpg');
                    $("#img-next").attr('src', 'images/icon-arrow-right-' + colors[frame] + '.jpg');
                    (i === 3) ? i = 0 : i = i + 1;
                    $(".arrowRight").animate({ opacity: 1 }, 150, function() { clicked = true; stack = frame});
                    $(".arrowLeft").animate({ opacity: 1 }, 150);
                });
            });
        });

    }

    if ($("#fitness-popArticlesInnerHolder").length > 0) {

		var numDivs = 0;
		$(".fitness-video").each(function(index) {
			numDivs = index + 1;
		});
	
		divWidth = $(".fitness-video").outerWidth(true); //WIDTH OF THE DIVS.
		$("#fitness-popArticlesInnerHolder").width(divWidth * numDivs);
		
        var i = 0;
        var clicked = true;
		
        $(".fitness-arrowRight").click(function() {
            var pos = $("#fitness-popArticlesInnerHolder").position().left;
			//if (BrowserDetect.browser === "Explorer" && pos < -253) pos = pos - 1; //IE JQUERY FIX.
			//console.log(pos);
            var holderWidth = $("#fitness-popArticlesInnerHolder").width();
            var newpos = pos - divWidth;
            //if (BrowserDetect.browser === "Explorer" && pos < 0) newpos = newpos - 1; //IE JQUERY FIX.
            var result = pos % divWidth;

            if (Math.abs(pos) >= (holderWidth - divWidth)) newpos = 0;
            if (clicked) {
                clicked = false;
                if (result === 0) {
                    $(this).animate({ opacity: 0 }, 150);
                    $(".fitness-arrowLeft").animate({ opacity: 0 }, 150, function() {
                        $("#fitness-popArticlesInnerHolder").animate({ left: newpos }, 250, function() {
                            $(".fitness-arrowRight").animate({ opacity: 1 }, 150, function() { clicked = true; });
                            $(".fitness-arrowLeft").animate({ opacity: 1 }, 150);
                        });

                    });

                }

            }

        }); //ARROW RIGHT CLICK

        $(".fitness-arrowLeft").click(function() {

            var pos = $("#fitness-popArticlesInnerHolder").position().left;
            var holderWidth = $("#fitness-popArticlesInnerHolder").width();
            var newpos = divWidth + pos;
            var result = pos % divWidth;

            if (pos === 0) newpos = (-(holderWidth - divWidth));
            //if (BrowserDetect.browser === "Explorer" && newpos < -(divWidth) - 1) newpos = newpos - 1; //IE JQUERY FIX
            if (clicked) {
                clicked = false;
                if (result === 0) {
                    $(this).animate({ opacity: 0 }, 150);
                    $(".fitness-arrowRight").animate({ opacity: 0 }, 150, function() {
                        $("#fitness-popArticlesInnerHolder").animate({ left: newpos }, 250, function() {
                            $(".fitness-arrowRight").animate({ opacity: 1 }, 150);
                            $(".fitness-arrowLeft").animate({ opacity: 1 }, 150, function() { clicked = true; });
                        });

                    });

                }

            }

        }); //END ARROW LEFT CLICK
    }


    /////////////// FEATURED VIDEOS 

    var videosWidth;
    var videosWidthAlt;
    var videosWidthAlt2;
    var numOfVideos;
    var videoType;
    var clicked = true;

    if ($(".video").length > 0) {
        videoType = ".video";
    } else if ($(".recipe-video").length > 0) {
        videoType = ".recipe-video";
    } else if ($(".living-video").length > 0) {
        videoType = ".living-video";
    } else if ($(".playerPage-video").length > 0) {
        videoType = ".playerPage-video";
        displayVideos = 4;
    }

    //this each will get the total number of video boxes. this way you can add
    //as many videos as you like
    $(videoType).each(function(index) {
        videosWidth = index;
        //this will hold the total number of videos for future use. 
        numOfVideos = index + 1;
    });

    //THIS IS FOR THE LIVING PAGE SCHOLARSHIP AND VIDEO PAGE HEALTHLY WOMEN CONTENT. 
    //THIS WILL SPLIT THE VIDEOS WIDTH DEPENDING ON WHICH SECTION YOU ARE LOOKING AT
    //videosWidth WILL BECOME EQUAL TO THE NUMBER OF VIDEOS IN EACH SECTION. 
    if ($("#living-videoHolder-alt").length > 0 || $(".playerPage-video").length > 0)
    {
        
        $("#videos " + videoType).each(function(index){
            numOfVideos = index + 1;
            videosWidth = index;
        });
        
        $("#videos-alt " + videoType).each(function(index){
            numOfVideos = index + 1;
            videosWidthAlt = index;
        });
        
        $("#videos-alt-2 " + videoType).each(function(index){
            numOfVideos = index + 1;
            videosWidthAlt2 = index;
        });
        
        videosWidth = (videosWidth + 1) * $(videoType).outerWidth(true);
        videosWidthAlt = (videosWidthAlt + 1) * $(videoType).outerWidth(true);
        videosWidthAlt2 = (videosWidthAlt2 + 1) * $(videoType).outerWidth(true);
        
        $("#videos").width(videosWidth);
        $("#videos-alt").width(videosWidthAlt);
        $("#videos-alt-2").width(videosWidthAlt2);
        
        
        ($("#videos-alt-2").length > 0)  ? displayVideos = 5 : displayVideos = 4;
        
    }
    else
    {
        //makes the video holder correct width to hold the total number of videos boxes
        videosWidth = (videosWidth + 1) * $(videoType).outerWidth(true);
        $("#videos").width(videosWidth);
        $("#videos-alt").width(videosWidth);
        $("#videos-alt-2").width(videosWidth);    
    }
     
    //get padding of video box
    var padding;
    if ($(".video").length > 0) {
        padding = parseInt($("#videoHolder").css('margin-left'))
    } else if ($(".recipe-video").length > 0) {
        padding = parseInt($("#recipe-videoHolder").css('margin-left'))
    } else if ($(".living-video").length > 0) {
        padding = parseInt($("#living-videoHolder").css('margin-left'))
    } else if ($(".playerPage-video").length > 0) {
        padding = parseInt($("#playerPage-videoHolder").css('margin-left'))
    }

    $(".video-arrowLeft").click(function(e) {

        var v1 = "#videos";
        var v2 = "#videos-alt";
        var v3 = "#videos-alt-2";
        var vid;

        if($("#home-featuredVideos").css("display") === "block")
        {
            vid = v1;
        }
        else if($("#home-featuredVideos-alt").css("display") === "block")
        {
            vid = v2;
        }
        else
        {
            vid = v3;
        }
           
		//FIX FOR HEALTHY WOMEN VIDEO SCROLLER
		var url = document.location.toString();
		if(url.indexOf("hw") > -1) vid = v2;
		//END fixed
		   
        var left = $(videoType).outerWidth(true);
        var pos = $(vid).position().left;

        if (Math.abs((pos)) <= 1) {
            newpos = 0;
            $(this).animate({ opacity: 0.25 });
        } else {
            newpos = ((pos) + (displayVideos * left));
            
            //console.log(newpos);
            //if (BrowserDetect.browser === "Explorer" && pos < 0) newpos = newpos - 1; //IE JQUERY FIX.
            if (BrowserDetect.browser === "Explorer" && newpos > -5) newpos = 0; //IE JQUERY FIX. FIX BY JESSICA C.
            $(".video-arrowRight").animate({ opacity: 1 });
        }

        //make sure on each click that clicked is true
        //to ensure that the transition is smooth
        if (clicked) {
            clicked = false;
            $(vid).animate({ left: newpos }, "fast", function() { clicked = true; });
        }

        //if the first video box has been reached fade out the previous arrow
        if (newpos === 0) $(this).animate({ opacity: 0.25 });

    });

    $(".video-arrowRight").click(function() {

        var v1 = "#videos";
        var v2 = "#videos-alt";
        var v3 = "#videos-alt-2";
        var vid;

        if($("#home-featuredVideos").css("display") === "block")
        {vid = v1}
        else if($("#home-featuredVideos-alt").css("display") === "block")
        {vid = v2;videosWidth = videosWidthAlt;}
        else
		{vid = v3;videosWidth = videosWidthAlt2;}
        
		//FIX FOR HEALTHY WOMEN VIDEO SCROLLER
		var url = document.location.toString();
		if(url.indexOf("hw") > -1){ vid = v2;videosWidth = videosWidthAlt; }
		//console.log(videosWidth);
		//END fixed
		
        var left = $(videoType).outerWidth(true);
        var pos = $(vid).position().left;
        if (Math.abs((pos)) >= Math.abs((videosWidth - (displayVideos * left)))) {
            newpos = (pos);
            $(this).animate({ opacity: 0.25 });
        } else {
            newpos = ((pos) - (displayVideos * left));
            if (numOfVideos > displayVideos) $(".video-arrowLeft").animate({ opacity: 1 });
        }

        if (BrowserDetect.browser === "Explorer") newpos = newpos - 1; //IE JQUERY FIX.
        //if (BrowserDetect.browser === "Explorer" && newpos > -5) newpos = 0; //IE JQUERY FIX. FIX BY JESSICA C.

        //make sure on each click that clicked is true
        //to ensure that the transition is smooth
        if (clicked && numOfVideos > displayVideos) {
            clicked = false;
            $(vid).animate({ left: newpos }, "fast", function() {
                clicked = true;
                if (Math.abs((newpos)) >= Math.abs((videosWidth - (displayVideos * left)))) $(".video-arrowRight").animate({ opacity: 0.25 });
            });
        }
		
        //if the last video box has been reached or there are 5 or less videos, fade out the next arrow
        if (numOfVideos <= displayVideos || Math.abs((pos)) >= Math.abs((videosWidth - (displayVideos * left)))) $(this).animate({ opacity: 0.25 });

    });

    //IF THERE IS LESS THAN 5 VIDEOS AUTOMATICALLY FADE OUT BOTH ARROWS
    if (numOfVideos <= displayVideos) $(".video-arrowRight, .video-arrowLeft").animate({ opacity: 0.25 }); 

    /////////////// REMOVE SEARCH TEXT FROM SEARCH BOX
    $('.btn-search').css('cursor', 'pointer').click(function() {
        location.href = '/search.aspx?SearchType=all&SearchTerm=' + $('.txt-search').val();
    });

    $("input.txt-search").click(function() {
        $(this).attr('value', '');
    }).blur(function() {
        if ($(this).attr('value') === '') {
            $(this).attr('value', 'SEARCH');
        }
    }).keypress(function(event) {
        if (event.which == 13) {
            event.preventDefault();
            location.href = '/search.aspx?SearchType=all&SearchTerm=' + $('.txt-search').val();
        }
    });

    /////////////// MAKE DIV'S ACTIVE LINKS

    // HOVER STATES - CHANGE DEFAULT MOUSE ARROW TO LINK POINTER (GIVES THE ILLUSION OF A LINK)
    $(".hover").css({ cursor: 'pointer' }).click(function(e) {
        //THIS WILL GRAB THE VALUE OR HREF FROM THE .hoverLink CLASS LINK. THIS WAY IF JAVASCRIPT
        //HAPPENS TO BE DISABLED, THE ACTUAL TEXT LINK WILL STILL WORK FINE. ALSO GOOD FOR SEO
        barkerClicked = 1;
        e.preventDefault();
        _gaq.push(['_setAccount', 'UA-8847764-12'], ['_trackEvent', 'RBRA Barkers', 'Click - ' + $(this).find('.hoverLink').attr('title'), location.href + ' || ' + document.title]);
        setTimeout("redirect('" + $(this).find('.hoverLink').attr('href') + "')", 1000);
    });

    $(".hoverLink").css({ cursor: 'pointer' }).click(function(e) {
        //THIS WILL GRAB THE VALUE OR HREF FROM THE .hoverLink CLASS LINK. THIS WAY IF JAVASCRIPT
        //HAPPENS TO BE DISABLED, THE ACTUAL TEXT LINK WILL STILL WORK FINE. ALSO GOOD FOR SEO
        e.preventDefault();
        if (barkerClicked != 1) {
            _gaq.push(['_setAccount', 'UA-8847764-12'], ['_trackEvent', 'RBRA Barkers', 'Click - ' + $(this).attr('title'), location.href + ' || ' + document.title]);
            setTimeout("redirect('" + $(this).attr('href') + "')", 1000);
        }
    });

  
    ////////////// START NEW CLASSICS | COMFORT FOOD NAVIGATION

    //IF THERE IS A HASH TAG IN THE URL, CHECK IT AND
    //MAKE THE CORRECT SECTION ACTIVE
    var url = document.location.hash.toString();

    if (url != "") {
        $(url).css({ color: '#52bd91' }).find("span").addClass("active");
        if (url.replace("#", "") === "comfortfood") {
            $("#home-featuredVideos").fadeTo(200, 0, function() {
                $(this).css({ display: 'none', position: 'absolute' });
                $("#home-featuredVideos-alt").css({ position: 'relative' }).fadeTo(200, 1);
            });
        }
    }
	else if(readCookie("recipe")){
		var recipe = readCookie("recipe");
		//alert(recipe);
		if (recipe === "comfortfood") {
            $("#home-featuredVideos").fadeTo(200, 0, function() {
                $(this).css({ display: 'none', position: 'absolute' });
                $("#home-featuredVideos-alt").css({ position: 'relative' }).fadeTo(200, 1);
				$("#comfortfood").css({ color: '#52bd91' }).find("span").addClass("active");
            });
        }else{
			$("#newclassics").css({ color: '#52bd91' }).find("span").addClass("active");
		}
	}
    else {
        $("#newclassics").css({ color: '#52bd91' }).find("span").addClass("active");
    }

    $(".videoControllerLink").click(function(e) {

        e.preventDefault();

        //CLEAR THE ACTIVE CLASS FOR BOTH LINKS
        $(".videoControllerLink").css({ color: '#444' }).find("span").removeClass("active");

        var check = $(this).attr('rel');

        if (check === "newclassics" || check === "2010") {
            
            if (check === "2010") {
                $("#2009").attr({ src: '/images/icon-2009.gif' });
                $("#2010").attr({ src: '/images/icon-2010.gif' });
                $("#2011").attr({ src: '/images/icon-2011.gif' });
                $(".video-arrowRight, .video-arrowLeft").animate({ opacity: 1 });
				
				$("#home-featuredVideos").fadeOut("slow", function() {
				$(this).css({ display: 'none', position: 'absolute' });
				$("#home-featuredVideos-alt-2").fadeOut("slow", function(){
					$(this).css({ display: 'none', position: 'absolute' });
					$("#home-featuredVideos-alt").css({ position: 'relative' }).fadeIn("slow");
                });
            });
				
            }
			else
			{
				//CREATE COOKIE
				createCookie("recipe", "newclassics");
				//APPEND ACTIVE TO CLICKED LINKED
				$(this).css({ color: '#52bd91' }).find("span").addClass("active");
				$("#home-featuredVideos-alt").fadeOut("slow", function() {
					$(this).css({ display: 'none', position: 'absolute' });
					$("#home-featuredVideos").css({ position: 'relative', opacity: 1 }).fadeIn("slow");				
				});
			}
            
        }
        else if (check === "comfortfood" || check === "2009")
        {  
            if (check === "2009") {
                $("#2009").attr({ src: '/images/icon-2009-alt.gif' });
                $("#2010").attr({ src: '/images/icon-2010-alt.gif' });
                $("#2011").attr({ src: '/images/icon-2011.gif' });
                $(".video-arrowRight, .video-arrowLeft").animate({ opacity: 1 });
							
				$("#home-featuredVideos").fadeOut("slow", function() {
					$(this).css({ display: 'none', position: 'absolute' });
					$("#home-featuredVideos-alt").fadeOut("slow", function(){
						$(this).css({ display: 'none', position: 'absolute' });
						$("#home-featuredVideos-alt-2").css({ position: 'relative' }).fadeIn("slow");
					});
				});
            }
			else
			{
				//CREATE COOKIE
				createCookie("recipe", "comfortfood");
				//APPEND ACTIVE TO CLICKED LINKED
				$(this).css({ color: '#52bd91' }).find("span").addClass("active");
				$("#home-featuredVideos").fadeOut("slow", function() {
					$(this).css({ display: 'none', position: 'absolute' });
					$("#home-featuredVideos-alt").css({ position: 'relative' }).fadeIn("slow");				
				});
			}
        }
        else if (check === "2011")
        {
            if (check === "2011") {
                $("#2009").attr({ src: '/images/icon-2009.gif' });
                $("#2010").attr({ src: '/images/icon-2010-alt.gif' });
                $("#2011").attr({ src: '/images/icon-2011-alt.gif' });
                $(".video-arrowRight, .video-arrowLeft").animate({ opacity: 1 });
            }
            $("#home-featuredVideos-alt").fadeOut("slow", function() {
                $(this).css({ display: 'none', position: 'absolute' });
                $("#home-featuredVideos-alt-2").fadeOut("slow", function(){
					$(this).css({ display: 'none', position: 'absolute' });
					$("#home-featuredVideos").css({ position: 'relative' }).fadeIn("slow");
				});
			});
        }
    }); //end videoControllerLink

    ////////////// END NEW CLASSICS | COMFORT FOOD NAVIGATION

    $(".recipe-video").hover(function() {
        $(this).css({ background: 'url(/images/bg-recipe-video-hover.png)', cursor: 'pointer' }).find(".videoTitle a").css({ color: '#52bd91' }).click(function() {
            //alert("hi");
            //window.location = $(this).find("a").attr('href');
        });
    }, function() {
        $(this).css({ background: 'url(/images/bg-recipe-video.png)' }).find(".videoTitle a").css({ color: '#444' });
    });

    /////////////////////////// SWAP IMAGE
    var originalSrc;
    $(".swapImg").hover(function() {
        originalSrc = $(this).attr("src");
        $(this).attr({ src: $(this).attr("hover") }).css({ cursor: "pointer" });
    }, function() {
        $(this).attr({ src: originalSrc });
    });

    /////////////////////////// POP UP FUNCTION

    var h = $(window).height();
    var w = $(window).width();
    var st = $(document).scrollTop();;
    var videoHolderTop;
    var videoHolderLeft;

    $(".popup, .popupOverlay, .popupIframe").click(function(e) {

        e.preventDefault();

        var popupClass = $(this).attr('class');

        //CHECK FOR OVERLAY CLASS. IF PRESENT FADE IN OVERLAY
        if (popupClass === "popupOverlay" || popupClass.indexOf("popupIframe") != -1) {
            $("#overlay").css({ height: $(document).height() }).animate({ opacity: '0.50' }).fadeIn();
        }

        var inc = $(this).attr('page');

        var location = $(this).attr('href');

        if (inc === undefined) inc = location; //IF THE PAGE ATTRIBUTE IS MISSING DEFAULT TO HREF

        $("#site").html(location);
        var src;
        var videoWidthHeight = $(this).attr('rel');

        //IF rel ATTRIBUE IS NOT SET THROW AN ALERT
        if (videoWidthHeight === undefined) {
            alert("Please set the 'rel' attribute with the width and the height as follows.\n rel=\"w:800-h:600\"");
            return false;
        }

        var videoWidth = videoWidthHeight.split('-');
        videoWidth = videoWidth[0];
        videoWidth = videoWidth.slice(2); //THIS WILL BECOME THE WIDTH OF THE VIDEO PASSED FROM THE REL ATTRIBUE

        var videoHeight = videoWidthHeight.split('-');
        videoHeight = videoHeight[1];
        videoHeight = videoHeight.slice(2); //THIS WILL BECOME THE HEIGHT OF THE VIDEO PASSED FROM THE REL ATTRIBUE
        window.globalVideoHeight = videoHeight;

		var cssPos = (iPad()) ? "absolute" : "fixed";
		
        videoHolderTop = ((h / 2) + st);
        videoHolderLeft = (w / 2);
		
		if(iPad()) $.scrollTo('0px', 'linear');	//IF IPAD THEN SCROLL TO THE TOP OF THE PAGE. 
        
		$("#playerShadow").css({ position: cssPos, top: videoHolderTop - (videoHeight / 2 + 15), left: videoHolderLeft - (videoWidth / 2 + 15), width: videoWidth + 'px', height: videoHeight + 'px', zIndex: '12500' }).animate({ opacity: '0.50' }).fadeIn(function() {

            $("#player").css({ position: cssPos, top: videoHolderTop, left: videoHolderLeft, zIndex: '13000' }).fadeIn().animate({ top: videoHolderTop - (videoHeight / 2) + 'px', left: videoHolderLeft - (videoWidth / 2) + 'px', width: videoWidth + 'px', height: videoHeight + 'px' }, function() {
				
                var data = $.ajax({
                    url: inc,
                    type: 'GET',
                    dataType: 'html',
                    success: function(text) {
						
                        if (popupClass.indexOf("popupIframe") != -1) {
                            $("#player").html("<iframe width='" + videoWidth + "' height='" + videoHeight + "' src='" + inc + "' border='0'></iframe>");
                        } else {
                            $("#player").html(text);
                        }
                        $("#site").html(location);
                        $("#close").css({ position: 'absolute', top: '10px', right: '10px' }).hover(function() {
                            $(this).css({ cursor: 'pointer' });
                        }).click(function() {
                            closepopup();
                        }); //end close

                        //THIS CONTROLS THE YES/NO RADIO BUTTONS. 
                        $("#dontleave").click(function(e) {
                            e.preventDefault();
                            closepopup();
                        });

                        $("#leavesite").click(function(e) {
                            e.preventDefault();
                            //window.location = location;
                            window.open(location);
							closepopup();
                        });

                    } //end success function

                }); //end ajax

            }); //end player																																																						 

        }); //end player shadow	

    }); //end popup / popupOverlay

    //THIS WILL KEEP THE OVERLAY WINDOW IN THE MIDDLE
    //OF THE PAGE WHEN THE USER IS SCROLLING	
    $(window).scroll(function() {
        /*if(iPad() === false){
			h = $(window).height();
			st = $(document).scrollTop();
			//alert(st);
			videoHolderTop = Math.floor(((h / 2) + st) - (window.globalVideoHeight / 2));
			$("#player").css({ top: videoHolderTop });
			$("#playerShadow").css({ top: videoHolderTop - 15 });
        }
		
        THIS IS TO MAKE THE MENU "STICKY" FOR THE IPAD. 
        if (iPad() || navigator.userAgent.match('Android')) {
            $("#topOfMenu").css({ borderRight: "1px solid black", borderLeft: "1px solid black", zIndex: "11000", backgroundColor: "#fff", position: "absolute", top: "0px" }).height(st).width("957px");
            $("#menuHolder").css({ position: "absolute", top: st });
        }*/
    });
    
    $(".maRoomLink, .maRoomLink-blue").click(function(e) {
        e.preventDefault();

        var elm = $(this).attr('href');
        var target = $(elm).position().top - 5;

        $.scrollTo(target, 'linear');
    });

    $(".ma-backToTop, .blue-backToTop").click(function(e) {
        e.preventDefault();
        $.scrollTo('0px', 'linear');
    });
	
	
    var loc;

    var currentUrl = location.pathname.toLowerCase();
    if (currentUrl.indexOf('/default.aspx') == 0) {
        $('.gray div#navHome').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/diet-and-rheumatoid-arthritis') == 0) {
        $('.green div#navDiet').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/rheumatoid-diet') == 0) {
        $('.green div#navDiet').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/ra-recipes') == 0) {
        $('.green div#navDiet').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/comfort-food-recipes') == 0) {
        $('.green div#navDiet').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/rheumatoid-arthritis-diet') == 0) {
        $('.green div#navDiet').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/diet-and-rheumatoid-arthritis') == 0) {
        $('.green div#navDiet').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/ra-diet') == 0) {
        $('.green div#navDiet').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/my-ra-fit-kit') == 0) {
        $('.orange div#navFitness').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/ra-fitness') == 0) {
        $('.orange div#navFitness').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/rheumatoid-arthritis-and-exercise') == 0) {
        $('.orange div#navFitness').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/ra-exercise') == 0) {
        $('.orange div#navFitness').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/rheumatoid-arthritis-exercise') == 0) {
        $('.orange div#navFitness').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/exercises-for-rheumatoid-arthritis') == 0) {
        $('.orange div#navFitness').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/the-meditation-room') == 0) {
        $('.orange div#navFitness').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/help-for-arthritis') == 0) {
        $('.yellow div#navFinances').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/rheumatoid-arthritis-financial-assistance') == 0) {
        $('.yellow div#navFinances').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/finances') == 0) {
        $('.yellow div#navFinances').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/living-with-ra') == 0) {
		$('.blue-alt div#navLiving').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/traveling-with-arthritis') == 0) {
        $('.blue-alt div#navLiving').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/rheumatoid-arthritis-and-work') == 0) {
        $('.blue-alt div#navLiving').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/ra-and-sex') == 0) {
        $('.blue-alt div#navLiving').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/arthritis-care') == 0) {
        $('.blue-alt div#navLiving').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    } else if (currentUrl.indexOf('/ucb-scholarship') == 0) {
        $('.blue-alt div#navLiving').css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
    }
	
	
	/*/A BETTER WAY TO KEEP TRACK OF THE SECTION YOU ARE IN
	$(".menu").click(function(){
		//alert($(this).find("div").attr("id"));
		createCookie("navSection", $(this).find("div").attr("id"));
	});
	
	var currPage = readCookie("navSection");
	if(currPage === "" || currPage === null || currPage === undefined) createCookie("navSection", "navHome"); //IF FIRST TIME TO SITE THEN DEFAULT TO HOME PAGE
	$("#" + currPage).css({ position: 'relative', width: '100%', height: '9px', background: 'url(/images/icon-active-nav-arrow.png) no-repeat center top' });
	*/
	
	
	
});            // end document ready

//////////CUSTOM FUNCTIONS


function closepopup()
{
    $("#player").html("").fadeOut("fast", function(){
        //RESET PLAYER POSITION TO DEFAULT. THIS WAY THERE ARE NO PROBLEMS WHEN IT'S
        //ANIMATED BACK IN THE NEXT TIME THE PLAYER IS USED.														  
        $(this).css({width: '0px' , height: '0px', top: '0px', left: '0px'});
        $("#playerShadow").fadeOut("fast", function(){
            $("#vidHolder").fadeOut("fast", function(){
	            $("#site").html('');
                $(this).css({display: 'none'});
            });
            $("#overlay").fadeOut("fast");							  									
        }); //end player shadow	
    }); //end player
}

function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function setFontSizes(div, index)
{
    $(div).css("font-size", getCookie("div" + index));
}

function resizeIt(div, size, index, arr)
{
    switch(size)
    {
        case "1":
            //alert(arr[size-1]);
            $(div).css("font-size", parseInt(getCookie("div" + index)) + parseInt(arr[size-1]) + "px");
            setCookie("currSize", "original");
            break;
        case "2":
            //alert(arr[size-1]);
            $(div).css("font-size", parseInt(getCookie("div" + index)) + parseInt(arr[size-1]) + "px");
            setCookie("currSize", "medium");
            break;
        case "3":
            $(div).css("font-size", parseInt(getCookie("div" + index)) + parseInt(arr[size-1]) + "px");
            //alert(arr[size-1]);
            setCookie("currSize", "large");
            break;
    }
}

function doFontSize(div, num, index, keepSize)
{
    if(keepSize)
    {
        switch(keepSize)
        {
            case "original":
                resizeIt(div, num, index, [0, 2, 3]);
                break;
            case "medium":
                resizeIt(div, num, index, [-2, 0, 1]);
                break;
            case "large":
                resizeIt(div, num, index, [-3, -2, 0]);
                break;
        }
    }
    else
    {
        
        switch(num)
        {
            case "1":
                $(div).css("font-size", getCookie("div" + index));
                setCookie("currSize", "original");
                break;
            case "2":
                $(div).css("font-size", parseInt(getCookie("div" + index)) + parseInt(num) + "px");
                setCookie("currSize", "medium");
                break;
            case "3":
                $(div).css("font-size", parseInt(getCookie("div" + index)) + parseInt(num) + "px");
                setCookie("currSize", "large");
                break;
        }
    }
}

function redirect(url) {
    window.location.href = url;
}


//FOR IPAD
function iPad() {
    var version = navigator.userAgent.match(/iPad/i) != null;
    if (match = /iPhone OS (.*) like Mac OS X/.exec(navigator.userAgent)) {
        version = parseInt(match[1].replace('_', ''), 10) / 100;
        if (version < 1) {
            version *= 10;
        }
    }

    return version;
}

//FIREFOX FIXES
if(BrowserDetect.browser === "Firefox" && BrowserDetect.OS === "Mac") document.write("<style type=\"text/css\">@-moz-document url-prefix(){#menu ul li a:hover div{top: 0px;}#menu ul li a {margin-top: -5px;}}</style>");



