function addToPlanLink ()    {
    jQuery('.my_itinerary, .trip-plan-object').unbind('click').click(function(){

        var objId = jQuery(this).attr('rel');
        objId = (objId!=undefined)?objId:'';
        var planCookie = jQuery.cookie('tripplan');
        if (planCookie == null)
        {
            var dialog = jQuery(
                                '<div class="dialog">'+
									'<p>You can create your own custom itinerary for your trip to DC’s Wine Country. Throughout the site, you’ll see many activities, destinations and events that you can add to your itinerary. Just click “Add this to my itinerary” as you browse our site. Fill in the title of your trip and when you’d like to start your trip in the fields below. As you add items to your itinerary, you’ll have the opportunity to share this with your family and friends and print your itinerary.</p>'+
                                    '<div class="dialog-left">'+
										'<h2>Create your vacation plan</h2>'+
										'<form id="new_plan" action="" method="post">'+
											'<label>Trip title</label><input id="dialog_plan_title" type="text" name="title" /><br />'+
											'<p class="tip">10 words or less, e.g. "Summer Trip to La Jolla"</p>'+
											'<label>Trip Start Date</label><input id="dialog_plan_date" type="text" name="plan_start_date" />'+
                                            '<input type="hidden" name="poiId" value="'+objId+'"/>'+
										'</form>'+
									'</div>'+
									'<div class="dialog-right">'+
										'<h2>Organize</h2><p>Save hotels, things to do, and restaurants in a private plan and organize them with headings and notes.</p>'+
										'<div class="right-banners"></div>'+
										'<h2>Map</h2><p>Drag and drop the items in your trip and see them plotted on a map</p>'+
										'<h2>Print & Share</h2><p>Print your trip plan and take it with you for easy travels or share via email with your friends and family.</p>'+
									'</div>'+
									'<div class="clear"></div>'+
                                '</div>'
                                );            
            dialog.dialog({
                dialogClass: 'tigplan_dialog_frame',
                modal : true, 
                buttons : {
                    "Create your trip plan" : function(){
                        var nd = new Date;
                        var newCookie = nd.getTime();
                        jQuery.cookie('tripplan', newCookie, {expires : 365, path: '/'} );
                        var actUrl = '/tripplan/trip_plan/'+newCookie;
                        if ( objId!='' ) actUrl += '/'+objId;
                        jQuery(this).find('#new_plan').attr('action', actUrl).submit();
                    },
                    "Cancel" : function(){
                        jQuery(this).dialog('close');
                    }
                }
            });
            var dateInput = jQuery(dialog).find('#dialog_plan_date').datepicker();
            
        }else
        {
            var url = '/tripplan/trip_plan/'+planCookie;
            var form = jQuery('body').append('<form id="redirForm" action="'+url+'" method="post" />');
            jQuery('#redirForm').append('<input type="hidden" name="poiId" value="'+objId+'"/>');
            jQuery ('#redirForm').submit();
        }
    });
}


function loadPlanCount ()
{
    var planCookie = jQuery.cookie('tripplan');
    if (planCookie != null)
    {
         jQuery.ajax({   type    : 'POST',
              url     : '/tripplan/load_plan_count',
              data    : {'cookie' : planCookie},
              success : function(data)
                  {
                      jQuery('#plan_count_recip').html('('+data+')');
                  }
            });
    }
}

jQuery(document).ready(function()    {
    jQuery('#subnav_plan_l').find("a[href*='My-Map-Trip-Planner']").attr('href', 'javascript: void 0;').addClass('trip-plan-object');
    loadPlanCount();
    addToPlanLink();
    
});
