$(document).ready(function() {
    var i,j,img,k,l,sidebarheight;
	// make the Copy height at least "min_height" px
	k=$('#Sidebar img').length;
	sidebarheight=0;
	for (i=0;i<k;i++) {
	    l=$('#Sidebar img').filter(':eq('+i+')');
	    sidebarheight+=l.height();
	}
	var min_height=400;
	if (sidebarheight>min_height) {
	    min_height=sidebarheight;
	}
	i=$('#Subhead').height();
	j=$('#Copy').height();
	if ((i+j+10)<min_height) {
	    $('#Copy').height(min_height-i);
	}

	// allow click on the breadCrumbs image to go to the "next" page
	$('#breadCrumbs img').click(function () {
	    if (breadCrumbActive==1) {
	        var i,j,x;
	        // menu structure :
	        var SiteList='|about_lfl';
            SiteList+='|personalized-weight-loss';
            SiteList+='|program_nutritional';
            SiteList+='|weight-loss-fitness';
            SiteList+='|program-maintenance';
            SiteList+='|program_tour';
            SiteList+='|program_clinics';
            SiteList+='|program_online';
            SiteList+='|successstories';
            SiteList+='|share-success-story';
            SiteList+='|faqs';
            SiteList+='|current-clinic-offers';
            SiteList+='|program_options';
            SiteList+='|scientific-weight-loss';
            SiteList+='|weight-loss-research';
            SiteList+='|cynthia-blog';
            SiteList+='|medical_QA';
            SiteList+='|lifestyle-assessment';
            SiteList+='|bmi_calculator';
            SiteList+='|weight-loss-recipes';
            SiteList+='|webinars';
            SiteList+='|dietandhealth_tips';
            SiteList+='|about';
            SiteList+='|about_philosophy';
            SiteList+='|about_team';
            SiteList+='|about_board';
            SiteList+='|leanforlifefoundation';
            SiteList+='|about_joinlindora';
            SiteList+='|about_joinlindora_jobs';
            SiteList+='|about_news';
            SiteList+='|clinicmap';
            SiteList+='|clinic-locations-list';
            SiteList+='|lhc-riteaid';
            SiteList+='|sutter';
            SiteList+='|videolibrary';
            SiteList+='|community';
            SiteList+='|research';
            SiteList+='|medicalfaq';
            SiteList+='|lean-for-life-partner';
            SiteList+='|partner_overview';
            SiteList+='|lindora-rite-aid';
            SiteList+='|allergan-lapband-lindora';
            SiteList+='|about_partners';
            SiteList+='|workerscomp_how';
            SiteList+='|corporate-wellness';
            SiteList+='|statistics';
            SiteList+='|employee-discounts';
            SiteList+='|become-partner';
            SiteList+='|default';
            
	        // individual clinic pages :
            SiteList+='|weight-loss-camarillo';
	        SiteList+='|weight-loss-cerritos';
	        SiteList+='|weight-loss-chino-hills';
	        SiteList+='|weight-loss-corona';
	        SiteList+='|weight-loss-costa-mesa-riteaid';
	        SiteList+='|weight-loss-costa-mesa';
	        SiteList+='|weight-loss-del-mar-riteaid';
	        SiteList+='|weight-loss-downey';
	        SiteList+='|weight-loss-encinitas-riteaid';
	        SiteList+='|weight-loss-fullerton';
	        SiteList+='|weight-loss-glendale';
	        SiteList+='|weight-loss-highland';
	        SiteList+='|weight-loss-huntington-beach';
	        SiteList+='|weight-loss-irvine';
	        SiteList+='|weight-loss-la-habra';
	        SiteList+='|weight-loss-laguna-hills';
	        SiteList+='|weight-loss-laguna-niguel-riteaid';
	        SiteList+='|weight-loss-long-beach';
	        SiteList+='|weight-loss-los-angeles-riteaid';
	        SiteList+='|weight-loss-marina-del-rey';
	        SiteList+='|weight-loss-monrovia';
	        SiteList+='|weight-loss-montclair';
	        SiteList+='|weight-loss-newport-beach-riteaid';
	        SiteList+='|weight-loss-newport-beach';
	        SiteList+='|weight-loss-north-valencia';
	        SiteList+='|weight-loss-northridge';
	        SiteList+='|weight-loss-orange';
	        SiteList+='|weight-loss-palm-desert';
	        SiteList+='|weight-loss-pasadena';
	        SiteList+='|weight-loss-rancho-cucamonga';
	        SiteList+='|weight-loss-rancho-santa-margarita';
	        SiteList+='|weight-loss-riverside';
	        SiteList+='|weight-loss-san-juan-capistrano';
	        SiteList+='|weight-loss-santa-monica-riteaid';
	        SiteList+='|weight-loss-sherman-oaks';
	        SiteList+='|weight-loss-so-torrance';
	        SiteList+='|weight-loss-temecula';
	        SiteList+='|weight-loss-tustin-riteaid';
	        SiteList+='|weight-loss-valencia';
	        SiteList+='|weight-loss-west-covina';
	        SiteList+='|weight-loss-westlake';
	        SiteList+='|weight-loss-westwood';
	        SiteList+='|weight-loss-woodland-hills';
	        SiteList+='|weight-loss-camarillo';

	        var S=SiteList.split('|');
	        var U=document.URL.split('/');
	        x=U[U.length-1].toLowerCase();
	        j=-1;
	        for (i=0;i<S.length;i++)
	        {
	            if (x==S[i].toLowerCase()+'.aspx')
	            {
	                j=i;
	                break;
	            }
	        }
	        if (j>-1)
	        {
	            j=j+1
	            if (j==S.length)
	                j=0;
	            location=S[j]+'.aspx';
	        }
	    }
	});
	
	// getStarted button animations
	$('#getStarted button').hover(
    	function ButtonOver() {
        	$(this).css('cursor', 'hand');
	        $(this).css('fontWeight','bold');
	        $(this).css('backgroundColor','rgb(125,065,153)');
	        $(this).css('color','FFFFFF');
        },
        function ButtonOut(button) {
	        $(this).css('fontWeight','normal');
	        $(this).css('backgroundColor','white');
	        $(this).css('color','000000');
        }
    );
    
    // animate the success story arrow when 2.3 loads
    if ($('#success_arrow').length>0) {
        var left=getSuccessStoryLeft(currentSuccessStory);
        $('#success_arrow').animate({left:left}, {duration:1000});
    }
    // animate when success story arrow is clicked
    $('#success_arrow').click(function() {
        i=currentSuccessStory+1;
        if (i>9) {
            i=1;
        }
        SwapStory(i);
    });      
    // swap community buttons
    $('.community').hover(
        function ButtonOver() {
            $(this).css({opacity:0.7});
            $(this).css({border:'10px'});
        },
        function ButtonOut() {
            $(this).css({opacity:1.0});
        }
    );
});	
function SetHeaderImage(index) {
    var id,img;
    img=document.getElementById('vh1');
    img.src='images/videos/success'+GetImageSuffix(1,index);
    img=document.getElementById('vh2');
    img.src='images/videos/medical'+GetImageSuffix(2,index);
    img=document.getElementById('vh3');
    img.src='images/videos/program'+GetImageSuffix(3,index);
    img=document.getElementById('vh4');
    img.src='images/videos/allvideos'+GetImageSuffix(4,index);
}
function GetImageSuffix(i,index) {
    var x;
    if (i==index)
        x='_on.jpg';
    else
        x='_off.jpg';
    return x;
}    
var win = null;
function p11pop(theURL,winName,features,w,h,centered) { //v2.0
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	if (centered == 'yes') {
	realFeatures = (features+',top='+TopPosition+',left='+LeftPosition+',width='+w+',height='+h);
	}
	else {
	realFeatures = (features+',width='+w+',height='+h+'left=0,top=0');
	}
	win = window.open(theURL,winName,realFeatures);
}
function SwapStory(index) {
    var i,x;
    for (i=1;i<=9;i++) {
        x="none"
        if (i==index) {
            x="inline";
        }
        $('#SuccessStory_' + i).css('display',x);
    }
    var left=getSuccessStoryLeft(index);
    $('#success_arrow').animate({left:left}, {duration:1000});
    currentSuccessStory=index;
}
function getSuccessStoryLeft(currentSuccessStory) {
    var left=0;
    if (currentSuccessStory==1) left=25;
    if (currentSuccessStory==2) left=90;
    if (currentSuccessStory==3) left=160;
    if (currentSuccessStory==4) left=230;
    if (currentSuccessStory==5) left=305;
    if (currentSuccessStory==6) left=375;
    if (currentSuccessStory==7) left=445;
    if (currentSuccessStory==8) left=515;
    if (currentSuccessStory==9) left=580;
    return left;
}            
