$(function(){
	// Clear values from form fields
	$('input:text, input:password, textarea').focus(function(){
		if ($(this).val() == $(this).attr('title')) {
			$(this).val('');
		}
		$(this).blur(function(){
			if ($(this).val().length == 0) {
				$(this).val($(this).attr('title'));
			}
		});
	});
	
	// Active states
	$('div.navigate_menu ul li a, ul.aux_nav li a, ul.footer_aux_nav li a').each(function(){
		if (targetURL == $(this).attr('href')) {
			$(this).parent().addClass('active');
		}	
	});
	$('ul.main_nav li a, ul.footer_nav li a').each(function(){
		if (targetURL == $(this).attr('href')) {
			$(this).addClass('active');
		}	
	});
	
	$('a.print_plan').click(function(e){
		e.preventDefault();
		if (window.print) {
			window.print();
		}
	});

	Shadowbox.init();

    /* Add Vendor */
    $('#vendor_listing a.add').click(function(e){
        e.preventDefault();
        var vendorId = $(this).attr('data-id');
        Shadowbox.open({
            content: '/template/itinerary/add.php?vendor_id='+vendorId
            , height: 400
            , player: "iframe"
            , width: 500
        });
    });

    $('#add_link').click(function(e){
        e.preventDefault();
        var vendorId = $(this).attr('data-id');
        Shadowbox.open({
            content: '/template/itinerary/add.php?vendor_id='+vendorId
            , height: 400
            , player: "iframe"
            , width: 500
        });
    });

    /* Remove Vendor */
    $('#planner_items p.remove a.vendor').click(function(e){
        e.preventDefault();
        var vendorId = $(this).attr('data-id');
        var itemId = $(this).attr('data-item-id');
        Shadowbox.open({
            content: '/template/itinerary/remove.php?vendor_id='+vendorId+'&item_id='+itemId
            , height: 250
            , player: "iframe"
            , width: 500
        });
    });

    /* Delete Itinerary */
    $('#itinerary-preview div.actions a.remove').click(function(e){
        e.preventDefault();
        var itemId = $(this).attr('data-id');
        Shadowbox.open({
            content: '/template/itinerary/delete.php?item_id='+itemId
            , height: 250
            , player: "iframe"
            , width: 500
        });
    });

    /* Add Event */
    $('div.upcoming_events a.add').click(function(e){
        e.preventDefault();
        var vendorId = $(this).attr('data-id');
        Shadowbox.open({
            content: '/template/itinerary/event_add.php?vendor_id='+vendorId
            , height: 400
            , player: "iframe"
            , width: 500
        });
    });

    $('#add_link_event').click(function(e){
        e.preventDefault();
        var vendorId = $(this).attr('data-id');
        Shadowbox.open({
            content: '/template/itinerary/event_add.php?vendor_id='+vendorId
            , height: 400
            , player: "iframe"
            , width: 500
        });
    });

    /* Remove Vendor */
    $('#planner_items p.remove a.event').click(function(e){
        e.preventDefault();
        var vendorId = $(this).attr('data-id');
        var itemId = $(this).attr('data-item-id');
        Shadowbox.open({
            content: '/template/itinerary/event_remove.php?vendor_id='+vendorId+'&item_id='+itemId
            , height: 250
            , player: "iframe"
            , width: 500
        });
    });

	$('#in_the_area select').change(function(){
		$(this).closest('form').submit();
	});
});

